python -m venv venv
venv\Scripts\activate
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python smoke_test.py
This project implements a basic data pipeline for a polyhouse (controlled agricultural environment) sensor system. The goal is to support yield forecasting by processing environmental sensor data such as temperature, humidity, and COβ levels.
The pipeline covers:
- Data ingestion from raw sensor files
- Data validation and cleaning
- Handling missing values and duplicates
- Exporting cleaned data for analysis and modeling
zelbytes-yield-forecasting/ β βββ data/ β βββ raw/ # Original sensor data (CSV/XLSX) β βββ interim/ # Loaded dataset snapshot β βββ processed/ # Cleaned dataset β βββ src/ β βββ ingest.py # Data ingestion script β βββ clean.py # Data cleaning pipeline β βββ cleaning_log.md # Data cleaning audit log βββ data_dictionary.md # Column definitions & units βββ .gitignore # Ignored files and folders βββ README.md
The dataset simulates real-time polyhouse sensor readings.
| Column | Description | Unit |
|---|---|---|
| timestamp | Time of sensor reading | datetime |
| temperature_c | Air temperature inside polyhouse | Β°C |
| humidity_pct | Relative humidity | % |
| co2_ppm | COβ concentration | ppm |
| yield_kg | Crop yield (target variable) | kg |
π See data_dictionary.md for full details.
- Reads raw sensor data (
CSV/XLSX) - Parses timestamp column
- Validates schema and data types
- Saves snapshot to:
- Handles missing values (sensor columns only)
- Applies forward-fill for short gaps
- Removes duplicate timestamps
- Filters invalid sensor readings:
- humidity: 50β100%
- temperature: 10β35Β°C
- COβ: 400β2000 ppm
- Drops rows with missing target (
yield_kg) - Saves cleaned dataset:
- No imputation for target (
yield_kg) to avoid data leakage - Median imputation used for sensor values
- Forward fill used for short sensor outages
- Duplicate timestamps removed to avoid bias in time-series analysis
Install required packages:
pip install pandas pyarrow openpyxl
## Task 4: Train/Test Split & Data Leakage Prevention
### Chronological Split
The dataset was sorted by timestamp and split chronologically using an 80/20 ratio. The first 80% of records were used for training, while the remaining 20% were reserved for testing. This ensures that the model is trained on past observations and evaluated on future observations.
### Data Leakage Prevention
To prevent data leakage, the MinMaxScaler was fitted only on the training dataset using `fit_transform()`. The same scaler was then applied to the test dataset using `transform()`. This ensures that no statistical information from the test set influences the training process.
### Train and Test Sizes
Training set size: 80% of total records
Test set size: 20% of total records
The exact row counts were logged during execution.
### Feature Integrity
All features (`temperature_c`, `humidity_pct`, and `co2_ppm`) are derived from measurements recorded at the same timestamp. No feature uses information from future timestamps, ensuring realistic forecasting conditions.
### Saved Artifacts
The following artifacts were generated and saved for future modeling tasks:
* `data/processed/train.parquet`
* `data/processed/test.parquet`
* `models/minmax_scaler_train.joblib`
These files will be used in subsequent regression and forecasting experiments.
task 7
# GridSearchCV Tuning Summary
## Objective
The objective was to improve Random Forest performance by tuning key hyperparameters using GridSearchCV.
## Parameter Grid
* n_estimators: [50, 100, 200]
* Controls the number of trees in the forest.
* More trees can improve performance but increase runtime.
* max_depth: [None, 8, 16]
* Controls tree depth.
* Shallower trees may reduce overfitting.
* min_samples_leaf: [1, 3, 5]
* Controls the minimum number of samples required in a leaf node.
* Larger values can improve generalization.
## Methodology
GridSearchCV was performed using TimeSeriesSplit with 3 folds. Only the training dataset was used during tuning. Mean Absolute Error (MAE) was used as the scoring metric.
## Results
* Best parameters: See `models/rf_best_params.json`
* Best model: `models/random_forest_tuned.joblib`
* CV results: `reports/gridsearch_results.csv`
The tuned model was evaluated once on the held-out test set after tuning.
## Runtime
The total GridSearch runtime was recorded in `reports/gridsearch_metrics.json`.
## Conclusion
GridSearchCV identified the best combination of hyperparameters for the Random Forest model while avoiding data leakage. The tuned model will be used for final model comparison and selection.
phase 2 (day 15 last)
π± Yield Forecasting using Machine Learning
This project predicts crop yield based on environmental parameters such as temperature, humidity, and CO2 levels using a trained Machine Learning model.
π Project Structure
zelbytes-yield-forecasting/
β
βββ data/
βββ models/
β βββ minmax_scaler_train.joblib
β βββ random_forest_tuned.joblib
β βββ feature_cols.json
β
βββ src/
β βββ predict.py
β
βββ requirements.txt
βββ README.md
βοΈ Requirements
Install dependencies using:
pip install -r requirements.txt
π How to Run Prediction
Run the script using:
python src/predict.py
π Example Output
Input: T=25, H=90, CO2=1000 β Predicted Yield: 1.16 kg
π§ Model Details
Algorithm: Random Forest Regressor
Scaling: MinMaxScaler
Input Features:
temperature
humidity
CO2
Target: yield_kg
π Workflow
Data collection and cleaning
Feature scaling using MinMaxScaler
Model training using Random Forest
Model saving using joblib
Inference using saved scaler + model
π Python Usage Example
from src.predict import make_prediction
result = make_prediction(25, 90, 1000)
print(result)
π¦ Requirements
pandas
numpy
scikit-learn
joblib
-------------------
phase 3
-------------------
# π Mushroom Yield Forecasting using Machine Learning
A machine learning-powered web application that predicts **daily mushroom yield (kg/day)** using polyhouse environmental sensor readings. The application is built with **Python**, **Scikit-learn**, and **Streamlit**, providing an interactive interface for farm managers to estimate yield under different environmental conditions.
## π Live Demo
**Streamlit App:**
https://zelbytes-yield-forecasting-n7jju6xpvrhfz7mr7dpig8.streamlit.app/
---
## π Project Overview
This project predicts mushroom yield based on three environmental parameters collected from a polyhouse:
* π‘ Temperature (Β°C)
* π§ Humidity (%)
* π¬ COβ Concentration (ppm)
Users can adjust these parameters through an interactive Streamlit interface and instantly receive the predicted daily mushroom yield.
---
## β¨ Features
* Interactive Streamlit web application
* Daily mushroom yield prediction
* Humidity sensitivity ("What-if") analysis
* Model metadata display
* Input validation with user-friendly warnings
* Responsive interface suitable for desktop and mobile
* Cached model loading for faster predictions
---
## π Tech Stack
* Python
* Streamlit
* Scikit-learn
* Pandas
* NumPy
* Joblib
* Matplotlib (if used)
---
## π Repository Structure
```text
zelbytes-yield-forecasting/
β
βββ app.py # Streamlit application (main entry point)
βββ requirements.txt # Python dependencies
βββ runtime.txt # Python version (optional)
βββ README.md
β
βββ models/
β βββ random_forest_tuned.joblib
β βββ minmax_scaler_train.joblib
β βββ feature_columns.json
β
βββ src/
β βββ __init__.py
β βββ predict.py
β
βββ tests/
β βββ test_predict.py
β
βββ reports/
β βββ methodology.md
β βββ task8_streamlit_app.png
β βββ test_scenarios.md
β
βββ data/app.py
Clone the repository:
git clone <your-github-repository-url>Move into the project directory:
cd zelbytes-yield-forecastingCreate and activate a virtual environment:
python -m venv .venv
.venv\Scripts\activateInstall dependencies:
pip install -r requirements.txtRun the application:
streamlit run app.pyThe application will be available at:
http://localhost:8501
| Feature | Unit |
|---|---|
| Temperature | Β°C |
| Humidity | % |
| COβ | ppm |
- Predicted Mushroom Yield (kg/day)
The project includes unit tests using pytest.
Run the tests:
pytest tests/| Temperature | Humidity | COβ | Expected Behaviour |
|---|---|---|---|
| 22Β°C | 88% | 900 ppm | Normal prediction |
| 22Β°C | 70% | 900 ppm | Lower yield expected |
| 32Β°C | 88% | 900 ppm | Warning displayed |
| 22Β°C | 88% | 1800 ppm | Warning displayed |
| 14Β°C | 90% | 900 ppm | Warning displayed |
The application is deployed on Streamlit Community Cloud.
Live Application:
https://zelbytes-yield-forecasting-n7jju6xpvrhfz7mr7dpig8.streamlit.app/