A user-friendly web application that recommends the most suitable crop to grow based on soil nutrients (N, P, K), temperature, humidity, pH, and rainfall. Built with Python, Flask, scikit-learn (Random Forest Classifier), and a clean HTML/CSS/JavaScript frontend..
This project helps farmers (especially in regions like Sri Lanka) make data-driven decisions for better yield and sustainable farming..
- Accurate Crop Prediction — Uses a trained Random Forest model (~99% accuracy on test data).
- Beautiful Responsive Interface — Modern form with gradient background, reset button, and real-time prediction display.
- Data Preprocessing & Model Training — Separate scripts for preprocessing, training, and testing.
- Weather Integration Ready — Code hooks for free APIs like OpenWeatherMap (auto-fetch Colombo/Negombo weather).
- Reset Form Button — Clears inputs and result easily.
- Modular Structure — Easy to extend (e.g., add fertilizer recommendation, market prices).
Here are visual examples of the Crop Recommendation System in action:
Screenshot showing the initial state: All input fields are blank, ready for user data entry. Includes the "Recommend Crop" and "Reset Form" buttons.
Screenshot showing a filled form, successful prediction (e.g., "Recommended Crop: rice"), and optional weather integration display for Negombo/Colombo area.
Note: Add your own screenshot here!
How to create one:
- Run the app (
python app.py)- Open http://127.0.0.1:5000 in your browser.
- Enter sample values (e.g., N=90, P=42, K=43, temp=25, humidity=80, pH=6.5, rainfall=200)
- Take a screenshot of the page after prediction (crop shown + weather bonus if integrated)
- Crop it nicely (remove browser tabs/taskbar)
- Save as
screenshots/app_screenshot.png(createscreenshots/folder if needed)- Commit & push to GitHub — the image will display in README.
- Backend: Python, Flask, scikit-learn, pandas, numpy, joblib
- Frontend: HTML5, CSS3 (with gradient & blur effects), JavaScript (Fetch API)
- Model: RandomForestClassifier (ensemble method – robust & high accuracy)
- Dataset: Crop Recommendation Dataset (~2200 rows, 22 crops)
- Clone the repository:
git clone https://github.com/your-username/crop-recommendation-system.git cd crop-recommendation-system.

