Food spoilage is a critical issue in food quality management that causes significant economic losses and health risks. Conventional approaches rely on costly hardware prototypes and limited datasets, with most studies focusing only on raw food items. Cooked or prepared foods, which are highly perishable and widely consumed, remain largely unexplored. This restricts the scalability, generalizability, and real-time usability of existing spoilage detection systems. To address this gap, this study presents an integrated machine learning framework for spoilage prediction and shelf-life estimation. A synthetic dataset of 50,000 records was generated to represent three spoilage stages: Fresh, Stale, and Spoiled. We trained and compared three supervised learning algorithms: Random Forest, Support Vector Machine (SVM), and XGBoost. Random Forest had the best accuracy. A regression model was applied to estimate the remaining shelf life in hours. The framework was deployed in a Streamlit dashboard with visual freshness indicators and QR code labeling, demonstrating a scalable and user-friendly solution that enhances food safety, reduces waste, and strengthens the transparency of the supply chain.
Introduction
Food spoilage causes 1.3 billion tons of food waste annually, posing global economic and health issues. Traditional spoilage detection methods are slow, subjective, and unscalable. There is a growing need for real-time, accurate, and consumer-friendly solutions for monitoring food freshness.
Existing Solutions and Gaps:
Electronic noses (E-noses) and IoT devices have shown potential in detecting spoilage using gas sensors. However, previous approaches suffer from:
Small or domain-specific datasets.
Lack of regression-based shelf-life prediction.
Limited consumer-facing tools (e.g., freshness timelines or QR traceability).
Focus primarily on raw foods.
Proposed Framework:
This study introduces a comprehensive machine learning system that:
Uses a synthetic dataset of 50,000 records, simulating spoilage data (e.g., NH?, H?S, CO?, VOCs, temp, humidity, pH).
Classifies food condition into Fresh, Stale, or Spoiled.
Predicts remaining shelf life using regression.
Integrates results into a user-friendly dashboard with QR code-based freshness labels.
Machine Learning Models Used:
Random Forest – Best performer with 99% accuracy, also used for regression.
Support Vector Machine (SVM) – 98% accuracy.
XGBoost – 98% accuracy.
Regression Performance:
Mean Absolute Error (MAE): 10.91 hours
R² Score: 0.727
Deployment:
Built using Streamlit dashboard for real-time input, visualization, and prediction.
Dynamic QR codes allow consumers and businesses to trace food freshness directly.
Results and Contribution:
All models performed exceptionally on synthetic data with zero misclassifications.
Random Forest was deployed due to high accuracy and speed.
The study fills a key gap by integrating ML prediction, scalability, and user traceability, offering a practical, scalable solution to reduce food waste and enhance safety.
Conclusion
This research demonstrates the feasibility of an ML-enhanced E-nose simulator with spoilage prediction and QR-based traceability. The proposed system bridges data-driven detection with consumer-facing transparency. Overall, this study designed and applied a real-time food spoilage detector using electronic nose (E-nose) simulation, sensor fusion, and machine learning. This approach goes beyond conventional manual food inspection schemes, which are commonly slow, subjective, and unsuitable for continuous surveillance. This was achieved through the integration of synthetic sensor data, state-of-the-art classification algorithms, and interactive visualizations, resulting in a practical system that can be implemented in real food settings such as restaurants and storage facilities. The system models gas sensors of ammonia, hydrogen sulphide, carbon dioxide, VOCs, and environmental conditions such as temperature, humidity, and pH, all of which are established indicators of food freshness and spoilage. A synthetic dataset of 50,000 labeled records was created and used to train three machine learning models: Random Forest, SVM, and XGBoost. The proposed method worked with 100% training and 99% testing accuracy. A major innovation is the estimation of spoilage timelines. In food labelled as fresh, the system predicts the change to stale and then spoil. This information is then formatted into a QR code which can be printed onto food packaging and then scanned by consumers who have access to a smartphone to see a real-time forecast of how long the product will last. This makes it user friendly for both the professionals and the final consumer. A Streamlit dashboard was created to enhance accessibility so that sensor values could be simulated with sliders, predictions of freshness could be visualized and classification results could be shown in real time. No dedicated hardware or technical skills are needed to use the interface, that is why it is practical in the kitchen, laboratories and production lines.
References
[1] FAO, “Global food losses and food waste – Extent, causes and prevention,” 2011.
[2] J. W. Gardner, P. Bartlett, “Electronic Noses: Principles and Applications,” Oxford University Press, 1999.
[3] R. Ravichandran, “IoT-Based Food Spoilage Detector,” IJRASET, 2022.
[4] R. Chinnasamy et al., “Food Safety Surveillance Using IoT,” Frontiers in Public Health, vol. 9, p. 816226, 2021.
[5] K. Dutta and A. Das, “Electronic Nose and Its Applications: A Survey,” IJRASET, 2022.
[6] Y. Liu et al., “Rapid Spoilage Detection of Pork Using Random Forest,” Meat Science Journal, 2020.
[7] A. Patidar, R. Khadanga, and S. P. Mohanty, “Real-Time Food Spoilage Detection Using Machine Learning and IoT,” in *2023 4th International Conference on IoT and Electronics (ICIE)*, IEEE, doi: 10.1109/ICIE57834.2023.10837714.