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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# π± CropSense β Crop Recommendation System
|
| 11 |
+
|
| 12 |
+
A Flask web application that predicts the most suitable crop to grow based on soil nutrient parameters. Built with Scikit-learn and deployed with a clean, responsive UI.
|
| 13 |
+
|
| 14 |
+
[](https://python.org)
|
| 15 |
+
[](https://flask.palletsprojects.com)
|
| 16 |
+
[](https://scikit-learn.org)
|
| 17 |
+
[](LICENSE)
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
Live Demo: https://crop-predict-wgrr.onrender.com/
|
| 22 |
+
|
| 23 |
+
Alternate Link: https://lovnishverma-croppredict.hf.space/
|
| 24 |
+
|
| 25 |
+
## π Overview
|
| 26 |
+
|
| 27 |
+
CropSense takes 11 soil parameters as input and recommends the most suitable crop using a **Logistic Regression** model trained on the [Crop dataset](https://raw.githubusercontent.com/lovnishverma/datasets/refs/heads/main/Crop.csv). It also returns the **top-3 predictions with confidence percentages**.
|
| 28 |
+
|
| 29 |
+
This project was developed as a teaching artifact for the **IndiaAI Foundations of Artificial Intelligence** programme at **NIELIT Ropar**, demonstrating the end-to-end ML workflow: data β model β deployment.
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## ποΈ Project Structure
|
| 34 |
+
|
| 35 |
+
```
|
| 36 |
+
crop-predict/
|
| 37 |
+
βββ app.py # Flask application
|
| 38 |
+
βββ classification.ipynb # Model training notebook (Colab)
|
| 39 |
+
βββ crop_recommendation_model.joblib # Saved trained model
|
| 40 |
+
βββ requirements.txt
|
| 41 |
+
βββ static/
|
| 42 |
+
β βββ css/ # Stylesheets
|
| 43 |
+
βββ templates/
|
| 44 |
+
βββ index.html # Frontend UI
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
## π§ͺ Input Features
|
| 50 |
+
|
| 51 |
+
The model uses 11 soil parameters:
|
| 52 |
+
|
| 53 |
+
| Feature | Description | Unit |
|
| 54 |
+
|---------|----------------------|--------|
|
| 55 |
+
| N | Nitrogen | kg/ha |
|
| 56 |
+
| P | Phosphorus | kg/ha |
|
| 57 |
+
| K | Potassium | kg/ha |
|
| 58 |
+
| ph | pH Level | β |
|
| 59 |
+
| EC | Electrical Conductivity | dS/m |
|
| 60 |
+
| S | Sulfur | mg/kg |
|
| 61 |
+
| Cu | Copper | mg/kg |
|
| 62 |
+
| Fe | Iron | mg/kg |
|
| 63 |
+
| Mn | Manganese | mg/kg |
|
| 64 |
+
| Zn | Zinc | mg/kg |
|
| 65 |
+
| B | Boron | mg/kg |
|
| 66 |
+
|
| 67 |
+
**Sample values** (pomegranate): `175, 36, 216, 5.9, 0.15, 0.28, 15.69, 114.20, 56.87, 31.28, 28.62`
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
## βοΈ ML Pipeline
|
| 72 |
+
|
| 73 |
+
```
|
| 74 |
+
Dataset (Crop.csv)
|
| 75 |
+
β
|
| 76 |
+
Feature/Target Split (X = 11 soil params, y = crop label)
|
| 77 |
+
β
|
| 78 |
+
Train-Test Split (80/20, random_state=42)
|
| 79 |
+
β
|
| 80 |
+
Logistic Regression (sklearn)
|
| 81 |
+
β
|
| 82 |
+
Evaluation (accuracy_score, classification_report, confusion matrix)
|
| 83 |
+
β
|
| 84 |
+
Model Serialization (joblib β .joblib file)
|
| 85 |
+
β
|
| 86 |
+
Flask REST API (/predict)
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
See [`classification.ipynb`](classification.ipynb) for the full training walkthrough.
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## π Getting Started
|
| 94 |
+
|
| 95 |
+
### 1. Clone the repository
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
git clone https://github.com/lovnishverma/crop-predict.git
|
| 99 |
+
cd crop-predict
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
### 2. Install dependencies
|
| 103 |
+
|
| 104 |
+
```bash
|
| 105 |
+
pip install -r requirements.txt
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### 3. Run the app
|
| 109 |
+
|
| 110 |
+
```bash
|
| 111 |
+
python app.py
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
Open your browser at **http://127.0.0.1:5000**
|
| 115 |
+
|
| 116 |
+
> **Note:** The pre-trained `crop_recommendation_model.joblib` is already included. If you want to retrain, open `classification.ipynb` in Google Colab and run all cells β it will regenerate the `.joblib` file.
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## π API Reference
|
| 121 |
+
|
| 122 |
+
### `POST /predict`
|
| 123 |
+
|
| 124 |
+
Accepts `multipart/form-data` with all 11 soil parameters.
|
| 125 |
+
|
| 126 |
+
**Request (curl example):**
|
| 127 |
+
|
| 128 |
+
```bash
|
| 129 |
+
curl -X POST http://127.0.0.1:5000/predict \
|
| 130 |
+
-F "N=175" -F "P=36" -F "K=216" -F "ph=5.9" -F "EC=0.15" \
|
| 131 |
+
-F "S=0.28" -F "Cu=15.69" -F "Fe=114.20" -F "Mn=56.87" \
|
| 132 |
+
-F "Zn=31.28" -F "B=28.62"
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
**Response:**
|
| 136 |
+
|
| 137 |
+
```json
|
| 138 |
+
{
|
| 139 |
+
"crop": "pomegranate",
|
| 140 |
+
"top3": [
|
| 141 |
+
{ "crop": "pomegranate", "prob": 87.3 },
|
| 142 |
+
{ "crop": "mango", "prob": 7.1 },
|
| 143 |
+
{ "crop": "grapes", "prob": 3.2 }
|
| 144 |
+
]
|
| 145 |
+
}
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
---
|
| 149 |
+
|
| 150 |
+
## π¦ Requirements
|
| 151 |
+
|
| 152 |
+
```
|
| 153 |
+
flask>=2.3
|
| 154 |
+
scikit-learn>=1.3
|
| 155 |
+
pandas>=2.0
|
| 156 |
+
joblib>=1.3
|
| 157 |
+
numpy>=1.24
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
---
|
| 161 |
+
|
| 162 |
+
## π Dataset
|
| 163 |
+
|
| 164 |
+
- **Source:** [`lovnishverma/datasets`](https://github.com/lovnishverma/datasets) β `Crop.csv`
|
| 165 |
+
- **Features:** 11 soil nutrient columns
|
| 166 |
+
- **Target:** `label` β crop name (e.g. pomegranate, wheat, rice, maize, etc.)
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
+
|
| 170 |
+
## π Author
|
| 171 |
+
|
| 172 |
+
**Lovnish Verma**
|
| 173 |
+
Project Engineer, NIELIT Ropar (Deemed University), Punjab
|
| 174 |
+
|
| 175 |
+
[](https://github.com/lovnishverma)
|
| 176 |
+
[](https://linkedin.com/in/lovnishverma)
|
| 177 |
+
[](https://huggingface.co/lovnishverma)
|
| 178 |
+
[](https://lovnishverma.in)
|
| 179 |
+
|
| 180 |
+
---
|
| 181 |
+
|
| 182 |
+
## π License
|
| 183 |
+
|
| 184 |
+
This project is licensed under the MIT License.
|
| 185 |
+
|
| 186 |
+
---
|
| 187 |
+
|
| 188 |
+
> Built for IndiaAI students at NIELIT Ropar Β· No brainrot. Just facts. πΎ
|
| 189 |
+
|