0% found this document useful (0 votes)
6 views9 pages

Use of Autoencoder For An Unsupervised Training To Predict Water Quality

This article discusses the use of a lightweight Autoencoder model for unsupervised anomaly detection in water quality time series data, specifically aimed at monitoring the Amazon River. The model, trained on normal operational data, identifies anomalies based on reconstruction errors, achieving an F1-score of 0.263 during testing. While the approach shows potential for water quality monitoring, the current performance is not suitable for production, and future improvements are suggested to enhance detection accuracy.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

Use of Autoencoder For An Unsupervised Training To Predict Water Quality

This article discusses the use of a lightweight Autoencoder model for unsupervised anomaly detection in water quality time series data, specifically aimed at monitoring the Amazon River. The model, trained on normal operational data, identifies anomalies based on reconstruction errors, achieving an F1-score of 0.263 during testing. While the approach shows potential for water quality monitoring, the current performance is not suitable for production, and future improvements are suggested to enhance detection accuracy.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Use of Autoencoder for an unsupervised training to

predict water quality

Abstract. This article presents an unsupervised approach for anomaly detection


in water quality time series data using a lightweight Autoencoder model, with
the objective of monitoring the Amazon River. As industrial activities in the
Amazon region increase, continuous water quality assessment becomes essen-
tial to preserve this vital ecosystem. The proposed method leverages an Autoen-
coder neural network trained exclusively on normal operational data to recon -
struct input signals consisting of nine water quality indicators. Anomalies are
identified when reconstruction errors exceed an optimized threshold. The model
architecture comprises dense layers. Training was conducted on a highly imbal-
anced public dataset from a 2018 GECCO challenge. Performance evaluation
on a hold-out test set achieved an F1-score of 0.263. Although the current per-
formance is insufficient for production deployment, the unsupervised Autoen-
coder methodology demonstrates promise for water quality monitoring applica-
tions where labeled anomalies are scarce. Future improvements should explore
alternative architectures such as Long Short-Term Memory networks, extended
training periods, and adaptive threshold techniques to enhance detection accu-
racy.

Keywords: Autoencoder, Anomaly Detection, Unsupervised Learning, Water


Quality Monitoring

1 Introduction

Water is one of the most important things for all known forms of life [1]. Brazil
hold some of the most significant rivers in America. The Amazon forest keeps a huge
a vast ecosystem, which is also irrigated by the Amazon River. The increase of com-
panies exploring the natural wealth in those areas has increased, thus creating the
need to monitor and care for the waters of the river, to ensure its quality [2].
To address this task, Artificial Neural Networks have promising solutions for the
particular scenario in the Amazon, a lightweight Autoencoder model, trained to detect
anomaly changes in a time series of water composition data, can be used to consis-
tently monitor the River such as the Amazon.
The process of training is conducted with a dataset containing water quality indica-
tors, measured through a distribution system, those measures are capable to qualify if
the water is in a usable state. In order to train the Autoencoder, the indicators are used
as input, the encoder represents it to latent space, and the decoder reconstructs. The
reconstruction error is quantified by Mean Squared Error (MSE), hence back propa-
gating it aiming to optimize. As a result, a trained model with errors in reconstruction
process indicates that an anomaly in the time series was identified.
2

Therefore, the problem of monitoring the waters of Amazon for anomalies is a


must, this present work proposes the development of a trusty, unsupervised and light-
weight deep Autoencoder model. To do so, the document is divided into; 2 Back-
ground, the necessary theory to analyze the work; 3 Methodology, exposing the used
training strategy and architecture; 4 Results, to expose the metrics obtained from test;
and 5 Conclusion, to discuss the result, and conclude if the objective of development
was obtained.

2 Background

2.1 Autoencoders

Bengio, Yoshua [3] shows the architecture of the Basic Autoencoder. It consists of
an input vector that is represented in a latent space, whose is going to be reconstructed
through the output.
As exposed by Vincent and Pascal [4] the characteristics of the encoding and de-
coding process, was proven useful for training deep networks. Also from its proper-
ties the algorithms find hard to reach large-weight solutions, meaning that it learns to
exploit statistical regularities present in the training set [3].
Autoencoders are composed by two essential components, the encoder fϴ:
y=f θ ( x)=s(Wx+b) (1)
and the decoder gϴ’:
z=g θ ' ( y )=s(W ' x +b ' ) (2)
Where W is the set of weights that can be set individual for encoder and decoder or
W' = T(W), in this case it is said to have tied weights, b is the bias. As said the hidden
representation y, resembles the latent representation between the input x and the re-
construction z. The Autoencoder training objective is to optimize the error of recon-
struction of the input, so it can adjust its weights, this loss can be obtained in various
ways, the used in the present work is MSE witch will be further discussed in section
3.3.

2.2 Anomaly Detection

Anomalies comes from the premise of imbalanced data [5], where most of the val-
ues present in a dataset represents a normal state or regime in the signals or features,
if those regimes are broken, the breakages are called anomalies. The difficulties that
come with the detection of those behaviors come from long periods of data that
doesn't have instances of those representations. Hence, the models responsible to ad-
dress this task tend to over fit, memorizing the data structures of the training dataset.
As discussed above, Autoencoders have the behavior to learn statistical regulari-
ties, tied to the measured error, from the loss function, results in a promising option to
detect anomalies. Trained to reconstruct signals that have a low rate of anomalies, the
3

decoder can find hard to reconstruct those instances, resulting in a loss increase,
which can be used to identify an anomaly.

3 Methodology

3.1 Dataset

The dataset originates from an industrial challenge opened in 2018, in the Genetic
and Evolutionary Computation Conference, to perform online anomaly detection in
water quality [6]. The data is composed by 9 measured indicators and 2 informational
data columns captured in a minute basis, as shown in Table 1.

Table 1. Description of the given time series data [6].

Column Name Description


Time of measurement, given in following format: yyyy-mm-
Time
dd HH:MM:SS
Tp The temperature of the water, given in °C.
Cl Amount of chlorine dioxide in the water, given in mg/L (MS1)
pH PH value of the water
Redox Redox potential, given in mV
Leit Electric conductivity of the water, given in μS/cm
Trueb Turbidity of the water, given in NTU
Cl_2 Amount of chlorine dioxide in the water, given in mg/L (MS2)
Fm Flow rate at water line 1, given in m3/h
Fm_2 Flow rate at water line 2, given in m3/h
Marker if this entry should be considered as a remarkable
EVENT
change resp. event, given in boolean.
The values disposed in the dataset are important water quality indicators, for the
study developed, any unexpected changes were considered as events (anomalies).
Flow rate and the temperature are operational information, not all changes in them
may be considered as events.

Fig 1. Features of the dataset over time, red dots indicates events
4

In Figure 1, can be observed the binary classification used, and the high imbalance
present in the dataset (1:67.64). For the purpose of training, the dataset passed
through preprocessing, filling the null values present by propagating the last valid
values, and also by normalizing the data, to avoid outliers interfere in training. The
separation for training and testing are the following; 20% for testing; 80% for train-
ing; and 20% of the training is dedicated to validating.

3.2 Autoencoder Architecture

The proposed Autoencoder architecture takes 9 input features, and is structured


into two main components: an encoder and a decoder. The encoder consists of five
fully connected (dense) layers. The first four hidden layers are set to 180 neurons,
activated by ReLu function. These are followed by a fifth layer with 90 neurons,
which serves as the bottleneck layer (or latent representation). Conversely, the de-
coder takes the latent representation and passes it through five dense layers. The lay-
ers each have 180 neurons and are activated by ReLu. Finally, the output layer recon-
structs the original signal, consisting of 9 neurons, corresponding to the input features.

3.3 Mean Squared Error

For the process of training, and measuring the distance between the read signal and
the expected behavior of it, the model takes advantage of the loss function MSE. The
MSE is responsible to calculates the average difference between the reconstructed
input and the original one [7], this function returns a number between 0 and 1. The
error function can be defined as:
n

∑ ( x i−z i )2
L( x , z)= i=1 (3)
n
Such function is then used to set the parameters ϴ, and as it's going to be further
discussed in this study can be also used to identify anomalies.

3.4 Optimization
The model is trained in an unsupervised manner, operating as a self-supervised
learning task, where the input and the target data are the same. The objective function
is defined as the reconstruction error between the input and the output, measured by
the MSE. Therefore, defining the problem as a Linear Regression, where the objective
is to minimize the distance between the reconstructed input and the original.
The Adam optimizer is utilized to minimize this objective. We select Adam for its
computational efficiency and ease of use, as it effectively handles the complexities of
the dataset, notably its significant class imbalance and large scale [8].
5

4 Validation process
The validation and testing procedure comprised the following steps:

1. Monitoring Training: At each training epoch, the model was evaluated


on an unseen validation set. The reconstruction loss was recorded to monitor
the learning curve and verify that the model was not over fitting.
2. Threshold Selection: After training, the model processed the samples of
the validation set. The reconstruction error was calculated for each sample.
An exhaustive search was performed over the range of observed error values
to identify the optimal classification threshold. The first 1000 samples of loss
where considered candidates of threshold τ, samples with an error >τ were
flagged as anomalies. The threshold that maximized the F1-score compered
with the binary labels of the corresponding timestamps on this validation
subset was selected.
3. Testing: The trained model was then evaluated on the hold-out test set.
Reconstruction errors were computed for all test samples, and the optimal
threshold τopr from Step 2 was applied to generate the final binary anomaly
predictions.

4.1 Used Metrics


Since the dataset has a high imbalance ratio, metrics like accuracy could result in a
misunderstanding of the results, due to this relation one of the best metrics that can
describe the models accuracy is F1-score of each class (anomaly and not anomaly),
the metric can be calculated as follows:
TP TP
2∗ ∗
TP+ FN TP+ FP
F 1score = (4)
TP TP
+
TP+ FN TP+ FP

Note that TP, means true positives, FP for false positives, FN for false negatives.
Additionally, the confusion matrix helps having a clear vision of the false negatives
and positives, which tied to Recall and Precision can result in a string understanding
of the model, Recall and Precision can be defined as follows:

TP (5)
Recall=
TP+ FN
TP (6)
Precision=
TP+ FP
6

5 Results

The training process was executed within 30 epochs, due to hardware and time
limitations. However, the loss of training seemed to have come to a stable point. As
illustrated in Figure 2, the loss of training exhibited a sharp decline during the first
five epochs, and subsequently stabilized, fluctuating within a range of approximately
0.065 to 0.075. Additionally, the validation loss followed a similar trajectory, starting
with a lower loss, and variate more during the next epochs, keeping lower values in
the majority of the epochs.

Fig 2. Training and validation loss over epochs


To qualitatively assess the model's performance, Figure 3 compares the original
input signals against their reconstructions for the first four features of the test set. The
reconstructed signals (orange) closely track the original time series (blue), indicating
that the model has successfully learned the underlying data distribution. However,
some discrepancy is observed in the reconstruction of peak amplitudes.

Fig. 3. Test input data over its reconstruction on the first 4 features
7

5.1 Anomaly Classification Performance

Following the threshold optimization procedure described in Section 4, the contin-


uous reconstruction error was converted into binary anomaly predictions for the test
set. The model predicted a higher number of anomalies than were present in the la-
bels, indicating a tendency toward false positives. This behavior is quantified in the
confusion matrix shown in Figure 4. The model produced 6.821 false positives and,
more critically, 944 false negatives. While false positives increase the operational
burden, false negatives represent undetected events and are therefore the more alarm-
ing error type for water quality monitoring.

Fig. 4. Confusion matrix of anomaly predicted over anomaly target in


test data

The overall classification report is presented in Table 2. Due to the significant class
imbalance in the dataset, accuracy is not a reliable performance metric. The F1-score
for the anomaly class is 0.263, with a precision of 0.169 and a recall of 0.595. This
indicates that while the model is capable of identifying a majority of the anomalous
events (due to high recall), it does so at the cost of an increase in the rate of false true.
The macro accuracy is provided, but due to imbalance can't be interpreted as a quality
measure of the model.

Table 2. Classification Report of testing data

precision recall F1-score Support


False 0.993 0.95 0.971 137237
True 0.169 0.595 0.263 2329
Accuracy 0.944
Macro avg 0.581 0.772 0.617 139566
Weighted avg 0.979 0.944 0.959 139566
8

6 Conclusion
The article proposed a lightweight Autoencoder capable of detecting anomalies in
the waters of the Amazon River. Although the dataset was not sourced from the Ama -
zon, the indicators demonstrated the viability of the approach. Based on the acquired
metrics, the resulting model would not be suitable for a production environment, due
to the high number of false negatives and false positives.

Nevertheless, the method of using Autoencoders for unsupervised classification


proved to be promising, as it requires less labeled data. Additionally, given the
model's ability to closely reconstruct the input signals, the proposed architecture could
lead to more accurate results with further improvements. The main limitations ob-
served in the experiment are related to the Autoencoder architecture itself; exploring
other structures, such as regression models or convolutional neural networks, as well
as modifications to preprocessing, such as removing anomalies from the training set,
which could enhance performance.

Future work should focus on addressing these limitations. Key directions include
reorganizing the dataset, further increasing the number of training epochs, and investi-
gating architectures such as Long Short-Term Memory and Convolutional Neural
Networks, which may yield different learning curves and better capture temporal
dependencies. Additionally, research into adaptive thresholding techniques could lead
to more robust anomaly detection.

References
1. R. M. Clark, S. Hakim, and A. Ostfeld, Eds., Handbook of Water and Wastewater Systems
Protection. New York, NY: Springer New York, 2011. doi: 10.1007/978-1-4614-0189-6.

2. “Ameaças à Amazônia,” ISPN - Instituto Sociedade, População e Natureza. Accessed:


Mar. 01, 2026. [Online]. Available: [Link]
amazonia/

3. Y. Bengio, “Learning Deep Architectures for AI,” Foundations and Trends in Machine
Learning, vol. 2, no. 1, pp. 1–127, Nov. 2009, doi: 10.1561/2200000006.

4. P. Vincent, H. Larochelle, Y. Bengio, and P.-A. Manzagol, “Extracting and composing


robust features with denoising autoencoders,” in Proceedings of the 25th international
conference on Machine learning, in ICML ’08. New York, NY, USA: Association for
Computing Machinery, Jul. 2008, pp. 1096–1103. doi: 10.1145/1390156.1390294.

5. V. H. A. Ribeiro and G. Reynoso-Meza, “Multi-criteria Decision-Making Techniques for


the Selection of Pareto-optimal Machine Learning Models in a Drinking-Water Quality
Monitoring Problem,” Int. J. Info. Tech. Dec. Mak., vol. 23, no. 01, pp. 447–474, Jan.
2024, doi: 10.1142/S0219622023500104.
9

6. F. Rehbach, S. Moritz, S. Chandrasekaran, M. Rebolledo, M. Friese, and T. Bartz-Beiel-


stein, “GECCO 2018 Industrial Challenge: Monitoring of drinking-water quality.”
Cologne University of Applied Sci ences, Gummersbach, Germany, 2018.

7. “The Elements of Statistical Learning: Technometrics: Vol 45, No 3.” Accessed: Mar. 08,
2026. [Online]. Available: [Link]

8. D. P. Kingma and J. Ba, “Adam: A Method for Stochastic Optimization,” Jan. 30, 2017,
arXiv: arXiv:1412.6980. doi: 10.48550/arXiv.1412.6980.

You might also like