# Predicting Tomato Spoilage Risk Using Logistic Regression and SHAP
A machine learning project that predicts whether a batch of tomatoes will spoil based on its storage conditions, and explains the model's reasoning using SHAP (SHapley Additive exPlanations).
**Author:** Praise Adegoju
**Country:** Nigeria
**Course:** Kujenga Programme — Final Project
---
## Project Question
Can I predict whether a batch of tomatoes will spoil based on the storage conditions it is exposed to (temperature, humidity, light, and CO2 levels), and which of these factors most strongly drive spoilage?
## Why This Matters
Nigeria loses an estimated 45 to 50 percent of every tomato harvest to post-harvest rot. This drives food insecurity, causes price spikes of up to 100 percent during lean seasons, releases methane at scale, and devastates smallholder farmer incomes.
If the conditions that drive spoilage can be predicted and explained, interventions become possible: storage conditions can be optimised before significant loss occurs, the most dangerous environmental factors can be identified and controlled first, and waste can be reduced while farmer income is preserved.
## Approach
1. **Cleaned and explored** a dataset of 3,741 tomato batches with environmental sensor readings
2. **Trained a Logistic Regression classifier** to predict spoilage (Good vs Bad) from 4 storage conditions
3. **Evaluated the model** using accuracy, precision, recall, F1-score, and a confusion matrix
4. **Explained the model with SHAP** at both global level (which features matter overall) and local level (why the model predicted a specific batch as Bad)
## Results
- **Test Accuracy: 94.15%**
- **Recall on Bad batches: 100%** (no spoilt batches were missed)
- **Top driver of spoilage:** Light intensity
- **Identified weakness:** the model can be misled by extreme single-feature values (revealed via SHAP false alarm analysis)
## Dataset
The dataset comes from the **Multi-Parameter Fruit Spoilage Predic …