๐ŸŒพ Optimized Crop Yield Prediction AI System

Hugging Face Spaces Python Gradio Scikit-Learn Model Accuracy License: MIT

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

  1. ๐Ÿ”ฎ 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.
  2. ๐ŸŒพ 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.
  3. โš™๏ธ 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.
  4. ๐Ÿ“Š Model Benchmarking & Feature Insights:

    • Compares 5 ML algorithms (Extra Trees, Random Forest, Decision Tree, LightGBM, XGBoost).
    • Grouped and individual feature importance charts.
  5. ๐Ÿ“ Dataset Explorer & Climate Insights:

    • Interactive data explorer previewing historical records and summary statistics.
  6. ๐Ÿš€ REST & Python API:

    • Built-in gradio_client and REST endpoints for programmatic agricultural forecasting.

๐Ÿ“Š 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

  1. Create a new Space at huggingface.co/new-space.
  2. Select Gradio as the Space SDK.
  3. Upload the following files to your Space:
    • app.py
    • requirements.txt
    • crop_yield_model.joblib
    • model_metadata.json
    • yield_df.csv
    • README.md
  4. 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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support