Milk spoilage poses a major challenge to food safety, public health, and sustainability, often resulting in unnecessary waste across households and dairy supply chains. Traditional detection methods, such as smelling or boiling, are subjective, delay early identification, and frequently lead to misjudgment. This study proposes a machine learning (ML)–based spoilage detection framework that integrates real-time pH and carbon monoxide (CO) sensor data to classify milk as fresh, not fresh, or spoiled. multiple supervised learning models, including random forest, eXtreme gradient boosting (XGBoost), support vector machine (SVM), and decision tree, were trained and evaluated using datasets collected from raw and boiled milk samples under varying conditions. Performance was assessed using coefficient of determination (R²), mean squared error (MSE), root mean squared error (RMSE), mean absolute error (MAE), and mean absolute percentage error (MAPE) metrics to identify the most reliable model for shelf-life prediction. Experimental results show that random forest and XGBoost outperform traditional threshold-based approaches, with random forest demonstrating superior consistency and operational efficiency. The findings highlight the potential of intelligent, low-cost sensor–ML systems to significantly enhance early spoilage detection, strengthen food safety, and reduce milk wastage across domestic and industrial environments.
Copyrights © 2026