Skip to content

Repository files navigation

🌾 YIELDICT AI β€” Smart Crop Yield Prediction & Farm Decision Support

Streamlit App Python Version Scikit-Learn Git LFS

YIELDICT AI is a machine learning agricultural intelligence and decision-support platform designed to forecast crop yields, evaluate farm economics, and provide risk-mitigated crop recommendations for Indian agriculture.

Powered by an ensemble Random Forest Regression Pipeline ($R^2 = 0.9805$), the platform transforms raw agro-climatic inputs into monetary insights, optimal fertilizer application curves, and climate drought simulations.


πŸ“Έ Key Features

1. 🌾 High-Precision Yield & Revenue Forecasting

  • Multi-Parameter Inference: Evaluates 55 crop types across 30 Indian states and 6 agricultural seasons.
  • Synchronized Controls: Interactive numeric boxes and sliders for Cultivated Area, Annual Rainfall, Fertilizer Usage, and Pesticide Application.
  • Monetary Valuation: Calculates total farm output ($Yield \times Area$) and expected gross revenue in INR (β‚Ή Lakhs / β‚Ή Crores) mapped to Government Minimum Support Price (MSP) benchmarks.

2. πŸ† Multi-Crop Profitability Leaderboard

  • Evaluates alternative crops viable in the selected state and season.
  • Ranks top alternative opportunities and displays an interactive Altair Revenue Bar Chart to maximize farm returns.

3. πŸ§ͺ Fertilizer ROI & Profit Sweet-Spot Optimizer

  • Simulates marginal fertilizer cost (β‚Ή30/kg) vs. crop yield returns across $25% - 200%$ dosage variations.
  • Pinpoints the Economic Sweet-Spot Dosage (kg/ha) and calculates potential net profit uplift.
  • Embeds an interactive Fertilizer Dosage vs. Net Profit Curve.

4. 🌧️ Climate Stress & Drought Resilience Simulator

  • Stress-tests farm yields against 5 monsoon rainfall scenarios ($-50%$ drought deficit to $+50%$ excess monsoon).
  • Computes a Drought Resilience Score (%) and categorizes the farm under automated climate risk tiers (πŸ›‘οΈ Low Risk / ⚠️ Moderate Risk / 🚨 High Risk).

5. 🎨 Botanical Paper & Nature Glassmorphism UI

  • Curated emerald-forest palette (#2d6a4f, #52b788, #1b382b), frosted glass surfaces, and responsive typography (Playfair Display + Plus Jakarta Sans).

πŸ› οΈ Tech Stack & Dependencies

Layer Technology
Frontend UI Streamlit, HTML5, Vanilla CSS3 (Custom Botanical Paper Theme)
Data Visualization Altair Interactive Visualizations
Machine Learning Scikit-Learn (Pipeline, ColumnTransformer, OneHotEncoder, RandomForestRegressor)
Data Manipulation Pandas, NumPy
Serialization Joblib, Git LFS

πŸš€ Step-by-Step Setup Guide

1. Clone the Repository

git clone https://github.com/TeamKinetix/Yieldict_AI.git
cd Yieldict_AI

2. Initialize Git LFS (for Model Weights)

The trained model (crop_yield_model.pkl, 175.5 MB) is tracked with Git Large File Storage (LFS):

git lfs install
git lfs pull

3. Set Up a Virtual Environment

# Windows
python -m venv venv
.\venv\Scripts\activate

# macOS / Linux
python3 -m venv venv
source venv/bin/activate

4. Install Dependencies

pip install -r requirements.txt

πŸ’» How to Run

Method 1: Launch the Main Web Application (Recommended)

streamlit run "ML base_line trainning/ML base_line trainning/app.py"

Or use the launcher wrapper:

streamlit run "ML base_line trainning/app.py"

Once started, open http://localhost:8501 in your browser.


Method 2: Launch the Standalone Optimizer API Server

For microservice setups or programmatic querying:

python optimizer/server.py

Access the advisory endpoint at http://localhost:8000.


Method 3: Run the CLI Decision Advisory Tool

For fast command-line farm simulations:

python optimizer/crop_optimizer.py

🧠 Model Training & Pipeline Architecture

The model is trained on 19,689 validated historical agricultural records using a single scikit-learn Pipeline:

Input Features (7)
β”‚
β”œβ”€β”€ Categorical Features ['crop', 'season', 'state']
β”‚   └── OneHotEncoder(handle_unknown='ignore', sparse_output=False) -> [88 dimensions]
β”‚
β”œβ”€β”€ Numerical Features ['area', 'annual_rainfall', 'fertilizer', 'pesticide']
β”‚   └── Passthrough -> [7 dimensions]
β”‚
└── Regressor
    └── RandomForestRegressor(n_estimators=100, max_depth=None, random_state=42, n_jobs=-1)

Model Performance Metrics

  • Coefficient of Determination ($R^2$): 0.9805 (98.05% variance explained)
  • Mean Absolute Error (MAE): 8.79 t/ha
  • Root Mean Squared Error (RMSE): 118.42 t/ha

How to Retrain the Model:

To reproduce or retrain the pipeline from scratch, open and run all cells in:

important code/Baseline_Model.ipynb

The notebook automatically outputs the updated crop_yield_model.pkl pipeline.


πŸ“‚ Project Directory Structure

CropYield/
β”‚
β”œβ”€β”€ .gitattributes                  # Git LFS configuration (*.pkl tracking)
β”œβ”€β”€ .gitignore                      # Tailored repository ignore rules
β”œβ”€β”€ .streamlit/                     # Streamlit theme and viewport configuration
β”‚   └── config.toml
β”‚
β”œβ”€β”€ 6 files/                        # PRD, Architecture, and Design specifications
β”‚   β”œβ”€β”€ PRD.md
β”‚   β”œβ”€β”€ architecture.md
β”‚   β”œβ”€β”€ design.md
β”‚   └── phases.md
β”‚
β”œβ”€β”€ important code/                 # Training notebooks & model checkpoints
β”‚   β”œβ”€β”€ Baseline_Model.ipynb        # Model training & evaluation notebook
β”‚   └── crop_yield_cleaned.csv      # Agricultural dataset (19,689 records)
β”‚
β”œβ”€β”€ ML base_line trainning/         # Web Application core
β”‚   β”œβ”€β”€ ML base_line trainning/
β”‚   β”‚   β”œβ”€β”€ app.py                  # Main Streamlit web application
β”‚   β”‚   β”œβ”€β”€ crop_yield_model.pkl    # Serialized scikit-learn Pipeline (175.5 MB)
β”‚   β”‚   β”œβ”€β”€ crop_yield_cleaned.csv  # Cleaned dataset
β”‚   β”‚   └── background.png          # UI graphics & branding
β”‚   └── app.py                      # Root launcher script
β”‚
β”œβ”€β”€ optimizer/                      # Advisory & Simulation Engine
β”‚   β”œβ”€β”€ __init__.py                 # Package initializer
β”‚   β”œβ”€β”€ crop_optimizer.py           # Multi-crop, fertilizer ROI & climate stress logic
β”‚   β”œβ”€β”€ msp_data.py                 # Crop pricing, MSP data & categories
β”‚   └── server.py                   # Standalone advisory service (Port 8000)
β”‚
β”œβ”€β”€ processed data for training/    # Cleaned datasets & EDA documentation
β”‚   β”œβ”€β”€ STEP_3_EDA_REPORT.md
β”‚   └── crop_yield_cleaned.csv
β”‚
β”œβ”€β”€ requirements.txt                # Python package dependencies
└── README.md                       # Master project documentation

πŸ‘₯ Authors & Team

Developed by Kinetix. For feedback, inquiries, or contributions, please open a GitHub Issue or Pull Request.

About

HACK-ML Hackathon

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages