Choosing the right crop each season is one of the toughest calls a farmer has to make, largely because soil composition, rainfall, and local climate rarely behave predictably. Rather than leaning on field-specific, data-backed guidance, many farmers still fall back on regional tradition or broad advisory services, a habit that often leads to lower yields, wasted fertilizer, and real financial loss. This paper presents an AI-driven crop recommendation system that combines supervised machine learning with soil-climatic analytics to make crop selection more data-driven. The system takes seven measurable soil and environmental inputs, nitrogen (N), phosphorus (P), potassium (K), temperature, humidity, pH, and rainfall, and classifies the most suitable crop from a set of 22 candidate crops using a trained Random Forest classifier. Five classification algorithms, Decision Tree, Random Forest, Support Vector Machine, Naive Bayes, and Gradient Boosting, were trained and compared on a balanced dataset of 2,200 labeled samples (100 samples per crop). The Random Forest model achieved the best overall balance of accuracy and stability, reaching 99.55% test accuracy, a 99.43% out-of-bag score, and a five-fold cross-validation mean of 99.36% (± 0.39%). The system is implemented as a Flask-based web application with a trained-model backend, offering crop prediction, confidence scoring, and an integrated plant disease advisory module. Because the trained model is lightweight and does not depend on a constant internet connection once deployed, the system is well suited to rural and underserved farming communities, offering a practical, low-cost step toward precision agriculture.
Introduction
The proposed AI-based Crop Recommendation System aims to improve agricultural productivity by helping farmers select the most suitable crop based on measurable soil and climatic conditions. Traditional crop selection often relies on experience or generalized agricultural advice, which may not consider field-specific variations in soil nutrients and climate. To overcome these limitations, the system uses machine learning to analyze seven key parameters—nitrogen (N), phosphorus (P), potassium (K), temperature, humidity, soil pH, and rainfall—and recommends the most appropriate crop.
The system is trained using the Kaggle Crop Recommendation dataset, which contains 2,200 records covering 22 different crop types. It is implemented as a Flask-based web application and also includes a plant disease advisory module, making it a comprehensive decision-support tool for farmers.
The literature review shows that many researchers have successfully applied machine learning algorithms such as Random Forest, Decision Tree, Support Vector Machine (SVM), Naïve Bayes, XGBoost, Gradient Boosting, and K-Nearest Neighbors (KNN) for crop recommendation. Among these, Random Forest consistently achieves the highest accuracy and reliability. Previous studies have also explored fertilizer recommendation, IoT-based soil sensing, and plant disease detection. However, most existing systems focus on a single task and do not integrate crop recommendation with disease advisory or provide detailed model comparisons.
The study identifies the main problem as farmers relying on traditional practices, generalized advisory services, or informal guidance instead of data-driven recommendations. This often leads to poor crop selection, inefficient fertilizer usage, and reduced yields. The proposed system addresses this issue by offering personalized recommendations based on field-specific soil and climatic data.
The objectives of the study include:
Designing a parameter-based crop recommendation system.
Comparing five machine learning algorithms (Decision Tree, Random Forest, SVM, Naïve Bayes, and Gradient Boosting).
Using a standardized seven-feature input set.
Providing confidence-scored crop recommendations.
Developing a lightweight Flask web application.
Integrating a plant disease advisory module.
The methodology begins with collecting seven standardized input parameters obtained from soil testing kits, weather data, or IoT sensors. After data collection, preprocessing includes checking for missing values, feature scaling using StandardScaler, label encoding, and splitting the dataset into training and testing sets. The machine learning models are then trained and evaluated using multiple performance metrics.
The system computes a suitability confidence score based on prediction probability and classifies recommendations into:
High Confidence (0.90–1.00)
Moderate Confidence (0.70–0.89)
Low Confidence (0.50–0.69)
Not Recommended (<0.50)
The recommendation output provides:
The most suitable crop.
Suitability score.
Confidence level.
Practical suggestions, such as whether the crop is highly suitable or whether soil improvement is recommended.
The system architecture consists of several modules:
User Input Layer for entering soil and climate data.
Preprocessing Engine for data normalization.
Classification Module using the trained Random Forest model.
Suitability Scoring Engine for confidence estimation.
Recommendation and Report Generator to produce user-friendly recommendations.
Extended Advisory Layer, which includes plant disease detection, fertilizer guidance, and field analysis.
The deployed Random Forest Classifier serves as the core machine learning model because it effectively handles nonlinear relationships, minimizes overfitting through ensemble learning, provides feature importance analysis, and generates reliable prediction probabilities. The production model uses 500 decision trees, balanced class weighting, feature subsampling, and out-of-bag validation to ensure robust performance.
The system is trained on the publicly available Crop Recommendation dataset, which contains statistical information for the seven soil and climatic features and covers 22 crop categories. Since the model is lightweight and capable of offline operation, it is suitable for deployment in rural areas, agricultural extension centers, and mobile-based advisory platforms.
Conclusion
This paper presented a data-driven approach to crop recommendation built around machine learning classification of seven soil and climatic parameters. Five candidate algorithms, Decision Tree, Random Forest, Support Vector Machine, Naive Bayes, and Gradient Boosting, were trained and compared on a balanced, 2,200-record dataset spanning 22 crop classes, with Random Forest selected as the production model after reaching 99.55% test accuracy, a 99.43% out-of-bag score, and a stable 99.36% (± 0.39%) five-fold cross-validation mean. Rather than depending on generalized regional advisory or image-based diagnosis alone, the system offers field-specific, parameter-driven crop suitability classification, packaged into a lightweight Flask web application that also integrates a supplementary plant disease advisory module, fertilizer guidance, and field analysis features. Its modular architecture makes it practical across several domains, including agricultural extension centers, smallholder farming, and government outreach programs, and its lightweight, offline-capable deployment keeps it accessible even in resource-constrained rural settings.
References
This paper presented a data-driven approach to crop recommendation built around machine learning classification of seven soil and climatic parameters. Five candidate algorithms, Decision Tree, Random Forest, Support Vector Machine, Naive Bayes, and Gradient Boosting, were trained and compared on a balanced, 2,200-record dataset spanning 22 crop classes, with Random Forest selected as the production model after reaching 99.55% test accuracy, a 99.43% out-of-bag score, and a stable 99.36% (± 0.39%) five-fold cross-validation mean. Rather than depending on generalized regional advisory or image-based diagnosis alone, the system offers field-specific, parameter-driven crop suitability classification, packaged into a lightweight Flask web application that also integrates a supplementary plant disease advisory module, fertilizer guidance, and field analysis features. Its modular architecture makes it practical across several domains, including agricultural extension centers, smallholder farming, and government outreach programs, and its lightweight, offline-capable deployment keeps it accessible even in resource-constrained rural settings.