An AI model and its training which helps farmer decide next crop based on the previous crop, soil and other factors .
# 🌾 Crop Recommendation System
This project is a machine learning model designed to recommend the most suitable crop to plant based on environmental and soil conditions. It analyzes key factors like nutrient levels (Nitrogen, Phosphorous, Potassium), temperature, humidity, pH, and rainfall to predict the optimal crop type.
The analysis, model training, and evaluation are all contained in the `1.ipynb` notebook.
## 📊 Dataset
The model is trained on the `Crop_recommendation.csv` dataset.
**Features (Input):**
* `N`: Ratio of Nitrogen content in soil
* `P`: Ratio of Phosphorous content in soil
* `K`: Ratio of Potassium content in soil
* `temperature`: Temperature in degrees Celsius
* `humidity`: Relative humidity in %
* `ph`: pH value of the soil
* `rainfall`: Rainfall in mm
**Target (Output):**
* `label`: The type of crop (e.g., rice, maize, chickpea, coffee, etc.)
## ⚙️ Project Workflow
1. **Data Loading:** The `Crop_recommendation.csv` dataset is loaded using `pandas`.
2. **Data Splitting:** The data is split into an 80% training set and a 20% testing set.
3. **Model Training:** Two different classification models are trained on the data:
* **Decision Tree Classifier** (with `criterion="entropy"` and `max_depth=5`)
* **Gaussian Naive Bayes**
4. **Model Evaluation:** Both models are evaluated using the test set, and their accuracy is calculated and compared.
5. **Model Saving:** The trained models are saved to disk as `.pkl` files (`Decision_Tree.pkl` and `Navis_Base.pkl`) using `pickle`.
## 📈 Models and Results
The Gaussian Naive Bayes model provided the best performance by a significant margin.
| Model | Test Accuracy |
| :--- | :--- |
| Decision Tree | 86.59% |
| **Gaussian Naive Bayes** | **99.55%** |
A visualization of this comparison is generated in the notebook. Given its high accuracy, the **Gaussian Naive Bayes** model (`Navis_Base.pkl`) is the final model used for prediction.
## 🛠️ How to Use
### 1\. Requirements
You will need the foll …