Soil analysis is critical for maximizing agricultural yield, yet measuring every metric (Nitrogen, Phosphorous, Potassium, and pH) can be costly for farmers. This project applies Machine Learning to help farmers identify the optimal crop for their land based on specific soil conditions.
The primary goal is to build a multi-class classification model and determine which single soil metric is the most predictive for choosing the right crop.
The dataset contains measurements from various fields, where each row represents the ideal soil conditions for a specific crop.
| Metric | Description |
|---|---|
| N | Nitrogen content ratio in the soil |
| P | Phosphorous content ratio in the soil |
| K | Potassium content ratio in the soil |
| pH | The acidity or alkalinity of the soil |
| crop | The target variable (e.g., wheat, rice, maize, etc.) |
- Checked for missing values and analyzed the unique categories in the
croptarget variable. - Split the data into Training (80%) and Testing (20%) sets to ensure unbiased evaluation.
Instead of using all features at once, this project evaluates the predictive power of each soil metric individually:
- Model: Logistic Regression (using the
multinomialsetting for multi-class support). - Process: A loop was used to train a unique model for each feature (N, P, K, and pH).
The F1-Score (weighted) was chosen as the primary metric. Since the goal is to find the most reliable individual predictor, the F1-score provides a better balance between precision and recall than simple accuracy, especially if crop classes are slightly imbalanced.
After evaluating each feature, the results identified the following:
- Best Predictive Feature: Potassium (K)
- Performance: Potassium yielded the highest F1-score, suggesting it is the most critical individual indicator for determining crop type in this dataset.
- Clone the repository:
git clone [https://github.com/YOUR_USERNAME/crop-classification.git](https://github.com/YOUR_USERNAME/crop-classification.git)