๐พ Optimized Crop Yield Prediction AI System
An end-to-end Machine Learning web application designed to forecast agricultural crop yields, recommend optimal crops based on regional climate parameters, and simulate environmental sensitivity curves (Rainfall, Temperature, and Pesticide application).
๐ Key Features
๐ฎ Interactive Crop Yield Forecaster:
- Supports 101 Countries and 10 Major Staple Crops.
- Input Climate metrics: Annual Rainfall (mm), Average Temperature (ยฐC), Pesticides (Tonnes), and Year.
- Calculates yield in Tonnes/Hectare (t/ha), hg/ha, kg/ha, kg/acre, and Total Farm Harvest.
- Agricultural Yield Performance Rating Badge (๐ Exceptional, ๐ข Above Average, ๐ก Normal, ๐ด Low) with historical comparisons.
- โก 1-Click Country Defaults: Automatically loads historical average climate metrics for any selected country.
๐พ Multi-Crop Optimization & Recommender:
- Evaluates all 10 major crops simultaneously under the same climate conditions.
- Highlights the #1 Highest Yielding Crop with interactive Plotly ranking charts.
โ๏ธ Climate & Input Sensitivity Simulator:
- Interactive "What-If" response curves:
- Rainfall vs Yield: Identifies dry vs optimal vs flood zones.
- Temperature vs Yield: Pinpoints thermal growth sweet spots.
- Pesticide vs Yield: Illustrates application efficacy and diminishing return plateaus.
- Interactive "What-If" response curves:
๐ Model Benchmarking & Feature Insights:
- Compares 5 ML algorithms (Extra Trees, Random Forest, Decision Tree, LightGBM, XGBoost).
- Grouped and individual feature importance charts.
๐ Dataset Explorer & Climate Insights:
- Interactive data explorer previewing historical records and summary statistics.
๐ REST & Python API:
- Built-in
gradio_clientand REST endpoints for programmatic agricultural forecasting.
- Built-in
๐ Dataset & Model Architecture
Dataset Overview (Kaggle / FAO)
- Total Records: 28,242 historical agricultural observations (1990 โ 2013).
- Geographic Coverage: 101 countries worldwide.
- Crops (10): Cassava, Maize, Plantains and others, Potatoes, Rice (paddy), Sorghum, Soybeans, Sweet potatoes, Wheat, Yams.
- Features:
Area,Item,Year,average_rain_fall_mm_per_year,pesticides_tonnes,avg_temp. - Target Variable:
hg/ha_yield(Hectograms per Hectare).
Benchmark Performance
| Model Algorithm | Rยฒ Score | MAE (hg/ha) | RMSE (hg/ha) | Training Time |
|---|---|---|---|---|
| Extra Trees (Champion) | 0.9913 (99.13%) | 2,570.21 | 7,925.48 | ~3.1s |
| Random Forest | 0.9876 (98.76%) | 3,452.75 | 9,470.36 | ~2.6s |
| Decision Tree | 0.9794 (97.94%) | 3,628.86 | 12,210.03 | ~0.5s |
| LightGBM | 0.9679 (96.79%) | 8,649.42 | 15,259.90 | ~2.4s |
| XGBoost | 0.9621 (96.21%) | 9,904.11 | 16,569.78 | ~0.7s |
๐ ๏ธ Local Installation & Running
# 1. Clone the repository
git clone https://github.com/YOUR_USERNAME/optimized-crop-yield-prediction.git
cd optimized-crop-yield-prediction
# 2. Install dependencies
pip install -r requirements.txt
# 3. (Optional) Re-train the model
python train_model.py
# 4. Launch the Gradio Web Application
python app.py
Open your browser at http://localhost:7860.
๐ Deploying to Hugging Face Spaces
- Create a new Space at huggingface.co/new-space.
- Select Gradio as the Space SDK.
- Upload the following files to your Space:
app.pyrequirements.txtcrop_yield_model.joblibmodel_metadata.jsonyield_df.csvREADME.md
- Hugging Face will automatically build the environment and start the app in ~60 seconds!
Detailed instructions are available in DEPLOYMENT_GUIDE.md.
๐ License
This project is licensed under the MIT License.
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐ Ask for provider support