The research introduces an innovative approach to enhance deep learning models for air quality classification by integrating tree-structured Parzen estimators (TPE) into the hyperparameter tuning process. It applies this approach to CNN, LSTM, DNN, and DBN models and conducts extensive experiments using an air quality dataset, comparing it with grid search, random search, and genetic algorithm methods. The TPE algorithm consistently outperforms these methods, demonstrating improved classification accuracy and generalization. This approach’s potential extends to enriching water quality classification models, contributing to environmental sustainability and resource management. Bridging deep learning with TPE offers a promising solution for optimized air quality classification, supporting informed environmental preservation efforts.