Crop Recommendation System Using Machine Learning: LIBANYA GIFTY T (950720112052)
Crop Recommendation System Using Machine Learning: LIBANYA GIFTY T (950720112052)
MACHINE LEARNING
A PROJECT REPORT
Submitted by
BACHELOR OF TECHNOLOGY
in
INFORMATION TECHNOLOGY
APRIL 2025
FRANCIS XAVIER ENGINERING COLLEGE (Autonomous)
TIRUNELVELI 627 003
BONAFIDE CERTIFICATE
MRS. M. VINOTHINI, M.E., Dr. M. CAROLINE VIOLA STELLA MARY, M.E., Ph.D.,
Tirunelveli. Tirunelveli.
Submitted for the B. Tech MINOR Degree Project Viva Voce held on ………………………………
ii
ACKNOWLEDGEMENT
iii
Abstract
Agriculture plays a crucial role in food security and economic growth, making
assist farmers in identifying the most suitable crops based on soil characteristics
using a scaling technique, and predicts the optimal crop using a pre-trained model.
for users to input their data and receive recommendations. By utilizing historical
utilization and reducing reliance on trial-and-error methods. The system has the
potential to minimize input costs and maximize crop yield, directly contributing
recommending crops that suit existing soil and climatic conditions. By using
historical data, predictive models, and a user-friendly web interface, the system
agriculture, such AI-based solutions will play a crucial role in creating a more
iv
TABLE OF CONTENTS
CHAPTER PAGE
TITLE
NO NO
ACKNOWLEDGEMENT iii
ABSTRACT iv
LIST OF FIGURES viii
LIST OF ABBREVIATIONS ix
1. INTRODUCTION
1.1 General Introduction 10
1.2 Project Objective 11
1.3 Project Goal 12
1.4 Project Scope 13
1.5 Project Purpose 13
2. LITERATURE REVIEW
2.1 Introduction 15
2.2 Literature Review 16
2.3 Summary 20
3. EXISTING SYSTEM
3.1 Introduction to Existing Crop Recommendation Systems 22
3.1.1 Evolution of Crop Recommendation Technologies 22
3.1.2 Importance of Crop Recommendation Systems 23
3.1.3 Features of Existing Systems 23
3.1.4 Accessibility and Platform Integration 23
3.1.5 Integration and Usability 24
3.2 Analysis of Existing Methodology 24
3.2.1 Data Collection Methods 24
3.2.2 Data Processing and Analysis 25
3.2.3 User Interaction and Experience 25
3.3 Case Studies or Examples 25
v
3.3.1 Random Forest-Based Crop Recommender 25
3.3.2 KNN-Based Localized Crop Predictor 26
3.4. Challenges Faced by Existing Systems 26
3.4.1 Data quality and completeness 26
3.4.2 Computational Constraints 26
3.4.3 Usability and Accessibility 27
3.4.4 Generalization and Model Adaptability 27
4. PROPOSED SYSTEM
4.1 Introduction 28
4.2 Motivation 29
4.3 Objectives and Goals 30
4.4 System Architecture 32
vi
5.4 Performance in Different Environments 52
vii
LIST OF FIGURES
FIGURE PAGE NO
NO TITLE
1 System Architecture 27
3 Flow Chart 32
5 Recommended crops 44
viii
LIST OF ABBREVIATIONS
ACRONYM ABBREVIATION
ML Machine Learning
RF Random Forest
UI User Interface
ix
CHAPTER 1
INTRODUCTION
1.1 INTRODUCTION
10
This report documents a detailed overview of the project, including the
approaches used, technologies and tools employed, and issues faced during
development. It also reflects on the use of machine learning for interpreting
agricultural data to deliver useful recommendations, highlighting the role of AI-
based decision-making in contemporary farming practices.
The goal of this project is to develop and design an intelligent, automated crop
recommender system based on machine learning methods. The system should help
farmers and stakeholders in agriculture by predicting the best crop to be grown
accurately from different environmental and soil parameters like Nitrogen (N),
Phosphorus (P), Potassium (K) levels, temperature, humidity, pH of the soil, and
rainfall. This method greatly minimizes guesswork and improves agricultural
decision-making, leading to greater productivity and optimization of resources.
11
1.3 PROJECT GOAL
One of the primary goals is to provide high prediction accuracy and efficient
inference, supporting real-time recommendations even in low-resource settings. The
machine learning model will be trained on varied agricultural datasets, enabling it to
learn intricate relationships between weather and soil attributes and crop suitability.
This flexibility guarantees consistent performance across various geographic
locations and seasonal changes.
12
1.4 PROJECT SCOPE
Its modular and scalable design guarantees the system can be scaled or
configured for varying regions, crop types, or other parameters. Altogether, this
project facilitates smart and sustainable agriculture through decreased guesswork,
optimized resource allocation, and enhanced crop yield utilizing sophisticated
machine learning and data science.
The main aim of the Crop Recommendation System via Machine Learning is
to create a smart, effective, and self-sustained system for recommending the most
appropriate crops under certain environmental and soil conditions. Crop choice is a
13
key decision in agriculture that has direct implications on yield, sustainability, and
resource utilization.
The system accepts input parameters like Nitrogen (N), Phosphorus (P),
Potassium (K), temperature, humidity, pH level, and rainfall. The inputs are given
to a machine learning model trained on the inputs, which inspects patterns and
suggests the best crop to cultivate. The outputs are given in a formatted way,
providing both the suggested crop and the data to support it so that the users can
know why the suggestion is made.
The project illustrates the use of Python for model building, Scikit-learn for
applying machine learning algorithms, and data visualization libraries to improve
interpretability. By making the crop recommendation system automated, the system
enables precision farming, enabling farmers to take well-informed decisions,
minimize the risk of crop failure, and increase productivity in general.
14
CHAPTER 2
LITERATURE SURVEY
2.1 INTRODUCTION
With the rise of data analytics and AI, machine learning models now allow
for the integration of multi-dimensional data such as temperature, rainfall, humidity,
and soil pH to make accurate and scalable predictions.
16
scalability and adaptability of their system, suggesting that with the integration of
real-time sensor data and mobile platforms, such AI-based tools could be deployed
widely, even in remote or resource-limited areas. This research underscores the
potential of machine learning not only to enhance crop productivity but also to
empower farmers with timely, location-specific recommendations for sustainable
agriculture.
17
Patel, V., & Bhavsar, P. – Cloud-Based Crop Advisory Using Machine Learning
(2021)
Singh, R., & Das, A. – Role of Feature Selection in Crop Prediction Accuracy
(2022)
Singh and Das analysed the impact of different feature selection techniques
on the performance of crop recommendation systems. Techniques such as
Recursive Feature Elimination (RFE) and Principal Component Analysis (PCA)
were applied to refine datasets. Their study found that proper feature engineering
significantly improved model performance, especially in algorithms like SVM and
Boost. By reducing irrelevant features, they managed to enhance both speed and
accuracy, showing that intelligent feature selection is crucial in real-time
deployment of recommendation system
Fernandez, M., & Rao, S. – Integration of GIS and Machine Learning in Crop
Suitability for the Mapping and analysing system in the analysis (2022)
18
as land slope, elevation, and soil type were processed using Decision Tree classifiers
to generate crop-specific zoning maps. This visual representation provided intuitive
and localized decision support for farmers and policymakers. The study proposed its
integration into national e-governance platforms to enhance precision agriculture at
the policy level.
Zhang, L., & Prakash, R. – Real-Time Crop Forecasting Using LSTM Models
(2023)
This study introduced the use of Long Short-Term Memory (LSTM) networks
for crop yield forecasting and recommendation based on weather time-series data.
Unlike traditional models that rely on static input, LSTM networks capture temporal
dependencies, making them effective in forecasting future conditions. The system
was tested across three agricultural zones and showed consistent results in adapting
to climate variability. This research demonstrated the potential of deep learning
models in long-term agricultural planning.
The authors developed a mobile application that uses built-in GPS and
climate APIs to fetch location-based weather conditions in real time. Coupled with
a lightweight ML model trained on regional datasets, the app provides crop
recommendations instantly based on both real-time and historical data. Field trials
indicated that the mobile-based system was effective in reaching underserved
farmers, especially those without access to desktop computing or consistent internet.
19
Ali, M., & Zhou, X. – Integrating Remote Sensing and ML for Agricultural
Planning (2023)
Joshi, A., & Nair, V. – Smart Farming Using IoT and ML (2022)
Combining IoT-based sensors with machine learning, this research developed
a dynamic crop recommendation system that adapts to real-time changes in soil
moisture and weather. The system utilizes cloud computing to store and process large
volumes of sensor data and updates crop recommendations accordingly. The project
demonstrated how real-time feedback could significantly reduce water and fertilizer
waste.
2.3 SUMMARY
20
crop calendars but lacked the adaptability and precision required for optimal yield
outcomes.
21
CHAPTER 3
EXISTING SYSTEM
3.1. INTRODUCTION
23
Additionally, cloud computing and IoT integration allow for scalable and real-time
crop recommendations across diverse regions.
3.1.5 INTEGRATION AND USABILITY
Modern systems are designed to be modular and flexible, enabling
integration with soil testing devices, remote sensing platforms, and government
databases. A well-designed user interface ensures ease of use, even for farmers with
minimal technical knowledge. Systems often include language support, mobile
compatibility, and options for downloading reports or sharing recommendations
with agricultural advisors.
24
3.2.2 DATA PROCESSING AND ANALYSIS
Collected data undergoes several preprocessing steps:
• Data Cleaning and Normalization: Ensures uniform data for accurate model
performance.
• Feature Selection: Algorithms like Recursive Feature Elimination (RFE) are
used to identify the most impactful input features.
• Model Training: Algorithms such as Random Forest, SVM, and Logistic
Regression are trained using labelled datasets.
• Model Evaluation: Accuracy, F1-score, precision, and recall metrics help
assess the effectiveness of the model before deployment.
3.2.3 USER INTERFACE AND EXPERIENCE
Usability is a core concern in existing systems. Key elements include:
• Simple Form Inputs: Soil and weather parameters are entered through
intuitive forms.
• Recommendation Output: Suggested crops are displayed with their
suitability score or rank.
• Visualization: Graphs and charts show trends, nutrient levels, and expected
yield potential.
• Localization: Support for regional languages and units (e.g., Celsius vs.
Fahrenheit) ensures wider adoption.
25
to handle nonlinear relationships between input features. These models show high
accuracy in suggesting crops like rice, wheat, maize, or pulses depending on
nutrient composition and weather patterns. Their ensemble nature also helps reduce
the risk of overfitting.
3.3.2 KNN-BASED LOCALIZED CROP PREDICTOR
K-Nearest Neighbours is favoured for systems that require quick adaptation
to local data. By comparing new inputs with nearby data points in the feature space,
KNN provides recommendations that align closely with localized farming
conditions. This method is especially effective when the dataset covers a specific
region or crop cycle.
26
3.4.3 USABILITY AND ACCESSIBILITY
• Digital Divide: Limited access to smartphones, internet connectivity, or
digital literacy in rural areas restricts system usage.
• Language and Interface Barriers: Lack of regional language support or
complex interfaces reduces farmer engagement.
3.4.4 GENERALIZATION AND MODEL ADAPTABILITY
• Lack of Transfer Learning Capabilities: Many models are trained from
scratch for specific tasks, which limits their ability to generalize knowledge
across different regions or crop types without extensive retraining.
• Insufficient Representation of Diverse Agro-Climatic Zones: Training
datasets may lack diversity in terms of soil types, climate conditions, and
farming practices, leading to poor model performance in underrepresented
regions.
• Dependency on Historical Data Patterns: Models heavily reliant on historical
trends may fail to adapt to sudden changes in climate, pest outbreaks, or
evolving agricultural practices.
• Static Feature Sets: Use of fixed input features can restrict adaptability to
emerging agronomic parameters, such as new soil health indicators or
modern farming technologies.
• Neglect of Socio-Economic Factors: Models often overlook socio-economic
constraints like landholding size, access to resources, and farmer
preferences, which are crucial for generalization and real-world applicability.
27
CHAPTER 4
PROPOSED SYSTEM
4.1 INTRODUCTION
With the rise of machine learning (ML) and data analytics, crop
recommendation systems have evolved to become intelligent, data-driven tools that
analyze complex agricultural parameters to provide accurate and timely suggestions.
28
4.2MOTIVATION
The motivation for this project stems from the pressing need to improve crop
planning and farm productivity in the face of climate uncertainty, declining soil
fertility, and resource limitations. Traditional crop selection methods lack the
precision and adaptability needed for today’s farming challenges. Farmers often
experience low yields due to incorrect crop choices, inefficient fertilizer usage, or
unanticipated weather conditions. Additionally, rural farmers may not have access
to expert agronomic advice, leaving them vulnerable to poor planning and financial
losses.
This system aims to bridge the knowledge gap by providing intelligent, accessible,
and real-time recommendations that empower farmers with science-backed
decisions.
29
4.3 OBJECTIVES AND GOALS
• Achieve high accuracy and reliability across different soil types and regional
climates.
• Reduce the risk of crop failure through predictive analytics and optimized
decision support.
• Design the system to handle large agricultural datasets and adapt to additional
features like crop pricing or pest alerts.
30
• Ensure compatibility with local, regional, and global datasets to expand
usability.
• Incorporate real-time sensor data and API integrations for dynamic decision-
making.
• Train and validate models using algorithms like Random Forest, K-Nearest
Neighbors (KNN), and Support Vector Machines (SVM).
31
• Explore satellite and IoT data sources for real-time environmental input.
• Offer downloadable reports or summaries that farmers can share with local
agricultural officers or cooperatives for collaborative planning.
32
friendly interaction. It starts with the data acquisition layer, which collects real-time
and historical data such as soil type, pH, moisture, weather conditions (temperature,
rainfall, humidity), and crop history.
33
Data Acquisition Module
The preprocessing engine handles cleaning and formatting of the input data
before it is passed to the model. Functions include:
This module contains the trained machine learning model (e.g., Random
Forest or XGBoost). It takes the pre-processed data and uses the model to predict
the most suitable crop for cultivation. The model is trained on historical crop yield
data and environmental conditions to ensure accuracy and adaptability to changing
patterns.
34
Recommendation Engine
The engine interprets the output of the machine learning model and converts
it into meaningful insights. It provides the final recommended crop along with
confidence scores. Additional features include:
• Optional chart or dashboard integration (e.g., Power BI) for deeper analytics
• The machine learning model analyzes the processed input and predicts the most
suitable crop.
• The recommended crop is displayed on the screen with visual highlights and
supporting information.
• The voice module announces the crop recommendation for improved accessibility.
• The system may also log the inputs and outputs for future reference or training data
expansion.
Output Generation
• If enabled, the TTS engine announces the count for accessibility purposes.
36
4.4.4 VISUAL REPRESENTATION
The Visual Representation section illustrates how different modules within the
Crop Recommendation System interact to generate results. It provides insights into
the overall system workflow using visual aids.
• User Input: The user enters essential agricultural data such as Nitrogen,
Phosphorus, Potassium, temperature, humidity, pH, and rainfall.
37
• Data Preprocessing: The entered data is normalized, cleaned, and checked
for validity.
• Model Prediction: The pre-processed data is fed into the trained ML model
(e.g., Random Forest), which predicts the best crop for cultivation.
• Recommendation Engine: The result is interpreted and formatted for user
display.
• Output Generation: The recommended crop is shown on the interface and
optionally announced via voice.
• UI Display: A clean interface shows input fields, predictions, and optional
charts/visuals.
Interaction Flow Chart
38
4.5 IMPLEMENTATION DETAILS
Programming Language
39
based on soil characteristics, environmental conditions, and weather data. These
models are trained on datasets containing features like nitrogen (N), phosphorus (P),
potassium (K) levels, pH, rainfall, and temperature.
These libraries are used extensively for data manipulation and numerical
operations. Pandas is employed to manage and clean agricultural datasets, while
NumPy powers mathematical operations and array handling for faster computations
during model training
The system dynamically suggests crops based on live weather and soil data,
offering timely advice to farmers through a web or mobile interface.
40
Adaptive Learning Mechanism
To increase accessibility for farmers, the system supports voice output in local
languages using text-to-speech engines, and provides a multilingual UI.
The system uses both open-source agricultural datasets (e.g., Krishi Vigyan Kendra,
ICAR) and custom field-level data. Data preprocessing includes:
41
• Encoding categorical data (like soil type or region)
Multiple models are trained and evaluated. The best-performing model (e.g.,
Random Forest or Boost) is chosen using:
• Cross-validation
System Integration
The final system is tested in rural settings or agricultural test beds, evaluating
the recommendation accuracy, usability, and real-time performance on mobile
devices.
42
4.5.4 CHALLENGES FACED DURING DEVELOPMENT
Designing a model that maintains high accuracy while being explainable and
interpretable for farmers posed a challenge. Simpler models were chosen over
complex ones like deep learning to maintain transparency.
Running the model on low-end devices and in areas with limited connectivity was
challenging. This was addressed by optimizing the model with TensorFlow Lite and
enabling offline-first functionality.
Some crops share similar growing conditions but differ in seasons. A seasonal
filter was added to the recommendation engine to improve contextual relevance.
43
4.6 TESTING AND EVALUATION
The primary objective was to verify whether the system could accurately
recommend crops across different soil types, weather patterns, and geographic
zones. Testing was also conducted under variable data quality conditions to assess
model generalization.
Unit Testing
Integration Testing
Integration tests were carried out to validate the seamless interaction between
the data ingestion pipeline, machine learning models, and user interface. Challenges
such as syncing real-time weather data with crop prediction outputs were observed,
44
particularly during network delays. These issues are currently being mitigated
through data caching and asynchronous API requests.
We evaluated the system based on the following criteria, taking into account
both the system was evaluated based on the following key criteria, which were
designed to assess its real-world performance and user impact:
• The system demonstrated high accuracy when predicting suitable crops for
standard soil and climate conditions using models like Random Forest and
XGBoost.
• However, some mismatches were observed in cases involving rare crops or
incomplete environmental data inputs.
45
• Occasional latency occurred when retrieving live weather data or working
with larger datasets, which is being addressed through performance tuning and
model optimization.
• Feedback from user testing highlighted the intuitive nature of the interface and
the usefulness of the crop ranking display.
• Suggestions were made to improve visual clarity, provide multilingual
support, and simplify data input for farmers unfamiliar with digital platforms.
The evaluation process uncovered both successful outcomes and areas where the
system could be improved:
Successes:
46
• Enhancements are needed to further streamline performance on low-end
devices and under limited internet connectivity conditions
Support for multilingual and audio-based UI: Expand access to semi-literate and
non-English speaking users by integrating voice instructions and local language
translations.
47
CHAPTER 5
5.1 INTRODUCTION
Overview
Observations
48
• The system performs well across a variety of input conditions, accurately
suggesting crops such as rice, maize, cotton, or pulses based on soil and
weather features.
49
"Get Recommendation" button, the model processes the data and suggests an
appropriate crop, helping farmers make informed decisions for better yield.
The image shows the output interface of the Crop Recommendation System
after the user has entered agricultural inputs and clicked the "Get Recommendation"
button. Based on the values provided for Nitrogen, Phosphorus, Potassium,
Temperature, Humidity, pH, and Rainfall, the system processes the data using a
machine learning model and displays the recommended crop. In this case, the model
suggests that Papaya is the best crop to be cultivated, helping farmers or users make
data-driven decisions for optimal crop selection.
50
Figure 5.3: Power BI Average Dashboard
Overview
51
Observations
• The prediction process is efficient and quick, usually generating results within
less than 2 seconds.
• The system always suggests suitable crops such as rice, maize, sugarcane, and
cotton for their respective optimal conditions.
Overview
The Crop Recommendation System was validated with datasets that reflect
various climatic zones, soil types, and seasons to test its flexibility and accuracy
under various agricultural conditions. The performance of the system was
determined in terms of prediction accuracy, consistency, and responsiveness to
changing input parameters.
Observations
• The system works best with full and clean data inputs, especially for weather
conditions and soil nutrients.
• In climatically fluctuating regions or soils with inconsistent profiles, the
system might need tuning to give the best recommendations.
• The model generalizes relatively well to all major crop-producing regions but
can show slightly less precise predictions in regions that are not properly
represented in the training data.
52
CHAPTER 6
6.1 CONCLUSION
54
CHAPTER 6
APPENDIX
7.1 APPENDIX 1
PROGRAM CODE
import numpy as np
import pickle
import requests
import json
POWER_BI_URL = "https://api.powerbi.com/beta/6c94e077-929a-46b2-a642-
8763ee68726c/datasets/a00c252c-b5b7-480b-9ef4-
dc188008a41a/rows?experience=power-
bi&key=TRBH34E5UXsFWoo3oQMANIxRDwWrXmHTv8ZMUk%2BNGdBZq
bfuH%2BEGnEGE7739lmh6zHbFi1M9mXzpa92rlBt1HA%3D%3D"
55
crop_dict = {
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
@app.route("/predict", methods=['POST'])
def predict():
try:
N = float(request.form['Nitrogen'])
P = float(request.form['Phosporus'])
K = float(request.form['Potassium'])
56
temp = float(request.form['Temperature'])
humidity = float(request.form['Humidity'])
ph = float(request.form['pH'])
rainfall = float(request.form['Rainfall'])
scaled_features = scaler.transform(single_pred)
prediction = model.predict(scaled_features)
# Prepare result
data = [{
"Nitrogen": N,
"Phosphorus": P,
57
"Potassium": K,
"Temperature": temp,
"Humidity": humidity,
"pH": ph,
"Rainfall": rainfall,
"Predicted_Crop": recommended_crop
}]
if response.status_code == 200:
else:
except Exception as e:
if __name__ == "__main__":
app.run(debug=True)
58
7.2 APPENDIX II – SCREENSHOTS
59
Figure 7.3: Recommended crops
60
REFERENCES
[1]. Bhagat, P., & Balpande, M., “A comparative study of crop prediction
models using machine learning,” International Journal of Advanced
Research in Computer Science, vol. 9, no. 3, pp. 586–590, 2018.
[2]. Bhattacharya, S., & Samanta, S., “A novel machine learning model
for crop prediction based on climatic parameters,” International Journal
of Innovative Research in Science, Engineering and Technology, vol. 8,
no. 9, pp. 9353–9360, 2019.
[3]. Bendre, M., & Thool, R., “Big data in precision agriculture: Weather
forecasting for future farming,” Procedia Computer Science, vol. 110,
pp. 402–409, 2017.
[4]. Chavan, V., & Bichkar, R. S., “Soil classification and crop suggestion
using machine learning,” International Journal of Engineering Research
& Technology (IJERT), vol. 8, no. 8, 2019.
[5]. Hossain, M. A., & Ghosh, S., “IoT-based smart farming: A machine
learning approach,” International Journal of Advanced Computer
Science and Applications, vol. 10, no. 3, pp. 434–442, 2019.
[6]. Jain, A., & Singh, A., “Crop yield prediction using machine learning,”
International Journal of Scientific Research in Computer Science, vol.
7, no. 6, pp. 42–47, 2019.
[7]. Khaire, S., & Patil, A., “Machine learning based crop recommendation
system,” in Proc. Int. Conf. Intelligent Computing and Control Systems
(ICICCS), 2020, pp. 1236–1240, doi:
10.1109/ICICCS48265.2020.9121210.
[8]. Kumar, R., & Kumari, P., “Crop prediction model using machine
learning approach,” International Journal of Engineering
Development and Research, vol. 7, no. 4, 2019.
61
[9]. Lempitsky, V., & Zisserman, A., “Learning to count objects in
images,” in Proc. Adv. Neural Inf. Process. Syst. (NeurIPS), 2010, pp.
1324–1332.
[10]. Naik, P., & Patel, D., “Crop recommendation system using decision
tree and random forest,” International Journal of Computer Sciences
and Engineering, vol. 6, no. 10, pp. 243–247, 2018.
[11]. Patil, S. T., et al., “A machine learning approach for smart agriculture,”
in Proc. IEEE Int. Conf. Advances in Computing, Communication and
Control, 2019, pp. 1–5.
[12]. Ramesh, A., & Suruliandi, A., “Soil fertility prediction using machine
learning algorithms: A review,” ICTACT Journal on Soft Computing,
vol. 7, no. 3, pp. 1459–1464, 2017.
[13]. Rani, R., & Tripathi, R., “Prediction of suitable crops using machine
learning,” Journal of Emerging Technologies and Innovative
Research, vol. 6, no. 5, pp. 142–147, 2019.
[14]. Sharma, A., Singh, V., & Shukla, A., “Crop recommendation system
10.5120/ijca2018917201.
62