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 recommendationsrf_yield_model.pkl- Random Forest model for yield predictionunified_recommendation_engine.pkl- Combined recommendation engineengine_config.pkl- Configuration for the recommendation engine
Model Utilities
crop_feature_names.pkl- Feature names for crop recommendation modelcrop_label_encoder.pkl- Label encoder for crop classescrop_scaler.pkl- Scaler for crop recommendation featuresscaler.pkl- Scaler for yield prediction featuresyield_feature_names.pkl- Feature names for yield prediction model
Data
engineered_features.csv- Processed agricultural featuresraw_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.
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support