Agricultural Advisory System for Bangladesh

A comprehensive machine learning system for agricultural advisory services in Bangladesh, providing crop recommendations and yield predictions based on environmental conditions and weather forecasts.

🌾 Overview

This system provides:

  • Crop Recommendations: Suggests optimal crops based on environmental conditions (73 crop varieties)
  • Yield Prediction: Predicts crop yields using trained Random Forest models
  • Weather Integration: Real-time weather forecasts for 8 Bangladesh districts via Open-Meteo API
  • Unified Recommendation Engine: Combines weather data, crop recommendations, and yield predictions

πŸ“¦ Repository Contents

Models

  • crop_recommendation_model.pkl - Trained classifier for crop recommendations
  • rf_yield_model.pkl - Random Forest model for yield prediction
  • unified_recommendation_engine.pkl - Combined recommendation engine
  • engine_config.pkl - Configuration for the recommendation engine

Model Utilities

  • crop_feature_names.pkl - Feature names for crop recommendation model
  • crop_label_encoder.pkl - Label encoder for crop classes
  • crop_scaler.pkl - Scaler for crop recommendation features
  • scaler.pkl - Scaler for yield prediction features
  • yield_feature_names.pkl - Feature names for yield prediction model

Data

  • engineered_features.csv - Processed agricultural features
  • raw_crop_data.csv - Raw crop data for training

πŸš€ Quick Start

Installation

pip install -r requirements.txt

Download Models from Hugging Face

from huggingface_hub import hf_hub_download
import joblib

# Download crop recommendation model
crop_model_path = hf_hub_download(
    repo_id="Nur2712/agricultural-advisory",
    filename="models/crop_recommendation_model.pkl",
    local_dir="./models"
)

# Load the model
crop_model = joblib.load(crop_model_path)

# Download scaler
scaler_path = hf_hub_download(
    repo_id="Nur2712/agricultural-advisory",
    filename="utilities/crop_scaler.pkl",
    local_dir="./models"
)
scaler = joblib.load(scaler_path)

Using the Models

import joblib
import numpy as np
from huggingface_hub import hf_hub_download

# Download and load models
model_path = hf_hub_download(
    repo_id="Nur2712/agricultural-advisory",
    filename="models/crop_recommendation_model.pkl"
)
model = joblib.load(model_path)

scaler_path = hf_hub_download(
    repo_id="Nur2712/agricultural-advisory",
    filename="utilities/crop_scaler.pkl"
)
scaler = joblib.load(scaler_path)

# Prepare features (example)
features = np.array([[100, 25, 70, 50]])  # rainfall_mm, temp_avg, humidity_percent, area_hectares
features_scaled = scaler.transform(features)

# Make prediction
prediction = model.predict(features_scaled)
print(f"Recommended crop: {prediction[0]}")

πŸ“Š Model Details

Crop Recommendation Model

  • Type: Classification
  • Classes: 73 crop varieties
  • Features: Rainfall, temperature, humidity, area
  • Algorithm: Trained classifier (check model file for specifics)

Yield Prediction Model

  • Type: Regression
  • Algorithm: Random Forest
  • Features: Rainfall, temperature, humidity, area
  • Output: Predicted yield in metric tons

🌍 Supported Districts

The system supports 8 Bangladesh districts:

  • Dhaka
  • Chittagong
  • Sylhet
  • Rajshahi
  • Khulna
  • Barisal
  • Rangpur
  • Mymensingh

πŸ”§ API Integration

This system is designed to work with a FastAPI backend. See DEPLOYMENT.md for API endpoint documentation.

Example API Usage

import requests

# Get crop recommendations
response = requests.get(
    "http://localhost:8000/crops/recommendations",
    params={
        "rainfall_mm": 100,
        "temp_avg": 25,
        "humidity_percent": 70,
        "area_hectares": 50
    }
)
recommendations = response.json()

# Predict yield
response = requests.get(
    "http://localhost:8000/yield/predict",
    params={
        "area_hectares": 50,
        "rainfall_mm": 100,
        "temp_avg": 25,
        "humidity_percent": 70
    }
)
yield_prediction = response.json()

πŸ“ˆ Performance

  • Crop Recommendation Accuracy: Check model training logs
  • Yield Prediction: RMSE and RΒ² scores available in training documentation
  • Supported Crops: 73 varieties
  • Weather Forecast: 7-day forecasts via Open-Meteo API

πŸ› οΈ Development

Project Structure

β”œβ”€β”€ models/              # Trained ML models
β”œβ”€β”€ utilities/           # Scalers, encoders, feature names
β”œβ”€β”€ data/               # Training and processed data
└── DEPLOYMENT.md       # Deployment documentation

Requirements

  • Python 3.11+
  • scikit-learn
  • pandas
  • numpy
  • joblib
  • huggingface_hub (for downloading models)

πŸ“ Citation

If you use this model in your research, please cite:

@misc{agricultural-advisory-bangladesh,
  title={Agricultural Advisory System for Bangladesh},
  author={Nur2712},
  year={2025},
  howpublished={\url{https://huggingface.co/Nur2712/agricultural-advisory}}
}

πŸ“„ License

MIT License - See LICENSE file for details

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“§ Contact

For questions or support, please open an issue in this repository.

πŸ™ Acknowledgments

  • Open-Meteo for weather data API
  • Bangladesh Agricultural Research Institute for data support
  • scikit-learn community for ML tools

Note: This model is trained on Bangladesh-specific agricultural data. Results may vary for other regions.

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

Space using Nur2712/agricultural-advisory 1