A Machine Learning-based Crop Recommendation System that predicts the most suitable crop based on soil nutrients and environmental conditions.
The system uses a K-Nearest Neighbors (KNN) classification algorithm and considers factors such as nitrogen, phosphorus, potassium, soil pH, temperature, humidity, and rainfall for crop prediction.
Agricultural crop selection depends on various soil and weather conditions. This project uses machine learning to recommend suitable crops based on input parameters.
The system also integrates real-time weather data using the Open-Meteo API to obtain temperature, humidity, and rainfall information.
- 🌱 Crop recommendation using Machine Learning
- 🤖 K-Nearest Neighbors (KNN) classification model
- 🌦️ Real-time weather data integration
- 🧪 Uses soil nutrient parameters:
- Nitrogen (N)
- Phosphorus (P)
- Potassium (K)
- Soil pH
- 📊 Uses environmental factors:
- Temperature
- Humidity
- Rainfall
- Python 🐍
- Pandas
- Scikit-learn
- NumPy
- Requests
- Open-Meteo API
Crop-Recommendation-System
│
├── crop_rec_system.py # Crop recommendation ML program
├── Crop_recommendation.csv # Dataset
├── requirements.txt # Required Python libraries
├── README.md # Project documentation
└── .gitignore # Git ignored files
The dataset contains soil and environmental parameters used for crop prediction.
| Feature | Description |
|---|---|
| N | Nitrogen content |
| P | Phosphorus content |
| K | Potassium content |
| temperature | Temperature value |
| humidity | Humidity percentage |
| ph | Soil pH value |
| rainfall | Rainfall amount |
label → Recommended crop
Clone the repository:
git clone https://github.com/Sathyabyte/Crop-Recommendation-System.gitNavigate into the project folder:
cd Crop-Recommendation-SystemInstall dependencies:
pip install -r requirements.txtRun the Python program:
python crop_rec_system.pyThe program will:
- Load the crop dataset
- Train a KNN classification model
- Fetch weather information
- Take soil nutrient values as input
- Predict the recommended crop
Enter Nitrogen value: 90
Enter Phosphorus value: 42
Enter Potassium value: 43
Enter pH value: 6.5
Recommended Crop: rice
- Save trained model for faster predictions
- Add a user-friendly GUI/web interface
- Improve model comparison using multiple ML algorithms
- Add location-based crop recommendations
Sathyabyte
BCA (Hons) Student | Data Science + AI/ML