Abstract
Air quality prediction is an important environmental task that supports pollution monitoring, public health protection, and sustainable urban decision-making. This study proposes a hybrid BiGRU-MLP prediction framework enhanced using Binary Ant Colony Optimization (BACO) for feature selection and the Firefly Algorithm (FA) for hyperparameter tuning. The proposed model was evaluated using the public Air Quality dataset from Kaggle, which contains 9,357 records and multiple pollutant and meteorological attributes, including CO(GT), NOx(GT), NO2(GT), temperature, relative humidity, and sensor-based air quality indicators. The dataset was divided into 70% training, 20% validation, and 10% testing subsets to ensure reliable model development and unbiased performance evaluation. Several baseline models were implemented for comparison, including BiGRU, MLP, Neural Network (NN), LSTM, and BiLSTM. The experimental results demonstrate that the proposed BiGRU-MLP model achieved the best predictive performance, obtaining an MSE of 0.0001, RMSE of 0.0101, MAE of 0.0081, MedAE of 0.0070, MAPE of 0.0008, and R² of 99.99%. In comparison, the standalone BiGRU achieved an R² of 96.87%, while MLP, NN, LSTM, and BiLSTM achieved R² values of 95.17%, 92.71%, 90.88%, and 89.29%, respectively. These results confirm that combining BiGRU’s temporal learning capability with MLP’s nonlinear feature representation significantly improves prediction accuracy. The integration of BACO and FA further enhances the model by selecting informative features and optimizing model parameters. Therefore, the proposed framework provides an accurate and efficient solution for air quality prediction and can support intelligent environmental monitoring systems.
Keywords: Air quality prediction, Hybrid deep learning, BiGRU-MLP model, Binary ant colony optimization, Firefly algorithm, Feature selection, Hyperparameter tuning, Regression modeling, Environmental monitoring
Subject terms: Engineering, Environmental sciences, Mathematics and computing
Introduction
Air pollution is one of the most critical environmental and public health challenges facing modern cities, particularly because pollutant concentrations are influenced by complex interactions among traffic emissions, industrial activities, meteorological conditions, seasonal variation, and sensor-based environmental measurements. Accurate air quality prediction is therefore essential for early warning systems, urban planning, environmental policy, and public health protection. Recent studies have shown that machine learning and deep learning models are increasingly effective for air quality forecasting because they can learn nonlinear relationships from high-dimensional environmental and meteorological data. Comprehensive reviews have confirmed the growing role of deep learning in air quality forecasting, especially for modeling temporal dependencies and pollutant variation patterns that are difficult to capture using conventional statistical models1,2.
Traditional air quality prediction methods, including statistical and shallow machine learning models, often show limited ability to represent long-term temporal dependencies, nonlinear pollutant interactions, and hidden sequential patterns in environmental time-series data. For this reason, recurrent neural network architectures such as LSTM, GRU, BiLSTM, and BiGRU have been widely adopted for air pollution forecasting. For example, previous studies have used LSTM-based and hybrid deep learning models to improve prediction accuracy for AQI and pollutant concentration forecasting in urban environments3–5. Moreover, hybrid architectures such as CNN-LSTM and stacked CNN-BiLSTM have demonstrated that combining different neural components can improve feature extraction and temporal representation compared with standalone deep learning models6,7.
Despite these advances, air quality prediction remains a challenging research problem. Environmental datasets usually contain noisy sensor readings, missing or abnormal values, redundant variables, and strong nonlinear correlations among pollutants and meteorological attributes. In addition, many existing models depend heavily on manually selected input variables or fixed hyperparameter settings, which may reduce generalization performance. Recent works have emphasized that air quality forecasting models should not only improve prediction accuracy but also address model robustness, optimization, feature relevance, and practical reliability in real-world monitoring systems8,9. Attention-based and optimized deep learning frameworks have also been introduced to enhance AQI prediction by improving feature weighting, temporal learning, and model adaptability10,11.
The main research gap is that many existing air quality prediction studies focus either on standalone recurrent models or on hybrid models without fully integrating automated feature selection and hyperparameter optimization. Although models such as LSTM, GRU, BiLSTM, CNN-LSTM, and attention-based networks have achieved promising results, several studies still suffer from high prediction error, weak optimization of model parameters, limited feature selection, and insufficient comparison with strong baseline neural models. Furthermore, redundant or irrelevant environmental variables may increase computational complexity and reduce predictive stability. Therefore, there is a need for a hybrid optimized model that can combine temporal learning, nonlinear mapping, automatic feature selection, and metaheuristic-based hyperparameter tuning within a unified framework.
To address these limitations, this study proposes a hybrid BiGRU-MLP model for air quality prediction, supported by BACO for feature selection and the FA for hyperparameter tuning. The BiGRU component is used to learn bidirectional temporal dependencies from air quality data, while the MLP component enhances nonlinear feature representation and final prediction capability. BACO is employed to select the most informative air quality and meteorological features, reducing redundancy and improving model efficiency. FA is used to optimize model hyperparameters and improve predictive performance. The proposed model is evaluated using a public Kaggle air quality dataset containing 9,357 records, divided into 70% training, 20% validation, and 10% testing subsets. The proposed BiGRU-MLP achieved superior performance compared with BiGRU, MLP, NN, LSTM, and BiLSTM, obtaining MSE = 0.0001, RMSE = 0.0101, MAE = 0.0081, MAPE = 0.0008, MedAE = 0.0070, and R² = 99.99%.
The main contributions of this study are as follows:
A hybrid BiGRU-MLP framework is proposed for accurate air quality prediction by combining bidirectional temporal learning with nonlinear multilayer perception.
Binary Ant Colony Optimization is integrated as a feature selection mechanism to identify the most relevant environmental and pollutant-related variables.
The Firefly Algorithm is applied for hyperparameter tuning to improve model convergence, prediction accuracy, and generalization.
The proposed model is compared with five baseline models, including BiGRU, MLP, NN, LSTM, and BiLSTM, using multiple regression metrics.
The experimental results demonstrate that the proposed optimized hybrid model significantly reduces prediction error and achieves the highest R² value among all evaluated models.
The remainder of this paper is organized as follows. Section 2 reviews the related literature on air quality prediction, deep learning models, feature selection, and metaheuristic optimization. Section 3 describes the dataset, preprocessing steps, BACO-based feature selection, FA-based hyperparameter tuning, and the proposed BiGRU-MLP architecture in addition to the experimental setup, evaluation metrics, and. Section 4 discusses the findings, comparative results, model effectiveness, and implications for intelligent environmental monitoring. Finally, Sect. 5 concludes the paper and highlights future research directions.
Related works
The related work section reviews recent studies on air quality and AQI prediction using statistical models, machine learning, deep learning, hybrid neural architectures, and optimization-based approaches. Previous research has explored several techniques, including ANN, ARIMA-based hybrids, CNN-LSTM, BiLSTM, GRU-based models, Vision Transformers, graph neural networks, and attention mechanisms to improve pollutant forecasting accuracy. Many studies have also incorporated feature engineering, spatial–temporal modeling, imputation methods, transfer learning, and metaheuristic optimization to address the nonlinear and dynamic nature of air pollution data. This section highlights the main contributions, strengths, and limitations of these existing approaches and identifies the research gap that motivates the proposed BiGRU-MLP model integrated with BACO-based feature selection and Firefly Algorithm-based hyperparameter tuning.
Kalaiselvi et al.12 proposed a hybrid deep learning framework for air quality forecasting that integrates CNN and LSTM components within a Multi-Modal Attention-based Spatio-Temporal Network (MAST-Net). The study’s main contribution lies in combining multi-source remote sensing data from Sentinel-5P, MODIS, and Landsat-8 with meteorological variables and ground-based observations to predict key pollutants such as PM2.5, PM10, NO₂, and O₃. The model further improves prediction reliability through dynamic feature selection and uncertainty quantification. Experimental results across metropolitan regions showed notable improvements over conventional methods, reducing RMSE by 23–31% and achieving correlation coefficients between 0.91 and 0.94, demonstrating its effectiveness for real-time and spatially adaptive air quality monitoring systems.
Madan et al.13 developed a short-term AQI forecasting framework that combines structured feature engineering with deep learning models. The study’s key contribution is the design of enriched temporal and pollutant-based features, including lag variables, moving averages, seasonal cyclic encodings, pollutant ratios, and date-related indicators, to better capture nonlinear dependencies and interactions among air quality variables. Using OpenWeather API data, the authors evaluated CNN, LSTM, and hybrid CNN-LSTM models optimized with Adam and RMSprop. The results showed that the CNN-LSTM model achieved the best performance, with an F1-score of about 91%, outperforming standalone LSTM and CNN models.
Fusiripong et al.14 introduced AQNet, a spatiotemporal deep learning framework designed to improve urban air quality forecasting by jointly modeling spatial and temporal dependencies. The main contribution of the study is the integration of adaptive mesh-based graph construction with attention-guided temporal learning, allowing the model to represent nonuniform monitoring-station distributions and dynamic pollutant patterns more effectively. Using the Beijing Multi-Site Air Quality Dataset, AQNet applies graph convolution to capture spatial relationships among monitoring stations, gated recurrent units to learn temporal variations, and a cross-fusion layer to combine both representations. The model achieved strong predictive performance, with an MAE of 2.50, RMSE of 3.35, R² of 0.96, and classification-related metrics above 0.95.
Alsholi et al.15 proposed a robust PM2.5 forecasting framework for Kuwait by combining advanced time-series imputation, dimensionality reduction, image-based representation, and hybrid deep learning. The study’s main contribution is the integration of three missing-value imputation methods—SAITS, CSDI, and linear interpolation—with PCA to reduce the feature space from 10 variables to 4 principal components. The processed data were transformed into visual representations using line graph images for time-domain and principal-component patterns and spectrograms for frequency-domain information. These images were then used as inputs to a hybrid ViT-BiLSTM model, where the Vision Transformer extracted informative visual features, and the BiLSTM modeled sequential dependencies for PM2.5 prediction. The proposed model achieved strong forecasting accuracy, with MAE, MSE, and RMSE values of 0.0191, 0.0031, and 0.0562, respectively. Its evaluation on additional datasets from Northern Ireland and Beijing further demonstrated its generalizability and effectiveness compared with previous approaches.
Somboonmark et al.16 proposed hybrid statistical–neural forecasting models for daily AQI prediction in Hat Yai, Songkhla, Thailand, using long-term AQI records collected from 2013 to 2023. The study’s main contribution is the development and comparison of ARIMA-ANN-REG and ARIMA-ANN-QREG models against conventional ARIMA, ANN, and ARIMA-ANN approaches. By integrating linear regression and quantile regression with the ARIMA-ANN structure, the proposed models improved prediction accuracy and reduced forecasting bias. The ARIMA-ANN-QREG model achieved the best overall performance, recording the lowest MAPE, minimal fractional bias, and reduced fractional error, indicating more stable and reliable AQI forecasting. In addition to the modeling contribution, the study developed a user-friendly web application that enables users to fit these forecasting models to their own time-series data, supporting practical environmental monitoring and decision-making.
Gilik et al.17 proposed a CNN-LSTM-based air pollution prediction framework that uses real sensor data to model spatial–temporal relationships across multiple urban locations. The study’s main contribution is the development of both univariate and multivariate prediction models for different pollutants using publicly available datasets from Barcelona, Kocaeli, and İstanbul. The proposed model combines CNN layers for spatial feature extraction with LSTM layers for temporal dependency learning, while extensive hyperparameter tuning is applied to optimize model architecture and reduce prediction error. The results showed that the CNN-LSTM model improved RMSE performance over conventional one-hidden-layer LSTM models by 11–53% for particulate matter, 20–31% for ozone, 9–47% for nitrogen oxides, and 18–46% for sulfur dioxide. The study also explored transfer learning between cities, showing that transferring model weights from Kocaeli to İstanbul improved prediction accuracy due to similarities in their pollution and meteorological patterns.
Duan et al.18 developed a hybrid AQI prediction model that combines statistical modeling, deep learning, and metaheuristic optimization to improve forecasting accuracy across four cities. The study’s key contribution is the integration of ARIMA for capturing the linear component of AQI time-series data and CNN-LSTM for modeling nonlinear temporal patterns. To overcome the difficulty of manually selecting CNN-LSTM hyperparameters, the authors employed the Dung Beetle Optimizer algorithm to automatically identify the optimal model configuration. The proposed optimized ARIMA-CNN-LSTM framework was compared with nine commonly used forecasting models and demonstrated superior performance across RMSE, MAE, and R² metrics. The model achieved R² values of 0.989, 0.962, 0.953, and 0.953 for the four cities, confirming its effectiveness in handling both linear and nonlinear air quality patterns and improving multi-city AQI forecasting reliability.
Hu et al.19 proposed a CNN-LSTM-KAN hybrid framework for AQI time-series prediction across five Chinese cities representing different climatic, geographic, and topographic conditions. The main contribution of the study is the integration of CNN and LSTM layers with Kolmogorov–Arnold Networks and attention mechanisms to improve feature extraction, temporal dependency learning, and adaptive feature weighting. The authors also applied Shapiro–Wilk normality testing to justify Gaussian filtering for noise reduction and designed a multi-regional validation strategy to assess model generalizability beyond a single-city setting. Experimental results showed that the proposed model reduced RMSE by 23.6–59.6% compared with baseline LSTM models and consistently outperformed conventional CNN-LSTM architectures. The model achieved strong cross-regional performance with R² values ranging from 0.92 to 0.99, while correlation analysis identified PM2.5 and PM10 as the most influential predictors, confirming its suitability for regionally adaptive air quality early-warning systems.
Guo et al.20 developed an ANN-based forecasting model for hourly PM2.5 and PM10 concentration prediction in Chongqing City using pollutant concentrations, temporal variables, and meteorological factors as input features. The main contribution of the study is the systematic comparison of thirteen ANN training functions to identify the most effective configuration for short-term particulate matter forecasting. The results showed that the Bayesian regularization training function, trainbr, provided the best prediction performance for both PM2.5 and PM10, achieving high correlation values of 0.9783 and 0.9773, respectively, with low RMSE and MAE values. The Levenberg–Marquardt function, trainlm, also showed strong performance as the second-best training method.
Cui et al.21 proposed a multi-distance spatio-temporal graph neural network with ensemble fusion, named MD-STGNN-EN, for AQI forecasting. The study’s main contribution is the construction of multiple spatial dependency structures using six heterogeneous time-series distance metrics, enabling the model to capture more detailed relationships among monitoring stations. The framework combines graph-convolution and temporal-convolution layers to learn hidden spatio-temporal patterns, while an ensemble fusion module based on CNN and MLP layers generates the final forecasts within an end-to-end learning structure. Evaluated on AQI data from 12 monitoring stations in Xi’an, China, the model achieved strong performance with MAE of 7.0866, MAPE of 14.3329%, and RMSE of 11.6184. Additional validation on another dataset confirmed the robustness of the method, demonstrating its effectiveness in modeling complex spatial and temporal dependencies for accurate AQI prediction.
Recent studies have increasingly emphasized the importance of combining machine learning, feature selection, and metaheuristic optimization to improve the accuracy and efficiency of environmental prediction models. Sawah et al.22 proposed a hybrid optimization framework for air quality prediction that integrates Binary Particle Swarm Optimization (BPSO) with Binary Whale Optimization Algorithm (BWAO) for feature selection and hyperparameter optimization. Their study demonstrated that optimized feature selection can reduce redundant environmental variables and improve air quality prediction performance, confirming the importance of metaheuristic optimization in pollution-related prediction tasks. This work is closely related to the present study because both approaches aim to improve air quality prediction through automated feature selection and optimization; however, the present study introduces a different optimization strategy by integrating BACO for feature selection with the Firefly Algorithm for BiGRU-MLP hyperparameter tuning.
In another environmental prediction study, Sawah23 introduced a feature-selection-driven machine learning framework for sustainable rainfall classification. The study highlighted the role of selecting the most informative meteorological attributes to improve classification accuracy, reduce computational complexity, and support sustainability-oriented environmental modeling. Although the task focused on rainfall classification rather than air quality prediction, it is methodologically relevant because it confirms that feature selection is essential for improving machine-learning-based environmental prediction systems.
Elkamhawy et al.24 developed ensemble neural network models for predicting and optimizing hydraulic-structure stability considering uplift pressure and exit gradient. Their work demonstrated the effectiveness of optimized neural-network-based modeling in complex engineering and environmental systems where nonlinear relationships exist among input variables and target responses. In addition to studies have increasingly used hybrid deep learning and optimization-based models to improve forecasting accuracy for example Ahmad and Kumar25 proposed a hybrid BiGRU-1DCNN model for spatio-temporal PM2.5 forecasting across multiple monitoring stations in Delhi, showing the effectiveness of combining convolutional feature extraction with bidirectional recurrent learning. Other recent studies introduced quantum-inspired neural networks26, hybrid RNN-BiGRU models with random imputation27, and hybrid spatio-temporal PM2.5 models to improve time-series air pollution prediction and handle missing or irregular environmental data28. In addition, WaveNet-based 1DCNN-BiLSTM-XGBoost29 and decomposed-recomposed 1DCNN-BiGRU models were developed for PM2.5 prediction using US Embassy monitoring data30, demonstrating the value of integrating convolutional, recurrent, decomposition, and residual-correction strategies. In addition to Aljanabi et al.31 compared multiple machine-learning algorithms for urban air-quality forecasting and showed that benchmark ML models remain important references for evaluating new prediction frameworks. Kulkarni et al.32 introduced a decentralized air-quality forecasting framework that integrates IoT and federated learning to support privacy-preserving AQI prediction across distributed urban sensors. More recently, Narkhede et al.33 proposed an air-pollution prediction framework based on advanced preprocessing and deep ensemble learning, confirming the importance of robust data preparation and ensemble-based modeling for improving prediction reliability. This supports the motivation for using hybrid neural architectures and optimization strategies in the present study. Compared with these recent studies, the proposed framework combines BACO-based feature selection, FA-based hyperparameter tuning, BiGRU-based temporal representation, and MLP-based nonlinear prediction within a unified model for air quality prediction.
Table 1 compares recent air quality prediction studies with the proposed model in terms of prediction target, dataset, modeling approach, optimization strategy, reported results, and main contribution. As shown in Table 1, previous studies have employed a wide range of techniques, including CNN-LSTM, ViT-BiLSTM, ARIMA-ANN, AQNet, CNN-LSTM-KAN, ANN, and spatio-temporal graph neural networks, to improve AQI or pollutant forecasting. These models demonstrated strong performance by incorporating spatio-temporal learning, attention mechanisms, graph structures, feature engineering, imputation strategies, and hyperparameter optimization. However, the proposed study further advances this direction by integrating a hybrid BiGRU-MLP architecture with Binary Ant Colony Optimization for feature selection and the Firefly Algorithm for hyperparameter tuning. This combination enables the model to capture bidirectional temporal dependencies, learn nonlinear feature interactions, reduce redundant inputs, and optimize prediction performance. Consequently, the proposed model achieved the best overall results, with MSE = 0.0001, RMSE = 0.0101, MAE = 0.0081, MAPE = 0.0008, MedAE = 0.0070, and R² = 99.99%, outperforming the compared studies and confirming its effectiveness for accurate air quality prediction.
Table 1.
Comparative summary of recent air quality prediction studies and the proposed BiGRU-MLP model.
| Study | Prediction target | Dataset & study area | Main method | Optimization & feature strategy | Main reported results | Main contribution &strength |
|---|---|---|---|---|---|---|
| Kalaiselvi et al12. | PM2.5, PM10, NO₂, O₃ | Metropolitan areas using Sentinel-5P, MODIS, Landsat-8, meteorological and ground data | MAST-Net: CNN-LSTM with multi-modal attention | Dynamic feature selection and uncertainty quantification | RMSE improved by 23–31%; correlation coefficient = 0.91–0.94 | Integrated multi-source satellite, meteorological, and ground observations for spatio-temporal pollutant forecasting |
| Madan et al13. | AQI | OpenWeather API dataset | CNN, LSTM, and hybrid CNN-LSTM | Lagged features, moving averages, cyclic seasonal encoding, pollutant ratios | CNN-LSTM achieved F1-score ≈ 91%; LSTM = 87.9%; CNN = 86.7% | Demonstrated the value of engineered temporal and pollutant-ratio features for short-term AQI forecasting |
| Fusiripong et al14. | Air quality/AQI | Beijing Multi-Site Air Quality Dataset; tested across Beijing, Delhi, Bangkok, and Kathmandu | AQNet: graph convolution + GRU + attention | Adaptive mesh-based graph construction and cross-fusion layer | MAE = 2.50; RMSE = 3.35; R² = 0.96; F1-score > 0.95 | Captured spatial and temporal dependencies using adaptive graph modeling with scalable urban deployment |
| Alsholi et al15. | PM2.5 | Kuwait air quality and weather data, 2017–2024; external datasets from Northern Ireland and Beijing | ViT-BiLSTM | SAITS, CSDI, and interpolation imputation; PCA; image/spectrogram transformation | MAE = 0.0191; MSE = 0.0031; RMSE = 0.0562 | Converted time-series and frequency-domain data into visual representations for ViT-based feature extraction |
| Somboonmark et al16. | Daily AQI | Hat Yai, Songkhla, Thailand, 2013–2023 | ARIMA-ANN-REG and ARIMA-ANN-QREG | Regression and quantile regression integration | ARIMA-ANN-QREG achieved lowest MAPE = 18.647%, MFB = 0.001, MFE = 0.179 | Improved classical ARIMA-ANN forecasting by reducing bias using regression-based hybridization |
| Gilik et al17. | Multiple pollutants | Barcelona, Kocaeli, and İstanbul air pollution datasets | CNN-LSTM | Hyperparameter tuning; univariate and multivariate modeling; transfer learning | RMSE improved by 11–53% for PM, 20–31% for O₃, 9–47% for NOx, and 18–46% for SO₂ | Combined spatial-temporal learning with cross-city transfer learning for pollutant prediction |
| Duan et al18. | AQI | Real AQI data from four cities | ARIMA-CNN-LSTM | Dung Beetle Optimizer for CNN-LSTM hyperparameter tuning | R² = 0.989, 0.962, 0.953, and 0.953 across four cities | Modeled linear AQI patterns with ARIMA and nonlinear dependencies with optimized CNN-LSTM |
| Hu et al19. | AQI | Five Chinese cities across different climatic and geographic regions | CNN-LSTM-KAN with attention | Gaussian filtering; KAN-based feature weighting; multi-regional validation | RMSE reduced by 23.6–59.6%; R² = 0.92–0.99 | Integrated Kolmogorov–Arnold Networks with CNN-LSTM to improve adaptive feature learning across regions |
| Guo et al20. | Hourly PM2.5 and PM10 | Chongqing City | ANN | Comparison of 13 ANN training functions | PM2.5: R = 0.9783, RMSE = 1.2271, MAE = 0.9050; PM10: R = 0.9773, RMSE = 1.8270, MAE = 1.4341 | Identified Bayesian regularization training as the most effective ANN training function for hourly PM prediction |
| Cui et al21. | AQI | 12 monitoring stations in Xi’an, China; additional validation dataset | MD-STGNN-EN: multi-distance spatio-temporal GNN with ensemble fusion | Six heterogeneous distance metrics for adjacency matrix construction; CNN-MLP ensemble fusion | MAE = 7.0866; MAPE = 14.3329%; RMSE = 11.6184 | Captured complex spatial dependencies using multiple distance-based graph structures and ensemble forecasting |
| Proposed study | Air Quality prediction | Kaggle Air Quality dataset; 9,357 records; 70/20/10 train-validation-test split | Hybrid BiGRU-MLP | Binary Ant Colony Optimization for feature selection and Firefly Algorithm for hyperparameter tuning | MSE = 0.0001; RMSE = 0.0101; MAE = 0.0081; MedAE = 0.0070; MAPE = 0.0008; R² = 99.99% | Combines bidirectional temporal learning, nonlinear MLP representation, automated feature selection, and metaheuristic hyperparameter tuning, achieving the highest predictive accuracy among the compared studies |
Materials and methods
Dataset description
This study uses the publicly available Air Quality dataset obtained from Kaggle34. The dataset contains 9,357 observations collected from air quality monitoring sensors and includes several pollutant-related and meteorological attributes. These variables describe the concentration of harmful gases, sensor responses, temperature, relative humidity, and the final air quality target value. The dataset was adopted to evaluate the effectiveness of the proposed BiGRU-MLP model for air quality prediction because it provides continuous environmental measurements that are suitable for regression-based forecasting tasks.
The dataset includes important air pollution indicators such as CO(GT), C6H6(GT), NOx(GT), and NO2(GT), in addition to sensor-based variables such as PT08.S1(CO), PT08.S2(NMHC), PT08.S3(NOx), PT08.S4(NO2), and PT08.S5(O3). Meteorological variables, including temperature (T) and relative humidity (RH), are also included because weather conditions can strongly affect pollutant dispersion and concentration levels. The prediction target in this study is Air Quality, which represents the overall air quality indicator estimated from the available pollutant and environmental measurements.
In this study, the variable “Air Quality” was used as the target variable for the regression task. This variable represents the air quality response value available in the adopted dataset and was not used as an input feature during model training. The input variables consisted only of pollutant-related measurements, sensor-response attributes, and meteorological factors, including CO(GT), NMHC(GT), C6H6(GT), NOx(GT), NO2(GT), PT08 sensor variables, temperature, and relative humidity. To avoid possible data leakage, the target column was separated from the feature matrix before preprocessing, feature selection, scaling, sequence construction, and model training. Therefore, BACO-based feature selection was applied only to the independent input variables, and the “Air Quality” column was used only as the output label for supervised learning and final evaluation.
Table 2 presents the descriptive statistical analysis of the air quality dataset used in this study. The dataset contains 9,357 records for each pollutant, sensor, meteorological, and target variable, indicating that all attributes have the same number of observations. The variables include pollutant-related measurements such as CO(GT), NMHC(GT), C6H6(GT), NOx(GT), and NO2(GT), sensor response variables such as PT08.S1(CO), PT08.S2(NMHC), PT08.S3(NOx), PT08.S4(NO2), and PT08.S5(O3), and meteorological factors such as temperature (T) and relative humidity (RH). The table also shows that several variables have a minimum value of − 200, which indicates the presence of invalid or missing sensor readings that require preprocessing before model training. The wide differences between the mean, standard deviation, and maximum values across variables confirm the heterogeneous nature of the dataset and the need for normalization or scaling.
Table 2.
Descriptive statistical summary of the air quality dataset variables.
| CO(GT) | Count | Mean | std | min | 50% | max |
|---|---|---|---|---|---|---|
| 9357.0 | −34.207524 | 77.657170 | −200.0 | 1.5000 | 11.900 | |
| PT08.S1(CO) | 9357.0 | 1048.990061 | 329.832710 | −200.0 | 1053.0000 | 2040.000 |
| NMHC(GT) | 9357.0 | −159.090093 | 139.789093 | −200.0 | −200.0000 | 1189.000 |
| C6H6(GT) | 9357.0 | 1.865683 | 41.380206 | −200.0 | 7.9000 | 63.700 |
| PT08.S2(NMHC) | 9357.0 | 894.595276 | 342.333252 | −200.0 | 895.0000 | 2214.000 |
| NOx(GT) | 9357.0 | 168.616971 | 257.433866 | −200.0 | 141.0000 | 1479.000 |
| PT08.S3(NOx) | 9357.0 | 794.990168 | 321.993552 | −200.0 | 794.0000 | 2683.000 |
| NO2(GT) | 9357.0 | 58.148873 | 126.940455 | −200.0 | 96.0000 | 340.000 |
| PT08.S4(NO2) | 9357.0 | 1391.479641 | 467.210125 | −200.0 | 1446.0000 | 2775.000 |
| PT08.S5(O3) | 9357.0 | 975.072032 | 456.938184 | −200.0 | 942.0000 | 2523.000 |
| T | 9357.0 | 9.778305 | 43.203623 | −200.0 | 17.2000 | 44.600 |
| RH | 9357.0 | 39.485380 | 51.216145 | −200.0 | 48.6000 | 88.700 |
| Air Quality | 9357.0 | −6.837604 | 38.976670 | −200.0 | 0.9768 | 2.231 |
Figure 1 shows the correlation matrix among the pollutant variables, sensor responses, meteorological attributes, and the target air quality variable. The Air Quality target has very strong positive correlations with C6H6(GT), T, and RH, with correlation values of approximately 0.98, 0.98, and 0.94, respectively. This indicates that benzene concentration, temperature, and relative humidity are highly influential variables for predicting air quality in the dataset. It also shows strong correlations among several sensor-based variables, such as PT08.S1(CO) with PT08.S2(NMHC) and PT08.S5(O3), suggesting that some sensor readings share similar response patterns. In contrast, variables such as NMHC(GT) and NO2(GT) show weak correlations with the target, indicating that their direct linear relationship with air quality is limited.
Fig. 1.
Correlation matrix of pollutant, sensor, meteorological, and air quality variables.
Figure 2 presents the density distributions of the pollutant, sensor, meteorological, and air quality variables. Most variables exhibit non-normal and skewed distributions, indicating that the dataset contains heterogeneous patterns and nonlinear relationships. Several attributes, including CO(GT), NMHC(GT), C6H6(GT), T, RH, and Air Quality, show sharp peaks around specific value ranges, while many variables also contain extreme values near − 200, which likely represent missing or invalid sensor readings. Sensor-based variables such as PT08.S1(CO), PT08.S2(NMHC), PT08.S3(NOx), PT08.S4(NO2), and PT08.S5(O3) show wider distributions, reflecting variations in sensor responses to different pollutant concentrations. These distribution patterns confirm the importance of preprocessing steps such as handling invalid values, scaling, and feature selection before model training.
Fig. 2.
Density distribution of pollutant, sensor, meteorological, and air quality variables.
Figure 3 illustrates the boxplot distribution of the pollutant, sensor, meteorological, and air quality variables. It shows that several attributes contain a considerable number of outliers, particularly NMHC(GT), NOx(GT), PT08.S1(CO), PT08.S2(NMHC), PT08.S3(NOx), PT08.S4(NO2), and PT08.S5(O3), indicating high variability in sensor and pollutant measurements. In addition, most variables include extreme values around − 200, which likely represent missing or invalid sensor readings rather than true environmental measurements.
Fig. 3.
Boxplot analysis of pollutant, sensor, meteorological, and air quality variables showing outliers and abnormal sensor readings.
Figure 4 presents the histogram distributions of the pollutant, sensor, meteorological, and target variables in the air quality dataset. Most attributes are not normally distributed and show skewed or concentrated frequency patterns, confirming the heterogeneous nature of the dataset. Several variables, including CO(GT), C6H6(GT), T, RH, and Air Quality, contain a noticeable cluster of observations near − 200, which indicates invalid or missing sensor readings that should be treated during preprocessing. Sensor variables such as PT08.S1(CO), PT08.S2(NMHC), PT08.S3(NOx), PT08.S4(NO2), and PT08.S5(O3) show wider value ranges and more continuous distributions, reflecting different sensor responses to pollutant concentrations.
Fig. 4.
Histogram distribution of pollutant, sensor, meteorological, and air quality variables in the dataset.
Data preprocessing
Data preprocessing was performed to transform the raw air quality dataset into a clean, consistent, and model-ready format. This stage is important because the dataset contains heterogeneous pollutant measurements, sensor responses, meteorological variables, and invalid values that may negatively affect the learning process if directly used. The preprocessing pipeline included initial inspection, invalid-value handling, missing-value imputation, normalization, data splitting, leakage prevention, and final sequence preparation for the proposed BiGRU-MLP model.
In the implemented preprocessing pipeline, all invalid sensor readings with a value of − 200 were first replaced with missing values because these values indicate unavailable or erroneous sensor measurements rather than valid environmental observations. After separating the input features from the target variable, the dataset was divided into training, validation, and testing subsets using a 70:20:10 ratio. All preprocessing parameters were then fitted using the training subset only. Specifically, the median value of each input feature was computed from the training data and used to impute missing values in the training, validation, and testing subsets. No median values were estimated from the validation or testing data. This ensured that information from unseen data did not influence the imputation process.
After median imputation, min–max normalization was applied to scale the input features. The minimum and maximum values of each feature were estimated only from the training subset. The same training-derived minimum and maximum values were then applied unchanged to transform the validation and testing subsets. The target variable “Air Quality” was kept separate from the feature matrix and was not used during imputation fitting, normalization fitting, BACO-based feature selection, or model input construction. This training-only fitting strategy was adopted to prevent data leakage and to provide an unbiased evaluation of the proposed model on unseen testing data.
Initial data inspection
Let the original dataset be represented as:
![]() |
1 |
where
represents the total number of records,
is the input feature vector for the
sample, and
is the target air quality value. Each input vector contains pollutant, sensor, and meteorological variables, as follows:
![]() |
where
denotes temperature and
denotes relative humidity. The prediction target is expressed as:
![]() |
Initial descriptive analysis was conducted to examine the count, mean, standard deviation, minimum, median, and maximum values of all variables. This inspection helped identify abnormal values, scale differences, skewed distributions, and possible outliers before model development.
Invalid sensor reading detection
The dataset contains several values equal to
, which are considered invalid or unavailable sensor readings rather than true environmental measurements. Therefore, all
values were treated as missing values. This transformation can be expressed as:
![]() |
2 |
where
represents the value of the
feature in the
record. This step prevents abnormal values from distorting the statistical properties of the dataset and avoids misleading the learning algorithm during training.
Missing value imputation
After replacing invalid readings with missing values, imputation was applied to obtain a complete dataset. Because the exploratory analysis showed skewed distributions and outliers in several variables, median imputation was considered suitable. The missing values in each feature were replaced by the median of valid observations in the same feature:
![]() |
3 |
where
represents all valid values of the
feature. The median value is calculated as:
![]() |
4 |
where
is the number of valid observations after sorting the feature values. Median imputation reduces the influence of extreme values and preserves the central tendency of each variable.
Outlier analysis
Outlier analysis was conducted using boxplots and distribution plots to distinguish invalid readings from valid extreme pollutant values. The interquartile range method can be used to identify outliers as follows:
![]() |
5 |
![]() |
6 |
![]() |
7 |
A value is considered an outlier if:
![]() |
8 |
where
and
are the first and third quartiles, respectively. In this study, invalid
values were treated as missing readings, while valid extreme values were retained because they may represent real pollution events or unusual environmental conditions.
Feature scaling and normalization
The dataset variables have different scales. For example, sensor response variables may reach values above 2000, while other variables, such as CO(GT), temperature, relative humidity, and air quality, have smaller ranges. Therefore, normalization was applied to place all input features within a comparable scale. Min-max normalization can be expressed as:
![]() |
9 |
where
is the normalized value,
is the minimum value of feature
, and
is the maximum value of feature
. This transformation maps the feature values into the range
, helping the BiGRU-MLP model converge more efficiently.
Also standardization can be expressed as:
![]() |
10 |
where
and
are the mean and standard deviation of feature
, respectively. In both cases, scaling prevents high-magnitude variables from dominating the training process.
Correlation analysis
Correlation analysis was performed to examine the linear relationships among pollutant variables, sensor responses, meteorological factors, and the target air quality variable. The Pearson correlation coefficient between two variables
and
is calculated as:
![]() |
11 |
where
ranges from
to
. A value close to
indicates a strong positive relationship, a value close to
indicates a strong negative relationship, and a value near
indicates a weak linear relationship. Although correlation analysis provides useful insight into feature relevance, it only captures linear associations. Therefore, final feature selection was performed using Binary Ant Colony Optimization to identify informative variables that may also contribute through nonlinear relationships.
Data splitting
After cleaning, imputation, and normalization, the dataset was divided into training, validation, and testing subsets using a 70:20:10 ratio. This split can be represented as:
![]() |
12 |
![]() |
13 |
![]() |
14 |
![]() |
15 |
where
is used for model learning,
is used for validation and hyperparameter tuning, and
is used only for final evaluation. Given
, the approximate split is:
![]() |
16 |
This splitting strategy supports fair evaluation and provides an unbiased estimate of the generalization ability of the proposed model.
Prevention of data leakage
To avoid data leakage, imputation and scaling parameters were calculated from the training set only and then applied to the validation and testing sets. For example, if min-max normalization is used, the transformation is performed as:
![]() |
17 |
![]() |
18 |
where
and
are calculated only from the training set. This ensures that information from the validation or testing data does not influence the training process.
A further leakage-prevention step was applied by separating the target variable from the input feature matrix before any preprocessing or optimization step. The target variable “Air Quality” was not included in the BACO feature-selection search space and was not used during feature scaling or hyperparameter optimization as an input attribute. Only the training subset was used to estimate imputation and normalization parameters, while the validation and testing subsets were transformed using the parameters learned from the training data. The validation set was used only for model selection and Firefly Algorithm-based hyperparameter tuning, whereas the test set was kept completely unseen until the final evaluation stage.
Feature selection preparation
After preprocessing, the normalized feature matrix was prepared for Binary Ant Colony Optimization. Each candidate feature subset can be represented by a binary vector:
![]() |
19 |
where
is the total number of features, and:
![]() |
20 |
The selected feature subset is then represented as:
![]() |
21 |
The purpose of this step is to reduce redundant and weakly relevant variables while preserving the most informative predictors for the BiGRU-MLP model.
Sequential data preparation for BiGRU-MLP
Because the proposed model includes a BiGRU component, the preprocessed air quality data were converted into temporal input sequences before model training. The original chronological order of the observations was preserved, and the samples were not randomly shuffled before sequence construction. After invalid-value handling, median imputation, min–max normalization, and BACO-based feature selection, a sliding-window strategy was applied to the selected feature matrix.
In this study, the window length was set to 24 time steps. Therefore, each input sequence contained the previous 24 consecutive observations of the selected pollutant, sensor-response, and meteorological features. The prediction target was shifted one step ahead, meaning that the model used observations from time steps
to
to predict the air quality value at time step
. The sliding window moved with a stride of one observation; therefore, consecutive windows were overlapping. This overlap allowed the model to learn continuous temporal changes in air quality patterns while preserving the temporal structure of the dataset.
Formally, for the selected feature matrix
and target vector
, each input sequence was constructed as:
![]() |
22 |
and the corresponding target was defined as:
![]() |
23 |
where
represents the input sequence with 24 time steps and
represents the next-step air quality value. The final model input tensor had the shape:
![]() |
24 |
where
is the number of generated sequences and
is the number of BACO-selected features. Since the target was shifted one step ahead, the proposed model performs next-step air quality prediction rather than same-time target estimation.
Final preprocessed dataset
After invalid-value treatment, imputation, normalization, feature selection, and sequence generation, the final dataset was ready for training the proposed optimized BiGRU-MLP model. The final preprocessing pipeline can be summarized as:
![]() |
25 |
This preprocessing workflow ensured that the input data were clean, normalized, informative, and suitable for temporal deep learning. As a result, the proposed model was trained on high-quality data, improving prediction stability, convergence, and generalization performance.
The proposed methodology
Figure 5 illustrates the complete workflow of the proposed air quality prediction methodology. The process begins with the Kaggle air quality dataset, followed by data inspection using descriptive statistics and exploratory visualizations such as histograms, density plots, boxplots, and correlation analysis. The preprocessing stage includes detecting invalid − 200 sensor readings, treating missing values, analyzing outliers, and applying feature scaling to prepare the data for model training. The dataset is then divided into 70% training, 20% validation, and 10% testing subsets. After preprocessing, Binary Ant Colony Optimization (BACO) is applied to select the most informative features, while the Firefly Algorithm (FA) is used to tune the hyperparameters of the proposed BiGRU-MLP model. The optimized BiGRU-MLP architecture learns bidirectional temporal dependencies through the BiGRU layer and captures nonlinear feature interactions through the MLP layer before producing the final air quality prediction. Finally, the proposed model is evaluated using MSE, RMSE, MAE, MedAE, MAPE, and R² and compared with baseline models including BiGRU, MLP, NN, LSTM, and BiLSTM.
Fig. 5.

Overall workflow of the proposed BACO–FA optimized BiGRU-MLP methodology for air quality prediction.
This study proposes an optimized hybrid deep learning framework for air quality prediction using BiGRU-MLP, integrated with BACO for feature selection and the FA for hyperparameter tuning. The proposed methodology is designed to improve prediction accuracy by combining three complementary components: optimized feature subset selection, bidirectional temporal dependency learning, and nonlinear feature representation. The complete framework consists of five main stages: data preprocessing, BACO-based feature selection, FA-based hyperparameter optimization, BiGRU-MLP prediction, and final model evaluation.
Problem formulation
Let the preprocessed air quality dataset be represented as:
![]() |
26 |
where
is the total number of samples,
denotes the input feature vector of the
sample,
is the number of input variables, and
represents the target air quality value. The objective is to learn a nonlinear mapping function
that predicts the air quality value as follows:
![]() |
27 |
where
is the predicted air quality value and
represents the trainable parameters of the proposed model. The main optimization objective is to minimize the prediction error between the actual and predicted air quality values:
![]() |
28 |
where
is the loss function. In this study, the mean squared error is used as the main training loss:
![]() |
29 |
BACO-based feature selection
Air quality datasets usually contain correlated, redundant, or weakly informative variables. Therefore, feature selection is applied to reduce input dimensionality and improve prediction performance. In this study, Binary Ant Colony Optimization is used to select the optimal subset of features.
Each feature subset is represented as a binary vector:
![]() |
30 |
where:
![]() |
The selected feature subset is defined as:
![]() |
31 |
In BACO, each artificial ant constructs a candidate feature subset according to pheromone intensity and heuristic information. The probability of selecting feature
by ant
is calculated as:
![]() |
32 |
where
is the pheromone value associated with feature
,
is the heuristic value of feature
, and
and
control the influence of pheromone and heuristic information, respectively.
The fitness function evaluates each selected feature subset based on prediction error and the number of selected features:
![]() |
33 |
where
represents the validation error obtained using the selected feature subset,
is the number of selected features,
is the total number of features, and
controls the trade-off between prediction accuracy and feature reduction.
After evaluating the ants, pheromone values are updated as:
![]() |
34 |
where
is the pheromone evaporation rate and
is the pheromone deposit for feature
. The pheromone deposit is calculated as:
![]() |
35 |
where
is the number of ants, and:
![]() |
The best feature subset is selected as:
![]() |
36 |
where
represents the optimal subset of features selected by BACO.
In the practical implementation, BACO was applied only to the independent input features after separating the target variable. Each ant represented one candidate binary feature subset, where a value of 1 indicates that the corresponding feature was selected and a value of 0 indicates that it was excluded. The BACO population was initialized with 30 ants and executed for 50 iterations. The pheromone evaporation rate was set to 0.1 to balance exploration and exploitation, while the pheromone and heuristic influence parameters were set to α = 1 and β = 2, respectively. The heuristic value of each feature was defined using its absolute Pearson correlation with the target variable. The fitness function combined validation prediction error and subset size, where validation MSE was the main optimization criterion and the feature-reduction term was used as a regularization component. The trade-off weight was set to λ = 0.01 so that BACO prioritized predictive accuracy while penalizing unnecessarily large feature subsets.
During the search process, candidate feature subsets were evaluated using validation performance. The best subset was selected based on the minimum fitness value obtained during the BACO iterations. The convergence behavior showed a rapid reduction in fitness during the first 15 iterations, followed by gradual stabilization after approximately 35 iterations. This indicates that BACO reached a stable feature subset and did not continue selecting additional redundant variables. The BACO feature-selection stage required approximately 18.6 min on a workstation equipped with an Intel Core i7 processor, 16 GB RAM, and an NVIDIA GPU.
Firefly algorithm for hyperparameter optimization
After selecting the optimal features, the Firefly Algorithm is applied to tune the hyperparameters of the proposed BiGRU-MLP model. Each firefly represents a candidate hyperparameter solution:
![]() |
37 |
where
is the number of hyperparameters. These hyperparameters may include the number of BiGRU units, number of MLP neurons, learning rate, dropout rate, batch size, and number of epochs.
The brightness of each firefly is determined according to the validation performance of the model. Since the objective is to minimize validation error, the brightness can be defined as:
![]() |
38 |
where
is the validation loss obtained using hyperparameter set
.
The distance between two fireflies
and
is calculated as:
![]() |
39 |
The attractiveness between fireflies decreases with distance and is calculated as:
![]() |
40 |
where
is the attractiveness at distance zero and
is the light absorption coefficient.
If firefly
is brighter than firefly
, firefly
moves toward firefly
according to:
![]() |
41 |
where
is the randomization parameter and
is a random vector. The best hyperparameter configuration is selected as:
![]() |
42 |
where
represents the optimal hyperparameters used to train the final BiGRU-MLP model.
In the practical implementation, the Firefly Algorithm was used to optimize the main hyperparameters of the proposed BiGRU-MLP model after BACO-based feature selection. Each firefly represented one candidate hyperparameter configuration, including the number of BiGRU units, number of MLP neurons, dropout rate, learning rate, batch size, and number of training epochs. The FA population consisted of 20 fireflies and was executed for 30 iterations. The attractiveness coefficient at zero distance was set to β₀ = 1.0, the light absorption coefficient was set to γ = 1.0, and the randomization factor was set to α = 0.2. These settings were selected to provide a balance between local exploitation around promising hyperparameter configurations and global exploration of the search space.
Hyperparameter tuning was performed using the validation subset only. For each candidate firefly, the BiGRU-MLP model was trained on the training subset and evaluated on the validation subset using validation MSE as the objective function. The test subset was not used during FA optimization and was reserved exclusively for the final unbiased evaluation of the optimized model. The searched hyperparameter ranges and the final FA-selected values are reported in Table 3. The final selected configuration was then used to retrain the optimized BiGRU-MLP model on the training data, with validation monitoring, before evaluating its performance on the independent test set.
Table 3.
Firefly algorithm hyperparameter search space and final selected configuration.
| Hyperparameter | Search range | Final FA-selected value |
|---|---|---|
| Number of fireflies | 20 | 20 |
| Maximum FA iterations | 30 | 30 |
| Attractiveness coefficient, β₀ | 1.0 | 1.0 |
| Light absorption coefficient, γ | 1.0 | 1.0 |
| Randomization factor, α | 0.2 | 0.2 |
| BiGRU units | 32–128 | 96 |
| MLP dense neurons | 32–256 | 128 |
| Dropout rate | 0.10–0.50 | 0.20 |
| Learning rate | 0.0001–0.01 | 0.001 |
| Batch size | 16–128 | 32 |
| Number of epochs | 50–200 | 120 |
Proposed BiGRU-MLP prediction model
The proposed prediction model combines a Bidirectional Gated Recurrent Unit with a Multilayer Perceptron. The BiGRU component captures temporal dependencies in both forward and backward directions, while the MLP component learns nonlinear relationships from the extracted temporal features.
For a sequential input:
![]() |
43 |
the GRU uses update and reset gates to control information flow. The update gate is calculated as:
![]() |
44 |
The reset gate is calculated as:
![]() |
45 |
The candidate hidden state is computed as:
![]() |
46 |
The final hidden state is calculated as:
![]() |
47 |
where
is the input at time
,
is the previous hidden state,
is the update gate,
is the reset gate,
is the candidate hidden state,
and
are weight matrices,
represents bias terms,
is the sigmoid activation function, and
denotes element-wise multiplication.
In the BiGRU structure, the forward hidden state is computed as:
![]() |
48 |
and the backward hidden state is computed as:
![]() |
49 |
The final BiGRU representation is obtained by concatenating the forward and backward hidden states:
![]() |
50 |
The extracted BiGRU representation is then passed to the MLP component:
![]() |
51 |
![]() |
52 |
where
is the activation of the
dense layer and
is the activation function, such as ReLU:
![]() |
53 |
The final predicted air quality value is obtained from the output layer:
![]() |
54 |
where
and
are the output layer weight and bias, respectively.
Model training
The model is trained by minimizing the MSE loss between the predicted and actual air quality values:
![]() |
55 |
The trainable parameters are updated iteratively using gradient-based optimization:
![]() |
56 |
where
is the learning rate and
is the gradient of the loss function with respect to the model parameters.
The final optimized prediction function can be expressed as:
![]() |
57 |
where
is the feature matrix selected by BACO,
is the optimal hyperparameter set obtained using FA, and
represents the trained model parameters.
Evaluation metrics
The proposed model is evaluated using several regression metrics, including MSE, RMSE, MAE, MedAE, MAPE, and
. These metrics provide a comprehensive assessment of prediction error and model goodness-of-fit.
The mean squared error is calculated as:
![]() |
58 |
The root mean squared error is calculated as:
![]() |
59 |
The mean absolute error is calculated as:
![]() |
60 |
The median absolute error is calculated as:
![]() |
61 |
The mean absolute percentage error is calculated as:
![]() |
62 |
The coefficient of determination is calculated as:
![]() |
63 |
where
is the mean of the actual air quality values.
Algorithm 1 summarizes the complete computational procedure of the proposed BACO–FA optimized BiGRU-MLP framework for air quality prediction. As presented in it, the process starts with data loading, inspection, invalid-value treatment, imputation, normalization, and data splitting. Then, Binary Ant Colony Optimization is applied to identify the most informative feature subset by evaluating candidate feature combinations according to validation performance and feature reduction. After selecting the optimal features, the Firefly Algorithm is employed to tune the main BiGRU-MLP hyperparameters, including the number of recurrent units, dense neurons, dropout rate, learning rate, batch size, and training epochs. Finally, the optimized BiGRU-MLP model is trained, tested on unseen data, evaluated using MSE, RMSE, MAE, MedAE, MAPE, and R², and compared with baseline models to confirm its predictive effectiveness.
Algorithm 1.
Proposed BACO–FA optimized BiGRU-MLP for air quality prediction.
Results and discussions
The results and discussion section presents the experimental evaluation of the proposed BACO–FA optimized BiGRU-MLP model for air quality prediction. The analysis includes the performance comparison between the proposed model and baseline models, including BiGRU, MLP, NN/CNN, LSTM, and BiLSTM, using multiple regression metrics such as MSE, RMSE, MAE, MedAE, MAPE, and
. In addition, training and validation error curves are discussed to examine model convergence, stability, and generalization ability. The actual-versus-predicted plots are also analyzed to visually assess the agreement between predicted and real air quality values. Overall, this section demonstrates the effectiveness of integrating BACO-based feature selection, Firefly Algorithm-based hyperparameter tuning, and the hybrid BiGRU-MLP architecture in reducing prediction errors and improving air quality forecasting accuracy compared with the baseline models.
Table 4 presents the evaluation results of the proposed BiGRU-MLP model compared with five baseline models: BiGRU, MLP, NN, LSTM, and BiLSTM. As shown in the table, the proposed BiGRU-MLP achieved the best overall performance across all evaluation metrics, recording the lowest error values with MSE = 0.0001, RMSE = 0.0101, MAE = 0.0081, MedAE = 0.0070, and MAPE = 0.0008. It also achieved the highest coefficient of determination, with R² = 99.99%, indicating an almost perfect fit between the predicted and actual air quality values. In contrast, the standalone BiGRU and MLP models achieved lower R² values of 96.87% and 95.17%, respectively, while NN, LSTM, and BiLSTM produced higher error values and weaker predictive performance. These results confirm that combining BiGRU’s bidirectional temporal learning capability with MLP’s nonlinear representation ability, supported by BACO-based feature selection and Firefly Algorithm-based hyperparameter tuning, significantly improves air quality prediction accuracy.
Table 4.
Performance comparison of the proposed BiGRU-MLP model with classical, ensemble, hybrid, attention-based, Transformer-based, and neural baseline models.
| Model | MSE | MAPE | MedAE | MAE | RMSE | R² |
|---|---|---|---|---|---|---|
| SVR | 0.0837 | 0.0239 | 0.2054 | 0.2318 | 0.2893 | 93.86% |
| Random Forest | 0.0396 | 0.0158 | 0.1372 | 0.1559 | 0.1990 | 96.94% |
| XGBoost | 0.0284 | 0.0131 | 0.1158 | 0.1296 | 0.1685 | 97.82% |
| LightGBM | 0.0301 | 0.0138 | 0.1194 | 0.1347 | 0.1735 | 97.69% |
| NN | 0.0984 | 0.0257 | 0.2183 | 0.2522 | 0.3137 | 92.71% |
| MLP | 0.0640 | 0.0207 | 0.1764 | 0.2024 | 0.2530 | 95.17% |
| LSTM | 0.1252 | 0.0290 | 0.2472 | 0.2836 | 0.3539 | 90.88% |
| BiLSTM | 0.1490 | 0.0317 | 0.2678 | 0.3084 | 0.3860 | 89.29% |
| BiGRU | 0.0408 | 0.0165 | 0.1420 | 0.1621 | 0.2020 | 96.87% |
| CNN-LSTM | 0.0267 | 0.0125 | 0.1086 | 0.1234 | 0.1634 | 97.95% |
| Attention-LSTM | 0.0193 | 0.0107 | 0.0918 | 0.1052 | 0.1389 | 98.48% |
| Transformer time-series model | 0.0146 | 0.0096 | 0.0827 | 0.0943 | 0.1208 | 98.91% |
| Proposed BiGRU-MLP | 0.0001 | 0.0008 | 0.0070 | 0.0081 | 0.0101 | 99.99% |
To provide a stronger and fairer evaluation, the proposed BACO–FA optimized BiGRU-MLP model was compared with a broader set of baseline models. In addition to BiGRU, MLP, NN, LSTM, and BiLSTM, the comparison included classical and ensemble machine learning models, namely Random Forest, SVR, XGBoost, and LightGBM; hybrid and attention-based deep learning models, namely CNN-LSTM and attention-LSTM; and a Transformer-based time-series model.
All models were evaluated under the same experimental conditions to ensure fairness. The same cleaned dataset, 70:20:10 train–validation–test split, BACO-selected feature subset, and training-only preprocessing strategy were used for all models. Median imputation and min–max normalization parameters were fitted using only the training subset and then applied unchanged to the validation and testing subsets. Hyperparameter tuning for all tunable models was conducted using the validation subset only, while the test subset was used exclusively for final evaluation. Therefore, the reported results reflect a fair comparison under identical preprocessing, feature-selection, and data-splitting conditions.
Figure 6 presents the error-metric comparison between the proposed BiGRU-MLP model and the benchmark machine learning and deep learning models, including SVR, Random Forest, XGBoost, LightGBM, NN, MLP, LSTM, BiLSTM, BiGRU, CNN-LSTM, attention-LSTM, and the Transformer time-series model. As shown in the figure, the proposed BiGRU-MLP model achieved the lowest values across all error metrics, including MSE, MAPE, MedAE, MAE, and RMSE. The traditional recurrent models, especially LSTM and BiLSTM, produced comparatively higher error values, while ensemble and hybrid models such as XGBoost, LightGBM, CNN-LSTM, attention-LSTM, and the Transformer time-series model showed stronger performance. However, the proposed BiGRU-MLP model consistently outperformed all benchmark models, confirming the effectiveness of combining BACO-based feature selection, Firefly Algorithm-based hyperparameter tuning, bidirectional temporal learning, and nonlinear MLP representation for air quality prediction.
Fig. 6.
Line-plot comparison of error metrics for the proposed BiGRU-MLP model and benchmark machine learning and deep learning models using MSE, MAPE, MedAE, MAE, and RMSE.
Figure 7 presents the correlation matrix of the selected features after applying the feature selection process. It shows that the retained variables include important sensor and meteorological attributes, such as PT08.S1(CO), NMHC(GT), PT08.S2(NMHC), PT08.S3(NOx), NO2(GT), PT08.S5(O3), and RH. Strong positive correlations are observed between PT08.S1(CO) and PT08.S2(NMHC), with a correlation value of 0.93, and between PT08.S2(NMHC) and PT08.S5(O3), with a correlation value of 0.91, indicating that these sensor responses share similar pollution-related patterns. In addition, RH shows moderate to strong correlations with PT08.S1(CO), PT08.S2(NMHC), and PT08.S3(NOx), suggesting that relative humidity may influence pollutant behavior and sensor responses. Some weak or negative relationships, such as the correlation between PT08.S3(NOx) and NO2(GT), indicate that the selected features provide diverse and complementary information.
Fig. 7.
Correlation matrix of the selected features used by the proposed BiGRU-MLP model.
The selected subset in Table 5 shows that BACO retained a compact group of sensor-response, pollutant-related, and meteorological variables. These features provide complementary information for predicting the target air quality value while reducing redundant or weakly informative inputs. The selected variables were subsequently used as the input features for the optimized BiGRU-MLP model.
Table 5.
Features selected by BACO for the proposed BiGRU-MLP model.
| No. | Selected feature | Feature type |
|---|---|---|
| 1 | PT08.S1(CO) | Sensor response |
| 2 | NMHC(GT) | Pollutant measurement |
| 3 | PT08.S2(NMHC) | Sensor response |
| 4 | PT08.S3(NOx) | Sensor response |
| 5 | NO2(GT) | Pollutant measurement |
| 6 | PT08.S5(O3) | Sensor response |
| 7 | RH | Meteorological variable |
The comparison in Table 6 confirms the positive effect of BACO on the proposed model. By reducing the input space from 12 original variables to 7 informative features, BACO reduced redundant information and improved model compactness. The BACO-selected subset also helped the BiGRU-MLP model focus on the most relevant pollutant, sensor-response, and meteorological variables, which contributed to lower prediction error and stronger generalization performance. Compared with the model trained using all original features, the BACO-enhanced model reduced RMSE from 0.0203 to 0.0101 and improved R² from 99.96% to 99.99%.
Table 6.
Performance comparison of the proposed BiGRU-MLP model before and after BACO feature selection.
| Model configuration | Number of input features | MSE | RMSE | MAE | MedAE | MAPE | R² |
|---|---|---|---|---|---|---|---|
| BiGRU-MLP without BACO | 12 | 0.0004 | 0.0203 | 0.0167 | 0.0142 | 0.0016 | 99.96% |
| BiGRU-MLP with BACO | 7 | 0.0001 | 0.0101 | 0.0081 | 0.0070 | 0.0008 | 99.99% |
Figure 8 presents the training and validation mean absolute error (MAE) curves for the proposed BiGRU-MLP model and the baseline models, including BiGRU, MLP, CNN, LSTM, and BiLSTM. All models exhibit a sharp reduction in MAE during the first few epochs, indicating rapid learning and effective convergence. After the initial training phase, the curves become stable, suggesting that the models reached steady performance without strong fluctuations. The proposed BiGRU-MLP model shows the lowest and most stable training and validation MAE curves compared with the other models, confirming its stronger ability to learn temporal and nonlinear patterns from the selected air quality features. The close alignment between training and validation curves also indicates that the model generalizes well and does not show clear signs of overfitting.
Fig. 8.
Training and validation MAE curves of the proposed BiGRU-MLP model and baseline deep learning models.
The curves for training and validation MSE of the proposed BiGRU-MLP model, as well as the baseline models, BiGRU, MLP, CNN, LSTM, and BiLSTM, are depicted in Fig. 9. All models converge to their optimal MSE very quickly in their first several epochs. After that, their MSE remains almost constant, which implies that they have converged successfully without any oscillation. The BiGRU-MLP model exhibits the best learning pattern in terms of the fastest decrease in MSE and its extremely low value during the rest of epochs. In addition, the proximity of the training and validation curves shows that the model performs generalization well without overfitting. Compared to the individual recurrent and neural models, the BiGRU-MLP curve proves that the combination of bidirectional temporal learning and nonlinear MLP is quite efficient, just like the evaluation results that show the lowest MSE and highest R2.
Fig. 9.
Training and validation MSE curves of the proposed BiGRU-MLP model and baseline deep learning models.
Figure 10 presents the actual versus predicted air quality values for the proposed BiGRU-MLP model and the baseline models. The proposed BiGRU-MLP shows the strongest prediction performance, where the predicted points closely overlap with the fitted line and achieve an
value of 99.99%, indicating an almost perfect agreement between actual and predicted values. In comparison, the baseline models show wider dispersion around the fitted line, with
values of 96.87% for BiGRU, 95.17% for MLP, 92.71% for CNN, 90.88% for LSTM, and 89.29% for BiLSTM. This confirms that the proposed model reduces prediction deviation more effectively than the standalone neural and recurrent models. Overall, the figure visually supports the quantitative evaluation results and demonstrates the superior predictive capability of the optimized BiGRU-MLP model for air quality prediction.
Fig. 10.
Actual versus predicted air quality regression plots for the proposed BiGRU-MLP model and baseline deep learning models.
Conclusion and future work
This study proposed an optimized hybrid BiGRU-MLP model for air quality prediction using Binary Ant Colony Optimization (BACO) for feature selection and the Firefly Algorithm (FA) for hyperparameter tuning. The proposed framework was designed to improve prediction accuracy by combining bidirectional temporal learning, nonlinear feature representation, automated selection of informative variables, and metaheuristic-based parameter optimization. The air quality dataset was first preprocessed by handling invalid sensor readings, treating missing values, analyzing outliers, normalizing features, and dividing the data into training, validation, and testing subsets using a 70:20:10 split. BACO was then applied to select the most relevant pollutant, sensor, and meteorological features, while FA was used to optimize the main hyperparameters of the BiGRU-MLP model.
The experimental results confirmed the superiority of the proposed model compared with several baseline models, including BiGRU, MLP, NN, LSTM, and BiLSTM. The proposed BiGRU-MLP achieved the best overall performance, with MSE = 0.0001, RMSE = 0.0101, MAE = 0.0081, MedAE = 0.0070, MAPE = 0.0008, and R² = 99.99%. These results indicate that the hybrid architecture can effectively capture complex temporal and nonlinear relationships in air quality data. The training and validation curves also demonstrated stable convergence and good generalization behavior, while the actual-versus-predicted analysis showed a very strong agreement between predicted and real air quality values. Overall, the findings show that integrating BACO-based feature selection and FA-based hyperparameter tuning with the BiGRU-MLP architecture provides an effective and accurate solution for air quality prediction.
Future research may also explore advanced explainable artificial intelligence techniques, such as SHAP or attention-based interpretation, to identify the most influential pollutants and environmental factors affecting air quality prediction. Moreover, uncertainty quantification can be incorporated to improve the reliability of predictions in real-world monitoring systems. Another promising direction is to develop a real-time deployment framework that integrates the proposed model with IoT-based air quality sensors and cloud computing platforms. Finally, future studies can compare BACO and FA with other optimization algorithms, such as Particle Swarm Optimization, Grey Wolf Optimizer, Bayesian Optimization, and Optuna, to further examine the computational efficiency, convergence behavior, and predictive stability of the proposed air quality prediction framework.
Acknowledgements
The authors acknowledge Princess Nourah bint Abdulrahman University Researchers Supporting Project number (PNURSP2026R442), Princess Nourah bint Abdulrahman University, Riyadh, Saudi Arabia.
Author contributions
Yasser Fouad provided resources, curated the data, contributed to visualization, and participated in review and editing. Hazem M. El-Bakry conceived and designed the study; developed the methodology; contributed to review and editing; and prepared the visualizations. Sarah M. Alhammad designed the study; developed the methodology; contributed to review and editing; and prepared the visualizations. Amira A. Mahmoud conceived and designed the study; contributed to review and editing. Ahmed M. Elshewey conceived and designed the study; contributed to the methodology; implemented the software; performed validation and formal analysis; conducted the investigation; curated the data; wrote the original draft; conducted the investigation; reviewed and edited the manuscript. Ahmed M. Osman contributed to the methodology, performed validation and formal analysis, and participated in review and editing. All authors read and approved the final manuscript.
Funding
Princess Nourah bint Abdulrahman University Researchers Supporting Project Number (PNURSP2026R442), Princess Nourah bint Abdulrahman University, Riyadh, Saudi Arabia.
Data availability
The data that support the findings of this study are available at https://www.kaggle.com/datasets/tawfikelmetwally/air-quality-dataset.
Declarations
Competing interests
The authors declare no competing interests.
Footnotes
Publisher’s note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
References
- 1.Zhang, Z., Zhang, S., Chen, C. & Yuan, J. A systematic survey of air quality prediction based on deep learning. Alexandria Eng. J.93, 128–141 (2024). [Google Scholar]
- 2.Méndez, M., Merayo, M. G. & Núñez, M. Machine learning algorithms to forecast air quality: A survey. Artificial Intelligence Review56(9), 10031–10066 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 3.Tran, H. D., Huang, H. Y., Yu, J. Y. & Wang, S. H. Forecasting hourly PM2.5 concentration with an optimized LSTM model. Atmos. Environ.315, 120161 (2023). [Google Scholar]
- 4.Janarthanan, R., Partheeban, P. & Somasundaram, K. Navin Elamparithi, P. A deep learning approach for prediction of air quality index in a metropolitan city. Sustain. Cities Soc.67, 102720 (2021). [Google Scholar]
- 5.Mao, W., Wang, W., Jiao, L., Zhao, S. & Liu, A. Modeling air quality prediction using a deep learning approach: Method optimization and evaluation. Sustain. Cities Soc.65, 102567 (2021). [Google Scholar]
- 6.Zhang, J. & Li, S. Air quality index forecast in Beijing based on CNN-LSTM multi-model. Chemosphere308, 136180 (2022). [DOI] [PubMed] [Google Scholar]
- 7.Das, B., Dursun, Ö. O. & Toraman, S. Prediction of air pollutants for air quality using deep learning methods in a metropolitan city. Urban Clim.46, 101291 (2022). [Google Scholar]
- 8.Karmoude, M. et al. Machine learning for air quality prediction and data analysis: Review on recent advancements, challenges, and outlooks. Sci. Total Environ.1002, 180593 (2025). [DOI] [PubMed] [Google Scholar]
- 9.Tao, C., Wang, Y., Wang, Y., Zheng, Z. & Zhang, H. Deep learning for air pollutant forecasting: opportunities, challenges, and future directions. Front. Environ. Sci. Eng.19, 172 (2025). [Google Scholar]
- 10.Wu, X., Gu, X., See, K. W. & ADNNet Attention-based deep neural network for Air Quality Index prediction. Expert Syst. Appl.258, 125128 (2024). [Google Scholar]
- 11.Ma, G., Xu, K., Zhang, Y., Zhang, L. & Chen, Z. A novel deep learning model for air quality index prediction integrating time series decomposition and intelligent optimization. Results Eng.27, 106078 (2025). [Google Scholar]
- 12.Kalaiselvi, S., Anitha, V., Manimaran, V., Samraj, T. & 3∗, L. Air quality prediction using multi-source remote sensing data integration with hybrid deep learning framework. Scientific Reports 2025 16:1 16, 2688- (2025). [DOI] [PMC free article] [PubMed]
- 13.Madan, T. et al. Hybrid deep learning model for air quality prediction and its impact on healthcare. Scientific Reports 2026 16:1 16, 6036- (2026). [DOI] [PMC free article] [PubMed]
- 14.Fusiripong, P. & Surbakti, H. Aqnet adaptive mesh attention framework for spatiotemporal air quality prediction in diverse urban environments. Int. J. Data Sci. Anal.22, 34 (2026). [Google Scholar]
- 15.Alsholi, G., Ahmad, I. & Abed, S. Air particulate matter (PM2.5) concentration prediction in Kuwait using vision transformer. J. Big Data. 13, 38 (2026). [Google Scholar]
- 16.Somboonmark, W. & Chumnaul, J. Enhancing AQI forecasting accuracy: integrating ARIMA, ANN, and regression techniques with the development of HM4AQI web application. J. Big Data. 13, 65 (2026). [Google Scholar]
- 17.Gilik, A., Ogrenci, A. S. & Ozmen, A. Air quality prediction using CNN+LSTM-based hybrid deep learning architecture. Environ. Sci. Pollut. Res.29, 11920–11938 (2022). [DOI] [PubMed] [Google Scholar]
- 18.Duan, J., Gong, Y., Luo, J. & Zhao, Z. Air-quality prediction based on the ARIMA-CNN-LSTM combination model optimized by dung beetle optimizer. Sci. Rep.13 (1), 13–12127 (2023). (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- 19.Hu, Y., Ding, Y. & Jiang, W. Geographically Aware Air Quality Prediction Through CNN-LSTM-KAN Hybrid Modeling with Climatic and Topographic Differentiation. Atmosphere 2025, Vol.16, 16, (2025).
- 20.Guo, Q., He, Z. & Wang, Z. Prediction of Hourly PM2.5 and PM10 Concentrations in Chongqing City in China Based on Artificial Neural Network. Aerosol Air Qual. Res.23, 220448 (2023). [Google Scholar]
- 21.Cui, S., Yang, Y., Liu, G. & Shen, L. Air quality index prediction based on spatio-temporal graph neural networks: An empirical study of Xi’an, China. Engineering Applications of Artificial Intelligence166, 113547 (2026). [Google Scholar]
- 22.Sawah, M. S., Elmannai, H., El-Bary, A. A., Lotfy, K. & Sheta, O. E. Improving air quality prediction using hybrid BPSO with BWAO for feature selection and hyperparameters optimization. Scientific Reports 2025 15:1 15, 13176- (2025). [DOI] [PMC free article] [PubMed]
- 23.Sawah, M. S. A novel feature selection-driven framework for sustainable and efficient rainfall classification using machine learning models. Unconventional Resources9, 100286 (2026). [Google Scholar]
- 24.Elkamhawy, E., Sawah, M. S., Tawfik, M. & Ismail, A. S. Ensemble neural network models for stability prediction and optimization of hydraulic structures considering uplift pressure and exit gradient. Scientific Reports 2026 16:1 16, 1307- (2026). [DOI] [PMC free article] [PubMed]
- 25.Ahmad, N. & Kumar, V. Spatio-temporal forecasting using a hybrid BiGRU-1DCNN model for PM $$_{2.5}$$ concentrations in Delhi, India (2018–2023) across multiple monitoring stations. Water, Air, & Soil Pollution 2025 236:7236, 459 (2025). [Google Scholar]
- 26.Ahmad, N. & Jas, S. Quantum-inspired neural networks for time-series air pollution prediction and control of the most polluted region in the world. Quantum Mach. Intell.7 (1), 7–9 (2025). (2025). [Google Scholar]
- 27.Ahmad, N. & Kumar, V. Enhancing PM $$_{2.5}$$ air pollution forecasting with novel random imputation based on hybrid RNN-Bidirectional GRU (nRI RNN-BiGRU) model. SN Computer Science 2025 6:66, 637 (2025). [Google Scholar]
- 28.Ahmad, N. & Kumar, V. A hybrid time series model for the spatio-temporal analysis of air pollution prediction based on PM2.5. Communications in Computer and Information Science2093 CCIS, 62–81 (2024). [Google Scholar]
- 29.Ahmad, N. & Kumar, V. Effective air pollution prediction using wavenet deep learning with Xgboost (1DCNN-BiLSTM-XgRC) for urban US embassies. Theoret. Appl. Climatol.156(9), 464 (2025). [Google Scholar]
- 30.Ahmad, N. & Kumar, V. Enhancing the PM2.5 Predictions of US embassies using novel hybrid 1DCNN-BiGRU and decomposed-recomposed 1DCNN-BiGRU-DR models. Aerosol. Sci. Eng.10.1007/S41810-025-00372-7 (2026). [Google Scholar]
- 31.Aljanabi, M., Shkoukani, M. & Hijjawi, M. Comparison of multiple machine learning algorithms for urban air quality forecasting. Periodicals of Engineering and Natural Sciences (PEN)9, 1013–1028 (2021). [Google Scholar]
- 32.Kulkarni, V. et al. Air Quality Decentralized Forecasting: Integrating IoT and Federated Learning for Enhanced Urban Environmental Monitoring. Engineering, Technology & Applied Science Research14, 16077–16082 (2024). [Google Scholar]
- 33.Narkhede, G., Poonawala, M., Sonawane, A., Hiwale, A. & Singh, A. R. Air pollution prediction with advanced preprocessing and deep ensemble learning. Atmospheric Pollution Research16, 102610 (2025). [Google Scholar]
- 34.air quality dataset. https://www.kaggle.com/datasets/tawfikelmetwally/air-quality-dataset
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
Data Availability Statement
The data that support the findings of this study are available at https://www.kaggle.com/datasets/tawfikelmetwally/air-quality-dataset.













































































