How chandruthangadurai2005/crop-yield-prediction-system works
Purpose and Entry Points
This is a local AI decision-support application for crop-yield prediction and crop recommendation. The backend entry point is api/app.py, run as a Flask server on port 5001. The browser client is the standalone page ui/index.html; it communicates with the Flask REST API rather than requiring a packaged web-server frontend.
API and Application Orchestration
api/app.py is the architectural center: it hosts REST endpoints, accepts farm/environment inputs, applies domain logic, invokes ML artifacts, and returns prediction/recommendation results. It also forms the boundary between the browser client and external location/weather services. CORS support allows ui/index.html to call the local API across origins.
Input Intelligence and Normalization
The application’s request-processing stage converts agricultural inputs into model-ready values: land-area standardization, rainfall/climate handling, seasonal detection from date/month, and categorical context such as crop, region, and season. GPS-derived location and reverse-geocoded context feed this stage when available. This logic is expected in api/app.py; no separate domain module is present in the tree.
Machine-Learning Inference
Yield estimation uses a scikit-learn Random Forest regression model. Runtime inference depends on externally downloaded serialized model binaries placed in models/; the repository includes the persisted feature schema at models/feature_columns.pkl. The feature-column artifact is a key compatibility boundary: normalized request data must match the training-time feature set and ordering before prediction.
Recommendation Flow
The system combines predicted productivity with crop-selection logic to recommend a suitable crop for the supplied environmental and agricultural conditions. Recommendation is application-level orchestration in api/app.py, likely evaluating candidate crop contexts through the same feature-engineering and inference path rather than exposing a separately stored recommendation model.
Data and Training Provenance
Raw agricultural data resides at data/raw/crop_data.csv; prepared training data is at data/processed/cleaned_crop_yield_data.csv. Exploratory and preprocessing workflows are notebook-based in notebooks/preprocessing.ipynb and notebooks/check.ipynb. These are offline training/preparation assets, distinct from serving; production inference consumes serialized artifacts under models/.
Runtime, External Dependencies, and Boundaries
The serving runtime is Python with Flask/Flask-CORS, pandas/NumPy, scikit-learn, and joblib. The client runtime is plain HTML/CSS/JavaScript in ui/index.html. External integrations include OpenWeather for climate/rainfall information and a reverse-geocoding API for location context. Model binaries are not versioned in this repository and must be obtained from the linked Google Drive source, making artifact availability a deployment prerequisite.
Main entry points: app.py Flask API · cleaned_crop_yield_data.csv Prepared training data · index.html Standalone UI · feature_columns.pkl Feature schema
Components 15
Browser Client
- Standalone UI · Collects farm inputs and displays results.
ui/index.html
Serving Runtime
- Flask API · Central request orchestration and inference boundary.
api/app.py - CORS boundary · Allows the standalone browser page to call the local API.
api/app.py - Input normalization · Standardizes area, climate, season, and categorical inputs.
api/app.py - Feature assembly · Builds ordered model-ready feature vectors.
api/app.py - Yield inference
api/app.py - Crop recommendation · Evaluates crop contexts using predicted productivity.
api/app.py
ML Artifacts
- Feature schema · Defines training-time feature names and ordering.
models/feature_columns.pkl - Downloaded model binaries · Deployment prerequisite not versioned in the repository.
Offline Data Preparation
- Raw crop data
data/raw/crop_data.csv - Prepared training data
data/processed/cleaned_crop_yield_data.csv - Preprocessing workflow
notebooks/preprocessing.ipynb - Data checks
notebooks/check.ipynb
External Services
- OpenWeather · Supplies climate and rainfall context.
- Reverse geocoding API · Converts GPS coordinates into location context.
Connections 20
- Standalone UI → CORS boundary: cross-origin REST requests
- CORS boundary → Flask API: permits
- Flask API → Input normalization: processes inputs
- Flask API → OpenWeather: fetches climate context
- Flask API → Reverse geocoding API: resolves GPS context
- OpenWeather → Input normalization: rainfall and climate
- Reverse geocoding API → Input normalization: regional context
- Input normalization → Feature assembly: normalized fields
- Feature schema → Feature assembly: column contract
- Feature assembly → Yield inference: ordered feature vector
- Downloaded model binaries → Yield inference: loaded estimator
- Yield inference → Crop recommendation: productivity estimates
- Crop recommendation → Flask API: recommendation result
- Yield inference → Flask API: yield result
- Flask API → Standalone UI: JSON response
- Raw crop data → Preprocessing workflow: source data
- Preprocessing workflow → Prepared training data: cleaned training data
- Prepared training data → Data checks: validation input
- Prepared training data → Downloaded model binaries: training provenance
- Prepared training data → Feature schema: feature provenance