# πΎ AgroAid Mandi Price Prediction API
## Overview
The AgroAid Mandi Price Prediction API is a Machine Learning-powered service that predicts agricultural commodity prices using historical mandi market data.
The API is designed to integrate with the AgroAid platform and provide:
* Real-time price prediction
* 7-day price forecasting
* Market trend analysis
* Confidence scoring
* Sell/Hold recommendations
The model is trained on historical APMC mandi data and deployed using FastAPI and Render.
---
# Project Architecture
```
AgroAid App
β
βΌ
Supabase Database
β
βΌ
Feature Generation
β
βΌ
Mandi Prediction API
β
βΌ
LightGBM Model
β
βΌ
Prediction Results
```
---
# Technology Stack
### Backend
* Python
* FastAPI
* Pandas
* NumPy
### Machine Learning
* LightGBM
* Scikit-Learn
* Joblib
### Database
* Supabase PostgreSQL
### Deployment
* Render
---
# Project Structure
```
mandi-price-api/
β
βββ main.py
βββ requirements.txt
βββ district_mapping.json
βββ commodity_mapping.json
βββ README.md
β
βββ mandi_price_model.pkl
β
βββ training/
βββ train_model.ipynb
βββ clean_apmc_data.csv
βββ feature_engineering.py
```
---
# File Descriptions
## main.py
Main FastAPI application.
Responsibilities:
* Load trained model
* Accept API requests
* Generate predictions
* Generate forecasts
* Calculate trends
* Calculate confidence scores
* Generate recommendations
Available endpoints:
* GET /
* POST /predict
* POST /forecast
* POST /trend
* POST /confidence
* POST /recommendation
---
## mandi_price_model.pkl
Serialized LightGBM model.
Generated after training.
Used for:
* Single day prediction
* Forecast generation
---
## district_mapping.json
District encoder mapping.
Example:
```json
{
"Rewa": 47,
"Bhopal": 12
}
```
Purpose:
Convert district names into numerical values used by the model.
---
## commodity_mapping.json
Commodity encoder mapping.
Example:
```json
{
"Wheat": 58,
"Soybean": 125
}
```
Purpose:
Convert commodity names into numerical values β¦