Dataset Viewer
Auto-converted to Parquet Duplicate
N
int64
0
140
P
int64
5
145
K
int64
5
205
temperature
float64
8.83
43.7
humidity
float64
14.3
100
ph
float64
3.5
9.94
rainfall
float64
20.2
299
label
stringclasses
22 values
90
42
43
20.879744
82.002744
6.502985
202.935536
rice
85
58
41
21.770462
80.319644
7.038096
226.655537
rice
60
55
44
23.004459
82.320763
7.840207
263.964248
rice
74
35
40
26.491096
80.158363
6.980401
242.864034
rice
78
42
42
20.130175
81.604873
7.628473
262.717341
rice
69
37
42
23.058049
83.370118
7.073454
251.055
rice
69
55
38
22.708838
82.639414
5.700806
271.32486
rice
94
53
40
20.277744
82.894086
5.718627
241.974195
rice
89
54
38
24.515881
83.535216
6.685346
230.446236
rice
68
58
38
23.223974
83.033227
6.336254
221.209196
rice
91
53
40
26.527235
81.417538
5.386168
264.61487
rice
90
46
42
23.978982
81.450616
7.502834
250.083234
rice
78
58
44
26.800796
80.886848
5.108682
284.436457
rice
93
56
36
24.014976
82.056872
6.984354
185.277339
rice
94
50
37
25.665852
80.66385
6.94802
209.586971
rice
60
48
39
24.282094
80.300256
7.042299
231.086335
rice
85
38
41
21.587118
82.788371
6.249051
276.655246
rice
91
35
39
23.79392
80.41818
6.97086
206.261186
rice
77
38
36
21.865252
80.192301
5.953933
224.555017
rice
88
35
40
23.579436
83.587603
5.853932
291.298662
rice
89
45
36
21.325042
80.474764
6.442475
185.497473
rice
76
40
43
25.157455
83.117135
5.070176
231.384316
rice
67
59
41
21.947667
80.973842
6.012633
213.356092
rice
83
41
43
21.052536
82.678395
6.254028
233.107582
rice
98
47
37
23.483813
81.332651
7.375483
224.058116
rice
66
53
41
25.075635
80.523891
7.778915
257.003887
rice
97
59
43
26.359272
84.044036
6.2865
271.358614
rice
97
50
41
24.529227
80.544986
7.07096
260.263403
rice
60
49
44
20.775761
84.497744
6.244841
240.081065
rice
84
51
35
22.301574
80.644165
6.043305
197.979122
rice
73
57
41
21.44654
84.94376
5.824709
272.20172
rice
92
35
40
22.179319
80.331272
6.357389
200.088279
rice
85
37
39
24.527837
82.736856
6.364135
224.675723
rice
98
53
38
20.267076
81.638952
5.014507
270.441727
rice
88
54
44
25.735429
83.882662
6.149411
233.132137
rice
95
55
42
26.795339
82.148087
5.950661
193.347399
rice
99
57
35
26.757542
81.17734
5.96037
272.299906
rice
95
39
36
23.863305
83.152508
5.561399
285.249365
rice
60
43
44
21.019447
82.952217
7.416245
298.401847
rice
63
44
41
24.172988
83.728757
5.58337
257.034355
rice
62
42
36
22.781338
82.067191
6.43001
248.718323
rice
64
45
43
25.629801
83.528423
5.534878
209.900198
rice
83
60
36
25.597049
80.145093
6.903986
200.834898
rice
82
40
40
23.830675
84.813601
6.271479
298.560118
rice
85
52
45
26.313555
82.36699
7.224286
265.535594
rice
91
35
38
24.897282
80.525861
6.134287
183.679321
rice
76
49
42
24.958779
84.479634
5.206373
196.956001
rice
74
39
38
23.241135
84.592018
7.782051
233.045346
rice
79
43
39
21.666283
80.709606
7.062779
210.814209
rice
88
55
45
24.635449
80.41363
7.730368
253.720278
rice
60
36
43
23.431219
83.063101
5.286204
219.904835
rice
76
60
39
20.045414
80.347756
6.76624
208.581016
rice
93
56
42
23.85724
82.22573
7.382763
195.094831
rice
65
60
43
21.971994
81.899182
5.658169
227.363701
rice
95
52
36
26.229169
83.836258
5.54336
286.508373
rice
75
38
39
23.446768
84.793524
6.21511
283.933847
rice
74
54
38
25.655535
83.470211
7.120273
217.378858
rice
91
36
45
24.443455
82.454326
5.950648
267.976195
rice
71
46
40
20.280194
82.123542
7.236705
191.953574
rice
99
55
35
21.723831
80.23899
6.501698
277.962619
rice
72
40
38
20.41447
82.208026
7.592491
245.15113
rice
83
58
45
25.755286
83.518271
5.875346
245.66268
rice
93
58
38
20.615214
83.773456
6.9324
279.545172
rice
70
36
42
21.841069
80.728864
6.94621
202.383832
rice
76
47
42
20.083696
83.291147
5.739175
263.637218
rice
99
41
36
24.458021
82.748356
6.738652
182.561632
rice
99
54
37
21.143475
80.335029
5.59482
198.673094
rice
86
59
35
25.787206
82.11124
6.946636
243.512041
rice
69
46
41
23.641248
80.285979
5.01214
263.11033
rice
91
56
37
23.431916
80.568878
6.363472
269.503916
rice
61
52
41
24.976695
83.891805
6.880431
204.800185
rice
67
45
38
22.72791
82.170688
7.300411
260.887506
rice
79
42
37
24.873007
82.840226
6.587919
295.609449
rice
78
43
42
21.323763
83.003205
7.283737
192.319754
rice
75
54
36
26.294655
84.569193
7.023936
257.491491
rice
97
36
45
22.228698
81.858729
6.939084
278.079179
rice
67
47
44
26.730724
81.785968
7.868475
280.404439
rice
73
35
38
24.889212
81.979271
5.005307
185.946143
rice
77
36
37
26.884449
81.460337
6.136132
194.576656
rice
81
41
38
22.678461
83.728744
7.52408
200.913316
rice
68
57
43
26.088679
80.379799
5.706943
182.90435
rice
72
45
35
25.429775
82.946826
5.758506
195.357454
rice
61
53
43
26.403232
81.056355
6.349606
223.367188
rice
67
43
39
26.04372
84.969072
5.999969
186.753677
rice
67
58
39
25.282722
80.543728
5.453592
220.115671
rice
66
60
38
22.085766
83.470383
6.372576
231.736496
rice
82
43
38
23.286172
81.433216
5.105588
242.317063
rice
84
50
44
25.48592
81.406335
5.935344
182.654936
rice
81
53
42
23.675754
81.035693
5.177823
233.703498
rice
91
50
40
20.824771
84.134188
6.462392
230.224222
rice
93
53
38
26.929951
81.914112
7.069172
290.679378
rice
90
44
38
23.835095
83.883871
7.473134
241.201351
rice
81
45
35
26.528728
80.122675
6.158377
218.916357
rice
78
40
38
26.464283
83.856427
7.549874
248.225649
rice
60
51
36
22.696578
82.810889
6.028322
256.996476
rice
88
46
42
22.683191
83.463583
6.604993
194.265172
rice
93
47
37
21.533463
82.140041
6.500343
295.92488
rice
60
55
45
21.408658
83.329319
5.935745
287.576694
rice
78
35
44
26.543481
84.673536
7.072656
183.622266
rice
65
37
40
23.359054
83.595123
5.333323
188.413665
rice
End of preview. Expand in Data Studio

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

🌱 Crop Recommendation Dataset

A machine learning dataset for crop recommendation based on soil properties and environmental conditions. The dataset contains measurements of essential soil nutrients and climatic parameters, along with the crop label that is suitable for those conditions.

This dataset can be used for machine learning classification, agricultural analytics, decision-support systems, and smart farming applications.


πŸ“Œ Dataset Overview

Property Details
Dataset Name Crop Recommendation Dataset
Task Multi-class Classification
Domain Agriculture / Machine Learning
Primary Objective Recommend the most suitable crop
Input Features Soil nutrients + environmental conditions
Target Variable Crop label
Data Type Tabular
File Format CSV
ML Problem Supervised Learning
Recommended Models Random Forest, XGBoost, SVM, Neural Networks, Decision Trees

🎯 Purpose

The purpose of this dataset is to develop machine learning models capable of recommending an appropriate crop based on the characteristics of a particular agricultural environment.

The model learns relationships between:

  • Nitrogen concentration
  • Phosphorus concentration
  • Potassium concentration
  • Temperature
  • Relative humidity
  • Soil pH
  • Rainfall

and the corresponding crop that is suitable for those conditions.

A trained model can then predict a crop recommendation for a new set of soil and environmental measurements.


πŸ“Š Dataset Features

The dataset contains the following variables:

Feature Description Unit / Representation
N Nitrogen content in the soil Soil nutrient measurement
P Phosphorus content in the soil Soil nutrient measurement
K Potassium content in the soil Soil nutrient measurement
temperature Average environmental temperature Β°C
humidity Relative humidity %
ph Soil acidity/alkalinity pH scale
rainfall Rainfall received mm
label Recommended crop Categorical

Feature Types

Numerical features

N
P
K
temperature
humidity
ph
rainfall

Categorical target

label

🧠 Machine Learning Task

This dataset is primarily designed for a multi-class classification problem.

Given:

N
P
K
temperature
humidity
ph
rainfall

the machine learning model predicts:

label

Example

Input:

N = 90
P = 42
K = 43
temperature = 20.8
humidity = 82.0
ph = 6.5
rainfall = 202.9

Possible prediction:

Recommended Crop: Rice

The example above illustrates the prediction format. The actual prediction depends on the trained model and dataset.


πŸ”¬ Potential Applications

This dataset can be used for:

  • 🌾 Crop recommendation systems
  • πŸ€– Machine learning classification
  • 🌱 Smart agriculture
  • 🚜 Precision farming
  • πŸ“ˆ Agricultural data analysis
  • 🌦️ Climate-aware crop selection
  • πŸ§‘β€πŸŒΎ Decision-support systems
  • πŸ“± Agricultural recommendation applications
  • πŸ”¬ Machine learning experimentation
  • πŸŽ“ Academic and educational projects

πŸ—οΈ Suggested Machine Learning Pipeline

A typical machine learning workflow using this dataset is:

Raw Dataset
     β”‚
     β–Ό
Data Loading
     β”‚
     β–Ό
Data Cleaning
     β”‚
     β–Ό
Exploratory Data Analysis
     β”‚
     β–Ό
Feature / Target Separation
     β”‚
     β–Ό
Train / Test Split
     β”‚
     β–Ό
Feature Scaling (if required)
     β”‚
     β–Ό
Model Training
     β”‚
     β–Ό
Model Evaluation
     β”‚
     β–Ό
Crop Prediction

πŸ€– Recommended Algorithms

Several supervised learning algorithms can be evaluated on this dataset.

Baseline Models

  • Logistic Regression
  • Decision Tree
  • K-Nearest Neighbors

Ensemble Models

  • Random Forest
  • Gradient Boosting
  • XGBoost
  • LightGBM

Other Models

  • Support Vector Machine
  • Neural Networks
  • Multilayer Perceptron

For a practical crop recommendation system, Random Forest and gradient-boosting models are strong candidates because they can capture nonlinear relationships between environmental conditions and crop classes.


πŸ“ˆ Evaluation Metrics

Because the task is multi-class classification, recommended evaluation metrics include:

  • Accuracy
  • Precision
  • Recall
  • F1-score
  • Confusion Matrix

For a more complete evaluation, macro-averaged and weighted F1-scores can also be reported.

Example:

Accuracy
Precision
Recall
F1-Score
Confusion Matrix

πŸ”Ž Data Exploration

Useful exploratory analyses include:

  • Distribution of nitrogen levels
  • Distribution of phosphorus levels
  • Distribution of potassium levels
  • Temperature distribution
  • Humidity distribution
  • Soil pH distribution
  • Rainfall distribution
  • Crop-class distribution
  • Feature correlations
  • Feature distributions by crop
  • Outlier analysis

Example visualizations:

Feature Distribution
        ↓
Correlation Analysis
        ↓
Crop-wise Comparison
        ↓
Feature Importance

🧹 Data Preprocessing

Depending on the version of the dataset, preprocessing may include:

  1. Checking for missing values
  2. Checking for duplicate records
  3. Detecting anomalous values
  4. Validating feature ranges
  5. Separating input features and target labels
  6. Encoding categorical labels if required
  7. Splitting data into training and testing sets
  8. Scaling numerical features when required by the selected algorithm

Tree-based models generally do not require feature scaling, while algorithms such as SVM, KNN, and neural networks may benefit from scaling.


⚠️ Dataset Limitations

This dataset should be considered a machine learning research and educational dataset, not a standalone agricultural decision-making system.

Crop suitability can depend on many factors that may not be represented in the dataset, including:

  • Soil type
  • Geographic location
  • Season
  • Crop variety
  • Irrigation availability
  • Local weather patterns
  • Pest and disease conditions
  • Soil depth
  • Soil organic matter
  • Agricultural practices
  • Market conditions
  • Extreme weather events

Therefore, predictions generated from a model trained on this dataset should not be treated as professional agricultural advice without additional validation and domain expertise.


🌍 Responsible Use

Users should avoid treating model predictions as guaranteed crop recommendations.

A responsible production system should combine machine learning predictions with:

  • Local agricultural knowledge
  • Regional climate data
  • Current weather information
  • Soil testing
  • Expert agricultural recommendations
  • Historical crop performance
  • Real-world validation

The model should be viewed as a decision-support tool, rather than a replacement for agricultural expertise.


πŸ§ͺ Example Python Usage

import pandas as pd

# Load dataset
df = pd.read_csv("Crop_recommendation.csv")

# Inspect dataset
print(df.head())
print(df.info())

# Separate features and target
X = df.drop("label", axis=1)
y = df["label"]

print("Features:")
print(X.columns)

print("\nTarget classes:")
print(y.unique())

🌳 Example Model

A Random Forest classifier can be used as a baseline:

from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, classification_report

X_train, X_test, y_train, y_test = train_test_split(
    X,
    y,
    test_size=0.2,
    random_state=42,
    stratify=y
)

model = RandomForestClassifier(
    n_estimators=200,
    random_state=42
)

model.fit(X_train, y_train)

predictions = model.predict(X_test)

print("Accuracy:", accuracy_score(y_test, predictions))
print(classification_report(y_test, predictions))

πŸš€ From Dataset to Production Application

This dataset can serve as the foundation for a complete crop recommendation application:

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Soil / Weather    β”‚
                    β”‚       Inputs        β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Data Validation   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   ML Classification β”‚
                    β”‚        Model        β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚ Crop Recommendation β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Web / Mobile App  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

A production implementation could additionally integrate:

  • REST API
  • Flask / FastAPI backend
  • React frontend
  • Database storage
  • Weather APIs
  • Soil data
  • Model monitoring
  • Cloud deployment

πŸ“ Dataset Structure

Recommended repository structure:

crop-recommendation-dataset/
β”‚
β”œβ”€β”€ Crop_recommendation.csv
β”œβ”€β”€ README.md
└── LICENSE

πŸ“‹ Data Schema

N              β†’ Numerical
P              β†’ Numerical
K              β†’ Numerical
temperature   β†’ Numerical
humidity      β†’ Numerical
ph            β†’ Numerical
rainfall      β†’ Numerical
label         β†’ Categorical

πŸ” Data Quality Considerations

Before using the dataset for research or production, users should verify:

  • Missing values
  • Duplicate records
  • Class balance
  • Feature distributions
  • Physically plausible values
  • Measurement units
  • Data provenance
  • Label consistency

Additional validation is recommended before deploying a model trained on this dataset in a real agricultural environment.


πŸ“œ License

Please refer to the repository's license file for the applicable terms of use.

If the original dataset was obtained from another source, users should also review and comply with the original dataset's license and attribution requirements.


πŸ™Œ Intended Audience

This dataset is suitable for:

  • Students
  • Machine learning practitioners
  • Data scientists
  • AI/ML researchers
  • Agricultural technology developers
  • Academic projects
  • Smart farming researchers
  • Developers building crop recommendation prototypes

⭐ Citation

If you use this dataset in a project, research work, publication, or application, please provide appropriate attribution to the original dataset source and follow its licensing requirements.


πŸ“Œ Disclaimer

This dataset is provided for research, educational, and machine learning development purposes.

Predictions generated from models trained on this dataset may not accurately represent real-world agricultural conditions. Users should validate predictions against local soil, climate, crop, and agricultural information before making real-world decisions.

Downloads last month
49