Skip to content

AdrikaPanwar/Crop_Dataset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌾 Crop Recommendation with Machine Learning

This mini-project demonstrates how Machine Learning can assist farmers in choosing the most suitable crop for their field based on soil metrics. The goal is to predict the best crop using a simple dataset containing soil nutrient levels and pH values.


🧠 Project Objective

To build a multi-class classification model that can predict the optimal crop for a field using the following features:

  • N: Nitrogen content in the soil
  • P: Phosphorous content in the soil
  • K: Potassium content in the soil
  • pH: Acidity level of the soil

We also identify the single most important feature contributing to the prediction using individual logistic regression models.


πŸ“ Dataset

Filename: soil_measures.csv
Each row in the dataset represents soil conditions of a field and the optimal crop to grow.

Columns:

  • N: Nitrogen ratio
  • P: Phosphorous ratio
  • K: Potassium ratio
  • ph: pH value of the soil
  • crop: Target variable (crop name)

βš™οΈ Model & Approach

  • Algorithm Used: Logistic Regression (Multinomial)
  • Task: Multi-class Classification
  • Evaluation Metric: Weighted F1 Score

We trained separate models for each feature to evaluate their individual contribution to prediction accuracy.


πŸ“Š Results

Feature F1 Score
N 0.091
P 0.148
K 0.239 βœ…
pH 0.045

πŸ‘‰ Potassium (K) turned out to be the best single feature for predicting crop type.


πŸ“ Key Learnings

  • Even with minimal features, machine learning models can provide useful insights for agriculture.
  • Among the soil metrics, Potassium (K) had the highest predictive power in isolation.
  • Further improvement can be done using all features together, hyperparameter tuning, and advanced classifiers (e.g., Random Forest, XGBoost).

πŸ’‘ Future Work

  • Build a full pipeline using all features
  • Apply advanced models like Decision Trees or Random Forests
  • Add feature importance analysis using SHAP or permutation importance
  • Integrate real-time soil sensor data (IoT)

πŸ“Œ Requirements

  • Python 3.x
  • pandas
  • scikit-learn

Install required packages:

pip install pandas scikit-learn

πŸ“‚ Usage

import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn import metrics

Make sure soil_measures.csv is in the same directory as your script or Jupyter notebook.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published