Preprint
Article

This version is not peer-reviewed.

Bayesian Surprise-Enhanced Random Forests for Rare Anomaly Classification in Environmental Sensor Data

Submitted:

12 August 2026

Posted:

13 August 2026

You are already at the latest version

Abstract
Given the inherent rarity of anomalous readings in environmental sensor data, tree-based models often provide high weighted classification metrics but low anomaly-class recall values, leading to excessive missed anomalies. This study proposes that integrating Bayesian surprise with a random forest classifier can simultaneously enhance weighted classification metrics and class-specific classification accuracy when classifying environmental sensor data. To test this approach, real air-, reservoir-, and river-water quality datasets are used to evaluate the new ensemble method. Bayesian surprise, which is defined using relative predictive surprise, is standardized and serves as an additional anomaly-informed feature. A random forest classifier is employed to classify raw sensor data augmented with the resulting relative predictive surprise values. Empirical experiments indicate that relative predictive surprise is robustly more effective than Rousseeuw–Croux estimators, Tukey interquartile ranges, and percentile-based rules in identifying anomalous sensor measurements. Moreover, augmenting the random forest classifier with relative predictive surprise values improves anomaly-class recall values and weighted classification metrics, indicating fewer missed anomalous sensor measurements. In conclusion, the relative predictive surprise is a computationally simpler and more effective anomaly measure compared to four baseline metrics. This anomaly measure and a random forest classifier emerge as a novel tool for balancing weighted classification metrics and class-specific classification accuracy in classifying environmental sensor data.
Keywords: 
;  ;  ;  ;  

1. Introduction

Advances in information technology have enabled the deployment of sensors to monitor environmental phenomena, such as air and reservoir water quality. For example, the Taiwanese government has installed environmental sensors to measure total phosphorus, chlorophyll a, and transparency to warn of critical river water quality. The government shares historical sensor measurements with residents through websites. Flagging anomalous sensor readings is governed by specific rules published on these websites.
Nevertheless, recent severe climatic changes or extreme events may cause environmental sensor data to undergo distribution shifts. New observations and old sensor measurements follow different probability distributions. Thus, it is difficult to apply a single probability distribution to model the sensor data and flag anomalous sensor measurements. It may therefore be necessary to recalibrate frequently existing rules to accommodate new anomalies.
Machine learning algorithms can help mitigate the burden of frequent recalibration of existing rules. In practice, training tree-based models for accurately processing large volumes of data has become feasible and computationally efficient. Such models may be trained to separate normal and anomalous sensor data, and human experts next inspect the resulting predictions to decide whether to accept or override the detected anomalies. However, a challenge may be encountered in implementing such an idea. Since anomalous data are naturally infrequent, tree-based models often fail to achieve balanced classification performance between normal and anomalous sensor data [1,2]. They may output high weighted classification metrics, but anomaly-class recall values remain low, implying that excessive false negatives have been generated.
This study proposes that integrating Bayesian surprise (e.g., [3]), defined using relative predictive surprise ( R P S ), with a random forest classifier may balance weighted classification metrics and the class-specific classification accuracy. R P S values are first computed, standardized, and then added as anomaly-informed features for real air quality, reservoir water quality, and river water quality datasets. Before augmenting with these R P S values as new features, the resulting predictive surprise values are compared to the Rousseeuw–Croux estimators [4], the Tukey interquartile range [5], and a simple percentile-based rule to ensure that they correctly flag anomalies on complementary cumulative probability curves. A random forest classifier is next employed to classify the augmented datasets. Based on empirical results, this study investigates whether the corresponding weighted classification metrics and the class-specific classification accuracy are simultaneously improved after adding the R P S values as new features.
This study anticipates that this research will fill three research gaps to make the corresponding contributions:
  • The first research gap is the lack of a computationally simple anomaly measure for environmental sensor data, which usually exhibit heavy tails. Calculating the R P S requires fewer steps than the computation of Rousseeuw–Croux estimators.
  • The second research gap concerns the performance of tree-based models in classifying environmental sensor data. Since anomalous environmental sensor measurements are naturally infrequent, tree-based models tend to focus on improving weighted classification metrics and may cease to optimize the classification accuracy of anomalous classes once the weighted accuracy is maximized [1,2]. This study aims to balance weighted classification metrics and the class-specific classification accuracy by aggregating R P S values as new anomaly-informed features.
  • The third research gap concerns the robustness of anomaly thresholds for heavy-tailed sensor data. When existing anomaly measures (for example, Rousseeuw–Croux estimators and percentile rules) are applied to different heavy-tailed distributions, the thresholds for separating normal and abnormal sensor readings may need to be re-tuned for more accurate separation. In contrast, relative predictive surprise is robust to different tail behaviors. This study adopts a fixed anomaly-detection criterion based on R P S across all heavy-tailed environmental sensor datasets.
  • The final contribution of this study is enhanced explainability. Without an anomaly measure, a tree-based model is like a ’black box’ in classifying normal and anomalous sensor data. It provides only limited explainability for its classification results. This study integrates a tree-based model with R P S values as anomaly-informed features to provide distribution-level information about how unexpected each sensor reading is, thereby improving the explainability of the resulting classifier.
The remainder of this article is organized into five sections. Section 2 presents a literature review relevant to this study. Section 3 elucidates Bayesian surprise and provides a brief review of the random forest classifier. Section 4 reports experimental results that test the combination of relative predictive surprise values and the random forest classifier on three real datasets of air quality, reservoir water quality, and river water quality. Based on these results, Section 5 offers a discussion. Section 6 presents the conclusions of this study.

2. Literature Review

Because environmental sensor data commonly exhibit heavy-tailed behaviors, the first part of this literature review focuses on prior studies that proposed anomaly measures for heavy-tailed data. The second part reviews published studies on data augmentation methods for heavy-tailed data, since this study calculates R P S values from real environmental sensor datasets and uses them as additional anomaly-informed features.

2.1. Anomaly Measure for Heavy-Tailed Data

A brief review of the literature on anomaly measures for heavy-tailed data identifies two important research gaps. First, a reliable threshold for distinguishing normal observations from anomalous ones has not yet been established. If a reliable threshold is unavailable, augmenting with anomaly-informed features provided based this threshold may not be confidential. Second, the computation of existing anomaly measures often remains unnecessarily complex. In published studies, anomaly measures for heavy-tailed data have generally been grouped into three main categories:
The first approach is based on extreme value theory and tail modeling [7,8,9,10,11]. Rather than modeling the entire heavy-tailed distribution to distinguish normal observations from anomalies, this approach focuses on the tail behavior and fits the tail using a specific probability distribution, such as the generalized Pareto distribution. Anomalies are then identified on the basis of the fitted tail model. In general, the choice of tail model depends on the heaviness and shape of the tail. Representative studies suggest that the Hill estimator [7] is one of the most widely used methods for characterizing tail heaviness. To address finite-sample issues, a previous study [8] proposed a trimmed version of the Hill estimator. Building on this idea, Bhattacharya et al. [9] developed an automatic, data-driven procedure for flagging observations that deviate from the central and intermediate structure of the data. Verardi and Croux [10] extended Tukey’s interquartile range method [5] by incorporating the medcouple to account for skewness in both univariate and multivariate settings, thereby producing an adjusted boxplot for outlier detection. Li et al. [11] estimated sample skewness and constructed empirical cumulative distribution functions to identify tail regions, which were then used to aggregate tail probabilities and define an outlier score.
The second approach comprises probability- and kernel-based methods for modeling heavy-tailed distributions. In this approach, researchers first derive parametric or nonparametric expressions to describe a heavy-tailed distribution, and then identify anomalies based on the resulting probability models. Horváth et al. [12] employed copula functions to estimate the joint distribution of a multivariate heavy-tailed random vector and constructed an anomaly score from the resulting copula-based estimation. A copula enables separate modeling of the marginal distributions and their dependence structure, capturing only the dependency among variables in a multivariate distribution. Bourigault and Mandic [13] combined generalized hyperbolic processes with kernel density estimation and one-class support vector machines to develop anomaly detection frameworks, where the anomaly score is defined using the fitted probability density function. Tortora et al. [14] proposed a model-based clustering approach based on mixtures of multiple scaled contaminated normal distributions to effectively accommodate skewness, heavy tails, or their combination in the classification of heavy-tailed data. This framework allows (1) flexible cluster shapes in terms of skewness and kurtosis and (2) component-wise and directional outlier detection.
The third approach focuses on deep learning models for representing complex, high-dimensional heavy-tailed data distributions. However, most of these models were originally designed for detecting anomalous images. A key distinguishing feature among the models lies in their learning mechanisms. For example, Zenati et al. [15] investigated generative adversarial networks and proposed adversarially learned anomaly detection, in which images with large reconstruction errors are identified as anomalous. Dionelis [16] also explored generative adversarial networks and adopted a similar reconstruction-based criterion for anomaly detection; however, their learning objective is to reconstruct the tail region of a heavy-tailed data distribution. Yang et al. [17] developed a transformer-based reconstruction module for image anomaly detection.

2.2. Data Augmentation Methods for Heavy-Tailed Data

This study proposes that augmenting heavy-tailed data with R P S values may improve the accuracy of classifying these data using a random forest classifier. A concise review of prior studies on data augmentation methods for heavy-tailed data reveals two research gaps. First, existing data augmentation methods for heavy-tailed data are largely restricted to specific application domains (for example, image classification), and their implementation can be inefficient because they typically require tuning many hyperparameters. For instance, a recent study [6] developed a distance-based scheme to enhance the performance of a random forest classifier; however, training this classifier must be performed twice to tune certain hyperparameters.
Other relevant studies in image classification are also available. Ma et al. [18] observed a substantial imbalance between the numbers of normal and abnormal images in an image classification problem. To address this issue, they proposed a four-phase training scheme for a conventional neural network. The second phase of this scheme incorporates a feature-uncertainty representation based on a Gaussian distribution, which provides probabilistic features of the decision boundary separating normal and abnormal images. Introducing this probabilistic feature improves the image classification performance of a convolutional neural network.
Song et al. [19] also investigated image classification problems. They developed a contrastive visual–language model that consists of visual and semantic components. The visual components were created using images, whereas the semantic features are generated using the text sequences associated with the images. Experimental results demonstrated that the proposed contrastive visual–language model improves the F1 scores for classifying normal and abnormal images.
Delaigle and Hall [20] investigated the effect of heavy tails on cardiomyopathy microarray data and Affymetrix spike-in data. They calculated statistical features to conduct their analysis. The purpose of this calculation is to recover influential genes that would otherwise be incorrectly discarded due to the presence of outliers.

3. Methods

Suppose X 1 , X 2 , X N represent a collection of N environmental sensor measurements. These X 1 , X 2 , X N may be acquired asynchronously. Each X i is a an n-dimensional tuple, x i 1 , x i 2 , x i n ( i = 1 , 2 , N ) . Each x i j ( j = 1 , 2 , n ) may be either normal or anomalous.

3.1. Bayesian Surprise

Suppose a null hypothesis H 0 states that the collected x i j ( i = 1 , 2 , N ; j = 1 n ) sensor measurements follow a specific probability distribution, such as the Student’s t distribution. A new observation x o b s may be a newly observed value for the j-th sensor variable. It may be an outlier of x 1 j , x 2 j , x N j if its resulting p value is below a predetermined significance level α (e.g., α = 0.05 ). This outlier is a potential anomaly. The p-value is calculated by [3]
p = Pr t i j t o b s α
where t i j = x i j μ j s j and t o b s = x o b s μ j s j , μ j is the mean of referenced x 1 j , x 2 j , x N j sensor measurements, s is their standard deviation and Pr denotes the probability. This Pr is equal to # ( t i j = t ) N ( i = 1 , 2 , N ) in which # ( t i j = t ) denotes the number of observations equals to t. However, the distribution of x 1 j , x 2 j , x N j may exhibit heavy tails. The p value-based anomaly detection may therefore yield excessive false positives. To address this issue, scholars proposed alternative approaches (e.g., [21]) that better characterize the rarity of an observation x o b s with respect to the reference measurements x 1 j , x 2 j , x N j . In this study, considering that reference measurements x 1 j , x 2 j , x N j follow an unknown distribution, the Bayesian surprise, defined through the R P S [3], is adopted to assess whether a t o b s is rare. For discrete sensor measurements, the R P S is defined by [3,21,22]:
R P S = Pr t o b s sup Pr t i j = Pr t o b s Pr m a x t i j
where sup is the supremum, the subscript m a x denotes the maximum, i = 1 , 2 , N , and j = 1 , 2 , n . The theoretical foundation of Equation (2) is related to the Kullback-Leibler divergence [23]. Unlike conventional approaches that seek observations inconsistent with a specific probability distribution, Equation (2) is used in this study to identify sensor readings that are relatively rare in the reference sensor data.
The surprise index can be used to determine whether t o b s is anomalous [21,22]. We can derive:
S I = i = 1 N Pr 2 t i j Pr t o b s i = 1 N Pr t i j Pr m a x t i j Pr t o b s = Pr m a x t i j i = 1 N Pr t i j Pr t o b s = Pr m a x t i j Pr t o b s
where S I represents the surprise index. Equation (3) indicates that the maximum of the S I is equal to the reciprocal of the R P S . This relationship may serve as an important basis for determining the threshold at which an R P S value implies an anomaly. Table 1[24] presents the referenced rules for flagging anomalies based on S I and R P S [24].

3.2. Random Forest Classifier

Suppose R 1 , R 2 , R N represent the N tuples consisting of raw sensor data and their R P S vslues in which R i = x i 1 , x i 2 , x i n , r i 1 , r i 2 , r i n and r i j = R P S ( x i j ) ( i = 1 , 2 , N ; j = 1 , 2 , n ) and Y is the class label. To avoid data leakage and possible confusion with the training-test split used in random forest classification, it must be emphasized that the R P S value of a new observation x o b s (or t o b s ) is computed based on the N raw reference observations x i j , x 2 j , x N j .
A random forest is a tree-based ensemble learning algorithm in which each tree is constructed using a random subset of the available information [25]. In classification tasks, it learns a prediction function f ( R ) from the training observations R i i = 1 , 2 , N to predict the class label Y. The learning objective is defined through a loss function L o s s Y , f ( R ) , which quantifies the mismatch between the predicted and actual labels. For classification under the zero-one loss criterion, the optimal prediction function is obtained by minimizing the expected loss E R Y L o s s Y , f ( R ) where the expectation E R Y is taken over the joint distribution of R and Y. A commonly used loss function is [26]:
L o s s Y , f ( R ) = I Y f ( R ) = 0 if Y = f ( R ) 1 otherwise
where I is the indicator function. If Y is the set containing all possible Y values, minimizing the E R Y L o s s Y , f ( r ) for the zero-one loss results in
f ( R ) = arg max Y Y P r Y = y | R
In ensemble learning, the prediction function f is constructed from a collection of base learners h 1 ( R , Θ 1 ) , h 2 ( R , Θ 2 ) , h K ( R , Θ K ) in which Θ k ( k = 1 , 2 , K ) denotes the random variables used to build the k-th learner. These random variables are assumed to be independent, and the resulting base learners are aggregated to form the final prediction function f:
f ( R ) = arg max Y Y k = 1 K I Y h k R , Θ k
The learners h 1 ( R , Θ 1 ) , h 2 ( R , Θ 2 ) , h K ( R , Θ K ) build the tree classifier by recursively splitting the training data R i ( i = 1 , 2 , N ) data into a splitting criterion that measures the purity of a leaf node. In this study, the G i n i index is chosen as the splitting criterion. It is defined as
G i n i = 1 i = 1 C P i 2
where C is the number of classes and P i denotes the proportion of observations belonging to class i in the node. Data partitioning based on Equation (7) is carried out recursively until a stopping criterion is satisfied. For classification of a new observation, the observation is propagated through each tree in the forest until it reaches a terminal node. Unlike a single decision tree model, random forest does not require pruning during tree growth. The absence of pruning simplifies model construction and is one of the practical advantages of random forest.
Algorithm 1 [26] presents the procedure for constructing a random forest classifier. First, bootstrap samples are generated from the observations R 1 , R 2 , R N data. This step returns each bootstrap sample to the R 1 , R 2 , R N by sampling with replacement. Each bootstrap sample is then used to grow a classification tree until a stopping criterion is met. During this process, the sample is recursively split to determine the best partition at each node.
Algorithm 1 Random forest classifier [26]
Input: 
Training observations { ( R i , Y i ) } i = 1 N , where R i = ( x i 1 , x i 2 , , x i n , r i 1 , r i 2 , , r i n ) contains raw sensor measurements and R P S -based anomaly-informed features; number of trees K; number of randomly selected features m
Output: 
A trained random forest classifier
1:
for k = 1 to K do
2:
    Draw a bootstrap sample from { ( R i , Y i ) } i = 1 N with replacement
3:
    Initialize the root node using all observations in the bootstrap sample
4:
    while the stopping criterion is not satisfied do
5:
        Randomly select m features from all available features
6:
        Determine the best split among the selected features according to the G i n i index
7:
        Split the current node into child nodes according to the best split
8:
    end while
9:
    Grow an un-pruned classification tree h k ( R , Θ k )
10:
end for
11:
Aggregate the predictions of { h k ( R , Θ k ) } k = 1 K by majority voting
12:
For a new observation, compute its R P S value using the reference observations
13:
return the resulting random forest classifier
In addition to the G i n i index, several hyperparameters must be specified when implementing a random forest classifier, including:
  • Maximum depth of the tree;
  • Number of trees in the forest;
  • Minimum number of samples required to split an internal node; and
  • Minimum number of samples required to be at a leaf node.
Section 4.4 further examines the effects of these four hyperparameters on the classification accuracy of a random forest classifier with and without the inclusion of R P S values as anomaly-informed features.

4. Applications

To improve the quality of life, the Taiwanese government has deployed environmental sensors to monitor environmental conditions, including air quality, reservoir water quality, and river water quality. It has also constructed websites to share historical sensor measurements. This study uses three real datasets collected from these websites to evaluate the performance of the random forest classifier and R P S .

4.1. Air Quality

The first real dataset contains 24,007 records of SO2, CO, NO2, PM2.5, and air quality index (AQI) measurements [27]. These measurements were collected daily in 2024 from 60 monitoring stations across Taiwan. The units of SO2 and NO2 are ppb, whereas that of CO is ppm. The unit of PM2.5 is μ g / m 3 . Figure 1 depicts the distributions of SO2, CO, NO2, PM2.5, and AQI. Table 2 presents their summary statistics, where I Q R denotes the Tukey interquartile range, and γ H i l l represents the trimmed Hill index [8].
As mentioned earlier, the trimmed Hill index [8] was used to characterize the heaviness of a tail. For the j-th sensor measurement, suppose χ ( 1 ) χ ( 2 ) χ ( N ) denote the ordered x 1 j , x 2 j , , x N j ( j = 1 , 2 , n ) sensor data. The trimmed Hill index is defined as [7,8]
γ H i l l = 1 k k 0 i = k 0 + 1 k ln χ ( N i + 1 ) χ ( N k )
where 1 k N , and k 0 denotes the number of the largest extremes trimmed from the estimation, with 0 k 0 < k . Based on the published article [8], Table 3 presents our interpretation of the resulting γ H i l l values. These values are used as practical reference thresholds rather than universal decision rules. In practice, k 0 and γ H i l l can be computed using standard spreadsheet software.
As expected, Figure 1 and Table 2 suggest that the distributions of SO2, CO, NO2, PM2.5, and AQI exhibit substantial upper-tail heaviness. Evidence includes the large kurtosis values and high γ H i l l values in Table 2, as well as the pronounced upper-tail spread shown in Figure 1. Under such distributional characteristics, applying the standard Z-score to anomaly detection may yield incorrect detections. Extreme x i j ( i = 1 , 2 , N ; j = 1 , 2 , n ) can inflate their mean and standard deviation, thereby masking potential anomalies.
Furthermore, Equation (9) presents the Pearson correlations among SO2, CO, NO2, and PM2.5. In particular, CO and NO2 exhibit a strong positive correlation. Equation (9) suggests that these two pollutants may share common emission sources, potentially related to fossil-fuel combustion.
S O 2 C O N O 2 PM 2.5 S O 2 C O N O 2 PM 2.5 1 0.208 0.266 0.284 0.208 1 0.735 0.592 0.266 0.735 1 0.434 0.284 0.592 0.434 1
Next, this study combines a log-log plot and dumbbell plots to compare the ranges of anomalies identified by the R P S and four baseline metrics. Since the γ H i l l values reported in Table 2 suggest substantial upper-tail heaviness, the Tukey interquartile range ( I Q R ), the Rousseeuw-Croux estimators Z S n and Z Q n , and a simple percentile-based rule are adopted as baselines. According to the I Q R , a sensor measurement x i j ( i = 1 , 2 , , N ; j = 1 , 2 , , n ) is considered anomalous if it satisfies
x i j < Q 1 1.5 I Q R or x i j > Q 3 + 1.5 I Q R
in which Q 1 and Q 3 are the first and third quartiles; respectively. Meanwhile, Rousseeuw-Croux estimators Z Q n and Z S n [4] are defined as
Z Q n = x i j median ( x i j ) Q n
Z S n = x i j median ( x i j ) S n
where, for each k, S n = 1.1926 median i median j x i k x j k and Q n = 2.219 x i k x j k : i < j ( L ) . Here, · is the absolute value, and { · } ( L ) denotes the L-th order statistic obtained by sorting all pairwise distances x i k x j k for i < j in an ascending order and selecting the L-th element. Moreover, L = floor N 2 + 1 ! 2 ! floor N 2 1 ! where floor denotes the floor function, ! represents the factorial, i , j = 1 , 2 , , N , and k = 1 , 2 , , n .
A log-log plot is employed to separate the regions associated with normal and anomalous observations on the complementary cumulative probability curve. In this plot, anomalous observations tend to occupy an approximately linear segment. As shown in Figure 2(a)-Figure 2(d), the slope between adjacent black points is calculated to detect this approximately linear segment. This segment is shaded in gray in Figure 2(a)-Figure 2(d). The 90th percentile is further marked as a reference threshold to verify the placement of the gray region. Blue, orange, red, and green dumbbells in Figure 2(a)-Figure 2(d) represent the anomaly ranges identified by R P S , I Q R , Z S n , and Z Q n , respectively, and the legend in each panel lists the corresponding criteria.
Figure 2(a)-Figure 2(d) demonstrate that Equation (2) is more effective than Equations (10)-(12) in detecting anomalous pollutant concentrations. In Figure 2(a)-Figure 2(c), the left boundaries of the gray regions closely align with the 90th percentiles, while in Figure 2(d) the discrepancy between the left boundary and the 90th percentile is negligible. These results indicate that the gray regions provide sufficiently accurate estimates of the ranges occupied by anomalous pollutant concentrations in all four plots. The blue dumbbells are consistently located close to the gray regions, supporting the effectiveness of Equation (2). In contrast, although the orange dumbbell in Figure 2(a) is also close to the gray region, the orange dumbbells in Figure 2(b)-Figure 2(d) are shorter than the widths of the corresponding gray regions, suggesting that Equation (10) yields an excessive number of false negatives. Moreover, lowering the thresholds from Z S n > 3.5 and Z Q n > 3.5 to Z S n > 3 and Z Q n > 3 could improve the agreement between the red and green dumbbells and the gray regions. This observation suggests that the original thresholds, Z S n > 3.5 and Z Q n > 3.5 may be overly conservative for anomaly detection.
Next, this study applies a random forest classifier to classify the collected air quality data. Before training the random forest classifier, standardizing the R P S values of these air quality data is implemented; thus, they can be incorporated as anomaly-informed features. For the SO2 concentration, its standardized R P S is calculated by
R P S ¯ S O 2 = R P S S O 2 Median R P S S O 2 I O R S O 2
where the overline denotes the standarization, the R P S S O 2 represents the R P S value derived from the SO2 concentration, Median ( · ) and I Q R S O 2 are its median and I Q R ; respectively. Applying the same procedures yields R P S ¯ C O , R P S ¯ N O 2 , and R P S ¯ P M 2.5 .
In Taiwan, the AQI is used to indicate whether air quality may be unhealthy. Based on the AQI regulation [27], the official six-category AQI is consolidated into three health-oriented categories. The class of good to acceptable contains the official categories of good and ordinary air quality are combined into a class of good to acceptable, whereas the class of unhealthy is composed of the categories of unhealthy, very healthy, and harmful. Accordingly, this study defines the class label Y in the form as
Y = 0 AQI 100 ( Good to acceptable ) 1 101 AQI 150 ( Unhealthy for sensitive acceptable groups ) 2 AQI 151 ( Unhealthy )
where Equation (14) yields 22,534 instances for Y = 0 , 1,367 instances for Y = 1 , and 106 instances for Y = 2 , indicating substantial class imbalance.
The random forest classifier is subsequently trained on the collected air quality data enriched with standardized R P S -based features. Within this framework, the standardized R P S variables do not determine or alter the class labels Y. Instead, they function as auxiliary predictors that characterize the abnormality intensity of individual pollutants. Accordingly, the proposed framework is more appropriately viewed as an AQI-category classification approach with anomaly-informed feature augmentation, rather than an anomaly-based relabeling scheme.
Unless otherwise specified, the random forest classifier is implemented with the scikit-learn package. Default hyperparameter settings are employed, except that the maximum depth of the tree is set to 8 and the class weight is set to ’balanced’. The latter setting is used to address class imbalance automatically. Specifically, scikit-learn assigns class weights inversely proportional to the empirical class frequencies in the training data. Thus, minority-class observations receive greater weights during model fitting, whereas majority-class observations receive lower weights, reducing the model’s tendency to favor majority classes.
The collected air quality data are randomly partitioned into training and testing subsets, with 75% of the instances used for model training and the remaining 25% reserved for performance evaluation. Because both the train-test split and random forest training involve randomness, results from a single run of the random forest classifier may be unstable. Therefore, it is independently trained using different random seeds. Nineteen random seeds are selected from the integer range of 42 to 65.
Across 19 runs, the standard deviation of each macro- or weighted-average classification metric, such as the macro F1-score, is below 5% of its corresponding mean, indicating that the performance estimates are sufficiently stable. For each run, the confusion matrix is row-normalized by dividing every entry in a row by the sum of that row. Thus, each row represents the distribution of predicted classes conditional on the true class.
Equation (15) and Table 4 present the mean and standard deviation of the normalized confusion matrices and classification metrics obtained across 19 repeated runs. Each classification metric is reported as mean ± standard deviation. Because Equation (14) describes a multi-class classification problem, the AUC is computed using a one-vs-rest approach in which each class is treated as the positive class in turn, and all remaining classes are treated as the negative class. The resulting class-specific AUC values are then aggregated to obtain an overall multi-class AUC value. For binary classification, the accuracy, precision, recall, specificity, and F1 scores are defined by True positive + True negative All samples , True positive True positive + False positive , True positive True positive + False negative , True negative True negative + False positive , and 2 × Precision × Recall Precision + Recall ; respectively. In the multi-class setting, these metrics are calculated for each class using the one-vs-rest framework and further macro- or weighted-averaged.
AQI 100 100 < AQI 150 AQI 151 AQI 100 100 < AQI 150 AQI 151 0.843 ± 0.0072 0.101 ± 0.011 0.056 ± 0.0084 0.232 ± 0.022 0.597 ± 0.022 0.171 ± 0.0270 0.169 ± 0.083 0.426 ± 0.129 0.405 ± 0.0500 ( Raw data ) AQI 100 100 < AQI 150 AQI 151 AQI 100 100 < AQI 150 AQI 151 0.848 ± 0.0108 0.097 ± 0.016 0.055 ± 0.0094 0.224 ± 0.0250 0.603 ± 0.0450 0.173 ± 0.028 0.127 ± 0.0360 0.348 ± 0.0660 0.525 ± 0.035 ( Raw data and R P S values )
Accordingly, Table 4 and Equation (15) show that augmenting raw air quality data with standardized R P S -based features improves the performance of the random forest classifier on the collected air quality dataset. The improvement is reflected simultaneously in the macro-, weighted-average classification metrics reported in Table 4, and in the class-specific recall values shown in Equation (15). The improved recall values may imply that the classification of 133( ( 0.88 0.843 ) × 22 , 534 + ( 0.603 0.597 ) × 1 , 367 + ( 0.525 0.405 ) × 106 ) instances has been corrected after the augmentation. Since the air quality was monitored daily, these 133 instances denote the measurements of air quality over 133 days.
Specifically, the augmented random forest classifier achieves modest but consistent improvements in macro-averaged classification performance, while maintaining competitive weighted-average performance. More importantly, the recall for the most severe pollution class, AQI≥151, increases from 0.405 ± 0.05 to 0.525 ± 0.035. This result indicates that incorporating R P S -based features substantially improves the model’s ability to identify observations with anomalous AQI values, which are typically rarer and more difficult to classify in a heavy-tailed dataset.
Surprisingly, the augmented features also improve the stability of predictions for the class Y = 2 . Without R P S -based feature augmentation, the standard deviation of the recall for Y = 2 (AQI ≥ 151) is 12.3% of the corresponding mean, whereas it decreases to 6.71% of the corresponding mean after augmentation. This finding suggests that the R P S -based representation provides more robust discriminatory information for identifying severe air-pollution events.
However, the improvement for Y = 2 is accompanied by a reduction in the probability of classifying these observations as the intermediate class, 100 < A Q I 150 , from 0.426 ± 0.129 to 0.348 ± 0.066. This shift is consistent with the improved diagonal value for the severe-pollution class and indicates that the augmented model better distinguishes the two higher-AQI categories. In contrast, the classification performance of the low-AQI and intermediate-AQI classes remains broadly stable, with only small changes in their diagonal entries.

4.2. Reservoir Water Quality

In Taiwan, reservoirs serve as a primary source of drinking water. Therefore, continuously monitoring water quality is essential for protecting public health. The second real dataset comprises 6,518 valid monthly water-quality records collected from 66 reservoirs between 2016 and 2025 [28]. The dataset includes conductivity, dissolved oxygen, turbidity, ammonia nitrogen (NH3−N), and Carlson’s Trophic State Index (CTSI). Dissolved oxygen is reported as a percentage, whereas conductivity, turbidity, and NH3−N are measured in μ S / cm , NTU, and mg/L, respectively. Figure 3 presents the distributions of these variables, and Table 5 summarizes their descriptive statistics.
The resulting γ H i l l values in Table 5 indicate five heavy-tailed distributions. Applying Equation (2) to anomaly detection for conductivity, dissolved oxygen, and turbidity introduces an additional methodological challenge. Specifically, anomalous observations may occur in both the upper and lower tails of the distributions; therefore, two approximately linear segments may need to be identified on the corresponding complementary cumulative probability curves. Such bidirectional anomalies are physically meaningful in water-quality monitoring, where dissolved oxygen and turbidity are commonly monitored indicators. For example, exceptionally high dissolved oxygen concentrations may be associated with water-pollution events, whereas abnormally low dissolved oxygen concentrations may indicate eutrophication. Eutrophic water may be unsuitable for drinking-water use.
Equation (16) presents the Pearson correlation of conductivity, dissolved oxygen, turbidity, and ammonia nitrogen (NH3−N). Inconsistent with the findings in Section 4.1, no pair of variables in this subsection exhibits a strong correlation.
Conduc - tivity Dissolved oxygen Turbi - dity NH 3 - N Conductivity Dissolved oxygen Turbidity NH 3 - N 1 0.034 0.132 0.169 0.034 1 0.031 0.230 0.132 0.031 1 0.083 0.169 0.230 0.083 1
Figure 4(a)-Figure 4(d) compare the anomalous ranges of current conductivity, dissolved oxygen, turbidity, and NH3−N data identified using the R P S , I Q R , Z S n , Z Q n , and the 90th, 10th, and 5th percentile rules. As in Figure 2(a)-Figure 2(d), the black points represent the complementary cumulative probability curves derived from the reservoir water-quality observations. Blue, orange, red, and green dumbbells indicate the ranges of anomalies identified by the R P S , I Q R , Z S n , Z Q n , respectively. Dashed lines denote the locations of 90th, 10th, and 5th percentiles. Gray regions represent approximately linear segments detected by calculating the slopes between successive black points.
Different from Section 4.1, conductivity, turbidity, and dissolved oxygen may exhibit extremely low values in this section. Therefore, after identifying the gray regions, dashed vertical lines are added to Figure 4(a)-Figure 4(c) to indicate the locations of the 5th or 10th percentiles. The selected percentile threshold, either 5th or 10th, is determined according to the extent of the corresponding gray region.
The need to use the 5th, 10th, and 90th percentile thresholds to verify the gray regions in Figure 4(a)-Figure 4(d) illustrates the limitations of applying percentile rules to anomaly detection in an ad hoc manner. The selection of percentile thresholds must be guided by the physical interpretation and distributional properties of each water-quality variable. In particular, the potential occurrence of unusually low or high values should be considered before defining one-sided or two-sided percentile-based anomaly criteria.
In contrast, calculating the I Q R , Z S n , and Z Q n metrics fails to identify extremely low values of conductivity and turbidity in Figure 4(a) and Figure 4(c). Moreover, the ranges of anomalies represented by the orange, red, and green dumbbells in Figure 4(a)-Figure 4(b) are narrower than the gray regions and blue dumbbells, which are created using the R P S . Only the results provided by the R P S , I Q R , Z S n , and Z Q n in Figure 4(d) may be acceptable, albeit imperfect. These results suggest that the R P S metric is more effective than the I Q R , Z S n , and Z Q n in detecting anomalies in the collected reservoir water quality data.
The Ministry of Environment in Taiwan manages reservoir water quality using the CTSI. It is calculated from Secchi-disk transparency, chlorophyll-a concentration, and total phosphorus concentration. These three variables are excluded from the training data used to train a random forest classifier because their inclusion would result in target leakage. Specifically, the CTSI is directly calculated from these measurements; therefore, using them as training data would allow the classifier to reconstruct the class label rather than identify reservoir trophic states from independent water-quality information.
According to the official standard, the class label Y is defined as follows[28,29]:
Y = 0 CTSI < 40 ( Oligotrophic reservoir water ) 1 40 CTSI 50 ( Mesotrophic reservoir water ) 2 CTSI > 50 ( Eutrophic reservoir water )
Based on Equation (17), the numbers of instances in classes CTSI < 40, 40 ≤ CTSI ≤ 50, and CTSI > 50 are 740, 3,314, and 2,464, respectively. Unlike the classification of air quality data in Section 4.1, the present classification of reservoir water quality data did not exhibit a substantial class-imbalance problem.
As in Equation (13), the R P S values of conductivity, dissolved oxygen, turbidity, and NH3−N are standardized using their respective medians and Tukey interquartile ranges as anomaly-informed features. The random forest classifier is then trained using the collected reservoir water-quality data augmented with these standardized R P S values. The data are randomly divided into training and test sets, with 75% of the observations used for model training and the remaining 25% reserved for performance evaluation. As in Section 4.1, the random forest classifier is trained independently under different random seeds. Eighteen seeds are selected from the integer range of 30 to 80.
Across 18 runs, the standard deviation of each macro-averaged and weighted-averaged classification metric is less than 5% of its corresponding mean, indicating that the estimated classification performance is sufficiently stable. As in Section 4.1, the confusion matrix for each run is row-normalized by dividing each entry in a row by the sum of that row. Consequently, each row represents the conditional distribution of predicted classes given the true class.
Equation (18) and Table 6 report the means and standard deviations of the row-normalized confusion matrices and classification metrics across the repeated 18 runs. As in Section 4.1, each classification metric is reported as the mean ± standard deviation. Multi-class AUC values are calculated using a one-versus-rest approach in which each class is treated in turn as the positive class, and all remaining classes are treated as the negative class. The resulting class-specific AUC values are then aggregated to obtain an overall multi-class AUC. Likewise, class-specific precision, recall, and F1-score are calculated under the one-versus-rest framework and subsequently summarized using macro and weighted averages.
CTSI < 40 40 CTSI 50 CTSI > 50 CTSI < 40 40 CTSI 50 CTSI > 50 0.671 ± 0.0021 0.327 ± 0.021 0.002 ± 0.0042 0.018 ± 0.0041 0.930 ± 0.011 0.052 ± 0.0100 0 0.171 ± 0.012 0.829 ± 0.0120 ( Raw data ) CTSI < 40 40 CTSI 50 CTSI > 50 CTSI < 40 40 CTSI 50 CTSI > 50 0.709 ± 0.0096 0.290 ± 0.0093 0.001 ± 0.0018 0.015 ± 0.0060 0.939 ± 0.0100 0.046 ± 0.0080 0 0.170 ± 0.0970 0.830 ± 0.0960 ( Raw data and R P S values )
Table 6 and Equation (18) illustrate a pattern that contrasts with that observed in Section 4.1. In the present classification of reservoir water quality data, the instances with CTSI > 50 , representing reservoir water that is unsuitable as a source of drinking water, are not the least frequent class. Accordingly, their recall value is not the lowest among the three classes. In contrast, the class with CTSI < 40 contained the fewest instances and exhibited the lowest recall value.
Overall, although the improvements are modest, augmenting the reservoir water-quality data with R P S -based features improved the macro-averaged classification performance and the recall for each class. The improved recall values may imply that the classification of approximately 60 instances has been corrected after the augmentation. Since the reservoir water quality is monitored monthly [28], those 60( ( 0.709 0.671 ) × 740 + ( 0.939 0.930 ) × 3 , 314 + ( 0.83 0.829 ) × 2 , 464 ) instances are the measurements of reservoir water quality over 60 months. If further improvements in classification performance are desired, combining the results in Section 4.1 and Section 4.2 suggests that tuning the maximum tree depth is preferred.

4.3. River Water Quality

On the same website [28] used to collect the reservoir water-quality data for implementing Section 4.2, river water-quality data are also available. Although the dataset includes additional variables, such as dissolved oxygen and NH3−N, this study retained the air temperature, potential of hydrogen (pH), conductivity, coliform groups, and river pollution index (RPI). A total of 19,699 records were collected for this section. Including other available variables is avoided because they either introduced target leakage or reduced classification accuracy.
The collected river water-quality data consist of monthly measurements from 296 monitoring stations across 54 rivers in Taiwan, spanning 2016 to 2025. Air temperature, conductivity, and coliform groups are measured in °C, μ S / cm , and CFU/100 mL, respectively. Figure 5 and Table 7 present the distributions and descriptive statistics of these variables.
The γ H i l l values report in Table 7 suggest that all five variables exhibit heavy-tailed characteristics. Furthermore, the skewness values indicate two distinct distributional patterns. Air temperature and pH have left-skewed distributions, whereas conductivity, coliform groups, and RPI have right-skewed distributions.
Equation (19) presents the Pearson correlation matrix for air temperature, pH, conductivity, and the coliform group. Consistent with the findings in Section 4.2, no pair of variables in this subsection exhibit a strong correlation.
Air tem - perature pH Con - ductivity Coliform groups Air temperature pH Conductivity Coliform group 1 0.1330 0.0113 0.0084 0.1330 1 0.0123 0.0574 0.0113 0.0123 1 0.0016 0.0084 0.0574 0.0016 1
Figure 6(a)-Figure 6(d) compare the anomalous ranges identified for successive observations of air temperature, pH, conductivity, and coliform groups using the R P S , I Q R , Z S n , Z Q n , 90th and 5th percentile rules. As in Figure 2(a)-Figure 2(d) and Figure 4(a)-Figure 4(d), the black points represent complementary cumulative distribution curves derived from the river water-quality observations. The blue, orange, red, and green dumbbells represent the anomalous ranges identified using the R P S , I Q R , Z S n , and Z Q n methods, respectively. The dashed lines indicate the 90th and 5th percentiles. The gray regions represent approximately linear segments identified from the slopes between successive black points. Unlike Section 4.2, the 10th percentiles are not shown in Figure 6(a)-Figure 6(d), because the resulting ranges differ substantially from those identified by the other methods.
Figure 6(a)-Figure 6(d), consistent with Figure 4(a)-Figure 4(d), illustrate a limitation of percentile-based rules. Expert judgment is required to determine whether the 90th percentile rule, the 5th percentile rule, or both rules should be applied for anomaly detection. For example, without a thorough understanding of the river system and its normal pH variability, it is difficult to select appropriate percentile thresholds for identifying anomalous pH observations. In contrast, the anomaly ranges identified by the R P S are generally close to the approximately linear regions shown in gray in Figure 6(a)-Figure 6(d), with only minor discrepancies.
In contrast, the consistency of the I Q R , Z S n , and Z Q n with the gray regions is less evident. The discrepancies between the orange, red, and green dumbbells and the gray regions are pronounced in Figure 6(a) and Figure 6(c), whereas the discrepancies in Figure 6(d) appear comparatively acceptable. Therefore, when these methods are applied to detect anomalies in new river water-quality data, their resulting anomaly ranges may require cautious interpretation.
To compare the classification performance of the collected river water-quality data with and without R P S -based data augmentation, this study formulates a binary classification problem. Based on the official RPI classification criteria, the class variable Y is defined by
Y = 0 if R P I 2 1 otherwise
Based on Equation(20), the RPI ≤ 2 and RPI > 2 classes contain 11,385 and 8,584 observations, respectively, corresponding to 57.0% and 43.0% of the collected river water-quality dataset. Thus, this dataset exhibits only a mild class-imbalance problem.
As in Section 4.1 and Section 4.2, the R P S values for air temperature, pH, conductivity, and the coliform group are standardized using their respective medians and Tukey interquartile ranges to construct anomaly-informed features. A random forest classifier is then trained using the collected river water-quality data augmented with these standardized R P S features. These data is randomly divided into training and test sets, with 75% of the observations used for training and the remaining 25% reserved for performance evaluation. As in Section 4.1, the classifier is trained independently under different random seeds. Sixteen seeds are selected from the integer range of 20 to 50.
Across the 16 runs, the standard deviation of each macro-averaged and weighted-average classification metric is less than 5 of its corresponding mean, indicating that the estimated classification performance is stable across random seeds. As in Section 4.1 and Section 4.2, the confusion matrix for each run is row-normalized by dividing each cell by the sum of the entries in its corresponding row. Consequently, each row represents the conditional distribution of predicted classes given the true class.
Equation (21) and Table 6 summarize the confusion matrices and classification metrics across the 16 repeated runs. The reported values are expressed as the mean ± standard deviation.
RPI 2 RPI > 2 RPI 2 RPI > 2 0.770 ± 0.0075 0.230 ± 0.0075 0.003 ± 0.0011 0.997 ± 0.0011 ( Raw data ) RPI 2 RPI > 2 RPI 2 RPI > 2 0.778 ± 0.0036 0.222 ± 0.0036 0.001 ± 0.0010 0.999 ± 0.0010 ( Raw data and R P S values )
Accordingly, Equation (21) and Table 8 show that augmenting the collected river-water-quality data with their R P S values improves both macro-level and class-specific classification performance. The corresponding recall improvements suggest that approximately 91( ( 0.778 0.770 ) × 11 , 385 ) additional instances in the RPI 2 class, and approximately 25( ( 0.999 0.996 ) × 8 , 584 ) additional instances in the RPI > 2 class were correctly classified after augmentation. Although the total of approximately 116 corrected instances may appear modest, each instance represents a distinct monthly measurement. Thus, the improvement corresponds to correctly classifying water-quality conditions in 116 different months over the monitoring period.
However, we may be interested in the relatively low recall value for the class RPI 2 . Inspecting the R P S values of the misclassified instances finds that some of them are anomalous, but some of them are not. To enhance the classification accuracy, the current classification criteria [28] for defining the RPI may be insufficient.

4.4. Sensitivity Study

Training a random forest classifier requires the specification of several hyperparameters. Their effects on predictive performance must therefore be examined through a sensitivity analysis. Following the last paragraph of Section 3.2, this study evaluates four key hyperparameters: the maximum tree depth (max_depth), the number of trees in the forest (n_estimators), the minimum number of samples required to split an internal node (min_samples_split), and the minimum number of samples required at a leaf node (min_samples_leaf). Like Section 4.2, 18 random seeds are selected from the integer range of 30 to 80. For each seed, the reservoir water-quality data are randomly divided into training and test sets, with 75% of these data used for training and the remaining 25% reserved for testing. Random forest classifiers are trained with and without the inclusion of standardized R P S features. Figure 7(a)-Figure 7(d) show the AUC values obtained under different hyperparameter settings. Each point represents the mean AUC across the 18 random seeds, whereas the error bars indicate the corresponding standard deviations.
Figure 7(a)-Figure 7(d) indicate that the AUC is most sensitive to the maximum tree depth (max_depth). In contrast, variations in the other hyperparameters have only modest effects on AUC performance. Furthermore, augmenting the reservoir water-quality data with R P S -based features consistently improves the AUC across the evaluated hyperparameter settings.

5. Discussion

In light of the contributions stated in Section 1 and the numerical results presented in Section 4.1 and Section 4.2, the findings of this study are discussed as follows:
  • The computation of R P S in Equation (2) involves relatively few steps: calculating Pr ( t o b s ) and identifying Pr max ( t i j ) ; i = 1 , 2 , , N ; j = 1 , 2 , , n . Therefore, its computational procedure is more straightforward than those required for calculating Rousseeuw–Croux estimators Z Q n and Z S n in Equations (11) and (12). This computational simplicity enhances the reproducibility and practical accessibility of the proposed measure.
  • Augmenting the collected sensor data with R P S -based features improves both macro-level and class-specific classification performance of a random forest classifier. Section 4.1, Section 4.2 and Section 4.3 show this improvement across three environmental sensor datasets subjected to different degrees of class imbalance. Although the improved macro-level and class-specific classification performance may be modest for both normal and anomalous sensor readings, it should be noted that these sensor readings were not collected over a short time period. Therefore, the enhanced macro-level and class-specific classification performance may reduce the risk of misinterpreting long-term environmental conditions. Surprisingly, the R P S -based features enabled the random forest classifier to identify nearly all anomalous river-pollution events in Section 4.3. These results suggest that the proposed augmentation can provide useful evidence for environmental policymaking and regional governance.
  • Calculating the R P S robustly detects anomalous environmental measurements in Section 4.1, Section 4.2 and Section 4.3. Despite the accuracy of detected anomalies, calculating the Tukey interquartile range I Q R and Rousseeuw–Croux estimators Z Q n and Z S n fails to detect extremely low conductivity, turbidity (in Section 4.2), and anomalous high air temperature (in Section 4.3). If we don’t understand the physical meaning of an environmental sensor measurement, it is difficult to determine which percentile rule should be imposed for locating the range of anomalous environmental sensor readings.
  • Section 4.3 highlights the importance of explainability in evaluating classification performance. In this section, the recall for the class RPI ≤ 2 is lower than that for the class RPI > 2, suggesting that misclassified instances are more likely to occur in the former class. We further examine these misclassified cases to improve classification accuracy. However, because the official regulation does not define the river pollution index for the dataset used in this section, it is difficult to explain the misclassifications without augmenting the feature set with R P S -based variables. Figure 2(a)–Figure 2(d), Figure 4(a)–Figure 4(d), and Figure 6(a)–Figure 6(d) show that R P S may be a more effective anomaly measure for identifying the anomalous range of a variable than I Q R , Z Q n , and Z S n , thereby providing a more interpretable basis for explaining misclassified instances.

6. Conclusions

This study applies a random forest classifier to classify air quality, reservoir water quality, and river water quality sensor data augmented with R P S -based features. The R P S serves as an anomaly measure to facilitate a random forest classifier in separating normal and anomalous data. To ensure the R P S is an effective anomaly measure, additional tests show that it is a simpler and effective anomaly measure in comparison with the I Q R , Z S n , and Z Q n . Furthermore, the R P S improves the explainability of classification results. Referring to the corresponding R P S values, we can understand why an instance is misclassified. Since we must avoid the target leakage in defining a class variable, raw data can’t provide similar explainability of misclassification results.
Conclusively, the contributions of this study are improving the weakness of a random forest classifier in classifying heavy-tailed data, demonstrating that the R P S is a simple and effective anomaly measure, and enhancing the explainability of classification results provided by a random forest classifier. Based on these contributions, this study concludes:
  • The R P S provides a computational simple anomaly measure for identifying anomalous sensor readings. Its calculation requires fewer steps than the calculations of Z Q n and Z S n . This computational simplicity enhances the reproducibility and practical accessibility of the proposed measure.
  • The R P S serves as an alternative anomaly measure for environmental monitoring data in which conventional mean- and standard-deviation-based measures may be sensitive to extreme values. Numerical results of this study show that it can identify anomalous observations in heavy-tailed environmental sensor datasets.
  • Augmenting heavy-tailed environmental datasets with R P S -based features improves the performance of a random forest classifier. The improvement was observed in both macro-level and class-specific classification results. After augmentation, the classifier made fewer classification errors for both normal and anomalous sensor readings, implying the reduce of misinterpreting long-time environmental conditions.
  • The ( R P S -based features can enhance the identification of rare but environmentally important events. The collected three datasets for implementing this study are subjected to different degrees of class imbalance. However, augmenting with R P S -based features improves the accuracy in classifying all three datasets. In particular, the augmented classifier identified nearly all anomalous river-pollution events.
  • The collected sensor data represented long-term environmental monitoring records. The proposed approach. Therefore, it may support environmental assessment, routine data screening, and evidence-based environmental policymaking.
However, the study may have several limitations. First, the collected data for implementing this study were sourced from environmental sensors. The generalizability of R P S must be further examined using data from other types of sensors, monitoring locations, and sampling frequencies. Second, this study uses a random forest classifier to generate classification results. Future studies may evaluate the usefulness of R P S -based features in other machine learning, such as the Naive-Bayes classifier. Investigating their use in real-time environmental monitoring systems is also suggested.

Author Contributions

This study is the author’s personal work.

Funding

This research received no external funding.

Data Availability Statement

’Air Quality’ at https://data.moenv.gov.tw/en/dataset/detail/AQX_P_434, ’Reservoir Water Quality’, and ’River Water Quality’ at https://wq.moenv.gov.tw/EWQP/zh/ConService/DownLoad/HistoryData.aspx (in traditional Chinese)

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

This manuscript includes the following abbreviations:
AQI Air quality index
AUC Area under the curve
CTSI Carlson’s trophic state index
IQR Interquartile range
pH Potential of hydrogen
RPI River pollution index
RPS Relative predictive surprise
SI Surprise index

References

  1. Liang, X.; Gao, Y.; Xu, S. ASE: Anomaly scoring based ensemble learning for highly imbalanced datasets. Expert Syst. Appl. 2024, 238, 122049. [CrossRef]
  2. O’Brien, R.; Ishwaran, H. A random forests quantile classifier for class imbalanced data. Pattern Recognit. 2019, 90, 232–249. [CrossRef]
  3. Bayarri, M.J.; Morales, J. Bayesian measures of surprise for outlier detection. J. Stat. Plan. Infer. 2003, 111(1), 3–22. [CrossRef]
  4. Rousseeuw, P.J.; Croux, C. Alternatives to the median absolute deviation. J. Am. Stat. Assoc. 1993, 88(424), 1273–1283. [CrossRef]
  5. Tukey, J.W.Exploratory Data Analysis, Pearson: New York, USA, 1977.
  6. Harvey, J.S.; Rosaler, J., Li, M.; Desai, D.; Mehta, D. Explainable unsupervised anomaly detection with random forest. arXiv 2025, arXiv:2504.16075.
  7. Hill, B.M. A simple general approach to inference about the tail of a distribution. Ann. Stat. 1975, 3(5), 1163–1174. [CrossRef]
  8. Bhattacharya, S.; Kallitsis, M.; Stoev, S. Data-adaptive trimming of the Hill estimator and detection of outliers in the extremes of heavy-tailed data. Electron. J. Stat. 2023, 19(1), 1872–1925.
  9. Bhattacharya, S.; Kamper, F.; Beirlant, J. Outlier detection based on extreme value theory and applications. Scand. J. Stat. 2019, 13(1), 1872–1925.
  10. Verardi, V.; Vermandele, C. Univariate and multivariate outlier identification for skewed or heavy-tailed distributions. Stata J. 2018, 18, 517–532. [CrossRef]
  11. Li, Z.; Zhao, Y.; Hu, X.; Botta, N.; Ionescu, C.; Chen, G.H. ECOD: Unsupervised outlier detection using empirical cumulative distribution functions. IEEE Trans. Knowl. Data Eng. 2023, 35(12), 12181–12193. [CrossRef]
  12. Horváth, G.; Kovács, E. Molontay, R. Nováczki, S. Copula-based anomaly scoring and localization for large-scale, high-dimensional continuous data. ACM Trans. Intell. Syst. Technol. 2019, 11, 1–26. [CrossRef]
  13. Bourigault, P.; Mandic, D. Kernel-based anomaly detection using generalized hyperbolic processes. In 2025 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP 2025), Hyderabad, India, 6-11 April 2025; pp. 1–5.
  14. Tortora, C.; Punzo, A.; Franczak, B. Handling skewness and directional tails in model-based clustering. Stat. Pap. 2025, 66, 114. [CrossRef]
  15. Zenati, H.; Romain, M.; Foo, C.-S.; Lecouat, B.; Chandrasekhar, V. Adversarially learned anomaly detection. In 2018 IEEE International Conference on Data Mining (ICDM), Singapore, Singapore, 17-20 November 2018; pp. 727–736.
  16. Dionelis, N. Tail of distribution GAN (TailGAN): Generative adversarial-network-based boundary formation. In 2020 Sensor Signal Processing for Defence Conference (SSPD), Edinburgh, UK, 15-16 September 2020; pp. 1–5.
  17. Yang, C.-A.; Peng, K.-C.; Yeh, R. Toward long-tailed online anomaly detection through class-agnostic concepts. arXiv 2025, arXiv:2507.16946.
  18. Ma, Y.; Jiao, L.; Liu, F.; Yang, S.; Liu, X.; Chen, P. Geometric prior guided feature representation learning for long-tailed classification. Int. J. Comput. Vis. 2024, 132(7), 2493–2510. [CrossRef]
  19. Song, Y.; Li, M.; Wang, B. A long-tailed image classification method based on enhanced contrastive visual language. Sensors 2023, 23(15), 6694. [CrossRef]
  20. Delaigle, A.; Hall, P. Effect of heavy tails on ultra high dimensional variable ranking methods. Stat. Sinica 2012, 22, 909–932. [CrossRef]
  21. Good, I.J. The surprise index for the multivariate normal distribution Ann. Math. Stat. 1956, 27(4), 1130–1135. [CrossRef]
  22. Weaver, W. Probability, rarity, interest and surprise, Sci. Monthly 1948, 67(6), 390–392.
  23. Kullback, S.; Leibler, R.A. On information and sufficiency, Ann. Math. Stat. 1951, 22(1), 79–86. [CrossRef]
  24. Rogers, J. How “random” is ryanair’s seating allocation?, Signif. 2017, 14(5), 12–13. [CrossRef]
  25. Breiman, L.; Friedman, J.; Stone, C.J.; Olshen, R.A. Classification and Regression Trees, Chapman and Hall/CRC: New York, USA, 1984.
  26. Cutler, A.; Cutler, D.R.; Stevens, J.R. Random forests. In Ensemble Machine Learning: Methods and Applications; Zhang, C.; Ma, Y., Eds.; Springer: New York, USA, 2012; pp. 157–175.
  27. Air quality data. 2026-01-01: https://data.moenv.gov.tw/en/dataset/detail/AQX_P_434.
  28. Reservoir water quality. 2026-03-30: https://wq.moenv.gov.tw/EWQP/en/Default.aspx (in traditional Chinese).
  29. Carlson, R.E. A trophic state index for lakes, Limnol. Oceanogr. 1977, 22(2), 361–369. [CrossRef]
Figure 1. Distributions of the collected air quality data
Figure 1. Distributions of the collected air quality data
Preprints 228058 g001
Figure 2. Comparisons of anomalies in the collected air quality data identified using the R P S , I Q R , Z S n , Z Q n , and a 90th percentile rule
Figure 2. Comparisons of anomalies in the collected air quality data identified using the R P S , I Q R , Z S n , Z Q n , and a 90th percentile rule
Preprints 228058 g002
Figure 3. Distributions of the collected reservoir water quality data
Figure 3. Distributions of the collected reservoir water quality data
Preprints 228058 g003
Figure 4. Comparisons of anomalies in the collected reservoir water quality data identified using the R P S , I Q R , Z S n , Z Q n , 90th, 10th, and 5th percentile rules)
Figure 4. Comparisons of anomalies in the collected reservoir water quality data identified using the R P S , I Q R , Z S n , Z Q n , 90th, 10th, and 5th percentile rules)
Preprints 228058 g004
Figure 5. Distributions of the collected river water quality data
Figure 5. Distributions of the collected river water quality data
Preprints 228058 g005
Figure 6. Comparisons of anomalies in the collected river water quality data identified using the R P S , I Q R , Z S n , Z Q n , 90th and 5th percentile rules
Figure 6. Comparisons of anomalies in the collected river water quality data identified using the R P S , I Q R , Z S n , Z Q n , 90th and 5th percentile rules
Preprints 228058 g006
Figure 7. Effects of four selected hyperparameters on the performance of a random forest classifier with and without augmenting R P S -based features
Figure 7. Effects of four selected hyperparameters on the performance of a random forest classifier with and without augmenting R P S -based features
Preprints 228058 g007
Table 1. Referenced rules for anomaly detection based on Equations (2) and (3) [24]
Table 1. Referenced rules for anomaly detection based on Equations (2) and (3) [24]
S I R P S Interpretation
S I < 5 R P S > 0.2 Normal
5 S I < 6.908 0.145 < R P S 0.2 Marginally anomalous
6.908 S I < 9.21 0.109 < R P S 0.145 Moderately anomalous
S I 9.21 R P S 0.109 Seriously anomalous
Table 2. Descriptive statistics of the collected air quality data
Table 2. Descriptive statistics of the collected air quality data
Statistics SO2 CO NO2 PM2.5 AQI
Mean 4.706 3.105 25.96 43.341 54.47
Median 2 3 23 38 48
Mode 2 2 17 31 44
Range [0,95] [0,23] [0,101] [0,169] [9,202]
Variance 29.699 3.637 215.83 636.474 643.176
Standard deviation 5.449 1.907 14.691 25.228 25.36
I Q R 3 3 20 37 31
Skewness 4.853 1.308 0.606 0.785 1.221
Kurtosis 41.781 3.928 -0.272 0.415 1.707
γ H i l l 11.567 25.899 5.524 48.064 14.921
Table 3. Interpretation of the trimmed Hill index γ H i l l [8]
Table 3. Interpretation of the trimmed Hill index γ H i l l [8]
γ H i l l Interpretation
≈ 0 No clear heavy-tail evidence
0.2-0.5 Heavy tail
> 0.5 Very heavy tail
1 Extreme tail heaviness
Table 4. Classification performance of air quality data before and after R P S -based augmentation
Table 4. Classification performance of air quality data before and after R P S -based augmentation
Metric Raw data Raw data and R P S values
AUC 0.957 ± 0.0016 0.960 ± 0.0018
Macro F1-score 0.442 ± 0.0082 0.452 ± 0.0055
Weighted F1-score 0.873 ± 0.0052 0.878 ± 0.0052
Accuracy 0.826 ± 0.0066 0.834 ± 0.0073
Weighted specificity 0.784 ± 0.0150 0.792 ± 0.0190
Weighted precision 0.939 ± 0.0320 0.940 ± 0.0220
Recall AQI 100 0.843 ± 0.0072 0.848 ± 0.0108
100 < AQI 150 0.597 ± 0.0220 0.603 ± 0.0450
AQI 151 0.405 ± 0.0500 0.525 ± 0.0350
Note: each classification metric is presented in its mean and standard deviation.
Table 5. Descriptive statistics of the collected reservoir water quality data
Table 5. Descriptive statistics of the collected reservoir water quality data
Statistics Conductivity Dissolved oxygen Turbidity NH3−N CTSI
Mean 388.878 8.535 6.228 0.817 50.014
Median 320 8.4 3.3 0.03 48
Mode 72 8.2 1.9 0.02 46
Range [59, 7980] [0, 18.4] [0.3, 550] [0.0086, 6.94] [25, 88]
Variance 122,053.2 2.569 224.161 0.102 105.598
STD 394.334 1.603 14.971 0.319 10.275
I Q R 186 1.5 4.4 0.03 11
Skewness 6.928 0.479 22.017 11.043 1.046
Kurtosis 95.007 4.857 691.243 155.326 1.041
γ H i l l 2.09 34.728 3.615 4.27 100.737
Table 6. Classification performance of reservoir water quality data before and after R P S -based augmentation
Table 6. Classification performance of reservoir water quality data before and after R P S -based augmentation
Metric Raw data Raw data and R P S values
AUC 0.962 ± 0.0029 0.967 ± 0.0022
Macro F1-score 0.837 ± 0.0068 0.852 ± 0.0078
Weighted F1-score 0.861 ± 0.0065 0.871 ± 0.0067
Accuracy 0.862 ± 0.0068 0.872 ± 0.0066
Weighted specificity 0.877 ± 0.0410 0.882 ± 0.0750
Weighted precision 0.868 ± 0.0710 0.878 ± 0.0075
Recall CTSI < 40 0.671 ± 0.0021 0.709 ± 0.0096
40 CTSI 50 0.930 ± 0.0110 0.939 ± 0.0100
CTSI > 50 0.829 ± 0.0120 0.830 ± 0.0960
Note: each classification metric is presented in its mean and standard deviation.
Table 7. Descriptive description of the collected river water quality data
Table 7. Descriptive description of the collected river water quality data
Statistics Air temperature pH Conductivity Coliform group RPI
Mean 26.812 7.864 2,457.846 152,431 2.799
Median 27.8 7.9 442 14,000 2.25
Mode 32 8.2 410 21,000 1
Range [2.2, 38.8] [2.64, 9.9] [44, 52,300] [10, 6.2 × 10 7 ] [1,10]
Variance 31.256 0.301 51,413,848.01 1.17 × 10 12 3.418
STD 5.591 0.549 7,170.166 1,081,075 1.849
I Q R 7.9 0.63 401 56,300 3
Skewness -0.612 -2.646 4.219 31.416 0.846
Kurtosis -0.198 17.745 18.149 1338.833 -0.144
γ H i l l 222.775 57.4 255.86 8.819 20.833
Table 8. Classification performance of river water quality data with and without R P S -based augmentation
Table 8. Classification performance of river water quality data with and without R P S -based augmentation
Metric Raw data Raw and R P S values
AUC 0.918 ± 0.0035 0.936 ± 0.0015
Macro F1-score 0.888 ± 0.0039 0.893 ± 0.0025
Weighted F1-score 0.889 ± 0.0040 0.894 ± 0.0025
Accuracy 0.891 ± 0.0037 0.896 ± 0.0026
Weighted specificity 0.875 ± 0.0400 0.881 ± 0.0025
Weighted precision 0.908 ± 0.0710 0.913 ± 0.0017
Recall RPI ≤ 2 0.770 ± 0.0075 0.778 ± 0.0036
RPI >2 0.996 ± 0.0011 0.999 ± 0.0012
Note: each classification metric is presented in its mean and standard deviation.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.