Professional Documents
Culture Documents
Crop Yield
Crop Yield
Crop Yield
Crop yield prediction plays a pivotal role in agriculture, aiding farmers, policymakers, and
stakeholders in decision-making processes related to crop planning, resource allocation, and
food security. Traditional methods of yield estimation often rely on historical data, agronomic
knowledge, and manual observation, which can be time-consuming and prone to inaccuracies.
In recent years, machine learning (ML) techniques have emerged as powerful tools for
predicting crop yields with greater accuracy and efficiency. This paper presents a
comprehensive review of machine learning-based crop yield prediction methodologies,
focusing on recent advancements, challenges, and future directions. The review encompasses
various aspects of crop yield prediction, including data sources, feature selection, model
selection, and evaluation metrics.
TABLE OF CONTENTS
1 ABSTRACT 2
Chapter 1 : INTRODUCTION
2 1.1 Background
1.2 Overview
1.3 Scope
Chapter 7 : RESULTS
8
7.1 Snapshots
10 Chapter 9 : CONCLUSION
11 Chapter 10 : REFERENCES
LIST OF FIGURES
Figure 1 Flowchart -
Figure 4 Methodology
In recent years, agriculture has witnessed a significant transformation with the integration of
advanced technologies like machine learning. One of the key areas where machine learning
algorithms have made a profound impact is in crop yield prediction. Crop yield prediction using
machine learning techniques offers farmers and agricultural stakeholders valuable insights into
potential harvests, enabling them to make informed decisions regarding crop management,
resource allocation, and market strategies.
Traditional methods of crop yield estimation often relied on historical data, manual
observations, and subjective assessments. However, these methods are limited in accuracy and
scalability, particularly in the face of dynamic environmental factors and changing climate
patterns. Machine learning algorithms, on the other hand, have the capability to analyse vast
amounts of data, including environmental variables, soil characteristics, crop genetics, and
agronomic practices, to generate predictive models with greater precision and reliability.
The process of crop yield prediction using machine learning typically involves several stages.
Firstly, relevant data is collected from various sources such as satellite imagery, weather
stations, soil sensors, and historical records. This data is then pre processed and transformed to
extract meaningful features that can influence crop growth and productivity. Next, machine
learning models are trained using supervised learning techniques, where past observations of
crop yields are used to teach the algorithm to recognize patterns and relationships between
input variables and output yields. Various algorithms such as decision trees, random forests,
support vector machines, and neural networks can be employed depending on the complexity
of the problem and the nature of the data.
Once trained, the machine learning models can be deployed to predict crop yields for future
seasons based on real-time or forecasted environmental conditions. These predictions empower
farmers with valuable insights into crop performance, allowing them to optimize resource
utilization, implement precision agriculture practices, and mitigate risks associated with factors
like drought, pests, and diseases. Moreover, accurate yield forecasts facilitate better planning
and decision-making across the agricultural value chain, from seed manufacturers and input
suppliers to commodity traders and policymakers.
crop yield prediction using machine learning represents a powerful tool for enhancing
agricultural productivity, sustainability, and resilience in the face of evolving challenges. By
harnessing the capabilities of machine learning algorithms, farmers can make data-driven
decisions to maximize yields, minimize losses, and contribute to global food security. As
technology continues to advance, the integration of machine learning into agriculture holds
immense promise for transforming the way we grow, manage, and harvest crops in the future.
1.1 Background
Agriculture is the backbone of any country, and it has become the most significant growing
sector all over the world because of increasing the population. About 60% of our country's
population works in agriculture which contributes more to our country's GDP and employment.
The main challenge in the agriculture industry is to improve farming efficiency and quality to
fulfil the speedily increasing demand for food. Apart from the mounting population, the climate
circumstance is also a huge challenge in the agricultural industry. In our project, we will make
use of ML algorithms to assist farmers to know future crop yield predictions and favourable
weather predictions.
1.2 Overview
Basic Concepts
An Crop yield predictor is an online platform that provides access to a variety of resources and
services to farmers and other stakeholders in the agriculture industry. The main objective of
such a portal is to help farmers improve their crop production and profitability by providing
them with information, tools, and services that can help them make informed decisions and
adopt best practices. Some of the basic concepts that are central to an Crop yield predictor for
better crop production include:
Weather data: Farmers must be able to plan their planting and harvesting schedules in
accordance with the weather as it is so important to agriculture. Agricultural portals give
farmers access to weather alerts and forecasts, which can aid them in making decisions
regarding pest control, irrigation, and other tasks. exemplary practices.
Best Practices: Farmers must stay current on the most recent best practices and procedures
because agriculture is a complicated and ever-evolving industry. It gives farmers access to a
variety of tools and materials that can assist them advance their agricultural methods.
1.3 Scope
One aspect of the project scope is data collection and pre processing. This involves gathering
historical data on weather conditions, soil characteristics, crop types, and previous yield
records. Data pre processing techniques such as cleaning, normalization, and feature
engineering are applied to ensure data quality and relevance for model training.
The next phase involves model development and evaluation. Machine learning algorithms such
as regression, decision trees, or neural networks are trained on the pre processed data to learn
the relationships between various factors and crop yields. These models are then evaluated
using metrics like mean absolute error or root mean square error to assess their accuracy and
reliability.
Furthermore, the project encompasses the deployment of the developed models into operational
systems. This involves integrating the models with agricultural management software or
decision support systems used by farmers or agricultural organizations. Real-time data streams
may be incorporated to continuously update and improve the predictive capabilities of the
models.
Finally, the project involves continuous monitoring and refinement. As new data becomes
available and agricultural practices evolve, the models need to be updated and fine-tuned
accordingly. Monitoring performance metrics and gathering feedback from end-users helps in
iteratively improving the accuracy and usability of the crop yield prediction system, ensuring
its effectiveness in supporting agricultural decision-making processes.
LITERATURE REVIEW
[1] According to analysis, the most used features are temperature, rainfall, and soil type, and
the most applied algorithm is Artificial Neural Networks in these models. The author used
parameters like State, district, season, and area. The user can predict the yield of the crop in
which year the user wants. The paper uses advanced regression techniques like Kernel Ridge,
and Lasso to predict the yield and uses the concept of Stacking Regression for enhancing the
algorithms to give a better prediction.
[2] In this paper, the author says, yield prediction was performed by considering farmers’
experience on a particular field and crop. Different Data Mining techniques are used and
evaluated in agriculture for estimating the future year’s crop production. This is achieved by
applying association rule mining on agriculture data. This research focuses on the creation of
a prediction model which may be used for future prediction of crop yield. This paper presents
a brief analysis of crop yield prediction using a data mining technique based on association
rules for the selected region.
[3] The author describes how the old farming data can be utilized to depict the future
expectation of harvests and yield. It likewise proposes to the ranchers what kind of yield can
be developed utilizing the climate station data and gives the appropriate data to incline toward
the precise season for cultivating. The curse on the harvest yield is broken down by utilizing
different ecological elements and Regression Analysis (RA), Linear Regression (LR)
Algorithms utilizing the various data mining strategies how to improve harvest production.
[4] This paper uses machine learning algorithms, direct relapse demonstrated from insights,
and two enhancement techniques, the Normal condition strategy, and the Gradient plunge
technique to anticipate the weather based on a couple of parameters. This work utilizes the
ordinary condition model’s speculation and contrasts it and the angle plunge model to give a
superior thought of the productivity of the models. This paper is about the use of machine
learning crop yield predictor for Better Crop Production ML algorithms, direct relapse
demonstrates from inside, and two enhancement techniques.
[5] We describe an approach to yield modelling that uses a semiparametric variant of a deep
neural network, which can simultaneously account for complex nonlinear relationships in high
dimensional datasets, as well as the known parametric structure and unobserved cross-sectional
heterogeneity. We show that this approach outperforms both classical statistical methods and
fully nonparametric neural networks in predicting the yields of years withheld during model
training. Our approach is less pessimistic in the warmest regions and the warmest scenarios.
[6] This paper predicts the yield of almost all kinds of crops that are planted in India. This script
makes novel by the usage of simple parameters like State, district, season, area and the user
can predict the yield of the crop in which year he or she wants to. The paper uses advanced
regression techniques like Kernel Ridge, Lasso, and Enet algorithms to predict the yield and
uses the concept of Stacking Regression for enhancing the algorithms to give a better
prediction.
[7] In this paper, we can predict the things like rainy, windy, sunny, stormy, floods and
variations in temperature, etc. Nowadays, the weather is making a bad impact, as society is
growing more and more, causing much damage, injury, and loss of life for farmers. Weather
forecasting is very important for agriculture and terrace gardening. Weather forecasting will
help remote areas for better crop production .In this paper, a low-cost solution for weather
forecast prediction is discussed.
[8] This paper uses algorithms such as Random Forest, Support Vector Machine, Weather, and
K Nearest neighbour, which are used for better performance results for each selected weather
parameter. We also use soil and weather parameters such as soil type, soil fertility, maximum
temperature, minimum temperature, and rainfall are used to identify suitable crops for specified
farms or land. Ethiopia consolidates both remotely detected information (RSD) and agrarian
overview information for a considerable beneficiary of specially appointed imported
nourishment help.
REQUIREMENT SPECIFICATION
➢ Under the prediction option, crop prediction will predict the crop to be grown, yield
prediction will predict the yield of the crop, and rainfall prediction will predict the rainfall
for that area in milli meters
The interface should be user-friendly. The application environment should be easy to use. It
should be adaptable to all kinds of platforms.
The system should behave consistently in a user-acceptable manner when operating within the
environment for which the system is intended.
3.3 SOFTWARE REQUIREMENT
● Browser: Chrome.
● Other software’s:
● Frontend:
❖ HTML5
❖ CSS3
❖ JavaScript.
● Backend:
❖ Python ,
❖ Apache,
❖ Php.
FRONTEND:
PHP:
➢ PHP is renowned for its simplicity and ease of use, making it accessible to both
beginners and experienced developers alike. Its syntax is similar to C, Java, and Perl,
making it familiar to programmers from various backgrounds.
2. Server-Side Scripting
3. Cross-Platform Compatibility
➢ PHP boasts a vast ecosystem of libraries and frameworks that streamline development
and enhance functionality. Popular frameworks such as Laravel, Symfony, and
CodeIgniter provide robust solutions for building scalable and maintainable web
applications.
5. Database Integration
6. Rapid Development
➢ With its dynamic typing, automatic memory management, and built-in functions for
common tasks, PHP enables rapid prototyping and development of web applications.
Its interpreted nature eliminates the need for compilation, allowing developers to iterate
quickly and efficiently.
1. Web Development
➢ PHP is widely used for building dynamic websites, e-commerce platforms, content
management systems (CMS), and web applications. Its ability to generate HTML,
interact with databases, and handle user authentication makes it indispensable for web
developers.
2. Server-Side Scripting
➢ PHP excels in server-side scripting tasks such as form processing, file handling, and
session management. It can process user input, generate customized responses, and
maintain stateful interactions between clients and servers.
Beyond web development, PHP is also utilized for command-line scripting tasks such as
automation, data processing, and system administration. Its command-line interface (CLI)
allows developers to execute scripts directly from the terminal, making it a versatile tool for
various scripting tasks
Backend:
PYTHON:
PYTHON'S CHARACTERISTICS
Python's syntax is known for its readability and simplicity. Its use of indentation and
whitespace as block delimiters enforces clean, well-structured code. This design choice
makes Python an excellent language for beginners and seasoned developers alike.
2. Cross-Platform Compatibility
Python is cross-platform, meaning it can run on various operating systems like Windows,
macOS, and Linux without significant modification. This feature simplifies development
and deployment.
Python comes with an extensive standard library that provides modules and functions for a
wide range of tasks. These libraries offer solutions for file handling, networking, regular
expressions, and more, reducing the need for developers to reinvent the wheel.
4. Open Source and Community-Driven
Python is an open-source language, which means it is freely available for anyone to use,
modify, and distribute. This open nature has fostered a vibrant and supportive community
of Python developers who contribute to its growth and development.
5. Dynamically Typed
Python is a dynamically typed language, which means you don't need to specify variable
types explicitly. This feature enhances developer productivity and code flexibility.
3.6 LIBRARIES:
• Visual Studio Code is a code editor in layman’s terms. Visual Studio Code is “a freeeditor
that helps the programmer write code, helps in debugging and corrects the code using the
intelli-sense method”. In normal terms, it facilitates users to write the code in an easy
manner. Many people say that it is half of an IDE and an editor, but the decision is up to to
the coders. Any program/software that we see or use works on the code that runs in the
background. Traditionally coding was used to do in the traditional editors or even in the
basic editors like notepad! These editors used to provide basic support to the coders.
• Some of them were so basic that it was very difficult in writing basic English level
programs in them. As time went by, some programming languages needed a specific
framework and support for further coding and development it, which was not possible using
these editors. VI Editor, Sublime Text Editor, is one of the many kinds of editors that came
into existence. The most prominent and which supports almost every coding language is
VISUAL STUDIO CODE. Its features let the user modify the editor as per the usage, which
means the user is able to download the libraries from the internet and integrate it with the
code as per his requirements.
Visual Studio Code has some very unique features. They are listed as below :
• Intelli-Sense:
It can detect if any snippet of code is left incomplete. Also, common variable syntaxes and
variable declarations are made automatically. Ex: If a certain variable is being used in the
program and the user has forgotten to declare, intelli-sense will declare it for the user.
• Cross-Platform Support:
Traditionally, editors used to support either Windows or Linux or Mac Systems. But Visual
Studio Code is cross-platform. So it can work on all three platforms. Also, the code works on
all three platforms; else, the open-source and proprietary software codes used to be different.
Usually supports all the programming languages but, if the user/programmer wants to use the
programming language which is not supported then, he can download the extension and use it.
And performance-wise, the extension doesn’t slow down the editor as it rums as a different
process. • Repository: With the ever-increasing demand for the code, secure and timely storage
is equally important. It is connected with Git or can be connected with any other repository for
pulling or saving the instances.
• Web-Support:
Comes with built-in support for Web applications. So, web applications can be built and
supported in VSC.
• Hierarchy Structure:
The code files are located in files and folders. The required code files also have some files,
which may be required for other complex projects. These files can be deleted as per
convenience.
• Improving Code:
Some code snippets can be declared a bit differently, which might help the user in the code.
This function prompts the user, wherever necessary, to change it to the suggested option.
• Terminal Support:
Many of the times, the user needs to start from the root of the directory to start with a particular
action, in-built terminal or console provides user support to not to switch in-between two
screens for the same.
• Multi-Projects:
• Git Support:
Resources can be pulled from Git Hub Repo online and vice-versa; saving can be done too.
Resource pulling also means cloning the code which is made available on the internet. This
code can later be changed and saved.
• Commenting: A common feature, but some of the languages do not support it. Commenting
on the code helps the user to recall or track according to the sequence he wants.
Advantages and Why should we use Visual Studio Code
There are many advantages over any other IDE; they are as follow:
1. Cross-platform support:
• Windows
• Linux
• Mac
2. Light-weight
3. Robust Architecture
4. Intelli-Sense
5. Freeware: Free of Cost- probably the best feature of all for all the programmers out there,
even more for the organizations.
6. Many users will use it or might have used it for desktop applications only, but it also provides
great tool support for Web Technologies like; HTML, CSS, JSON.
There are a few things that one can find a bit odd compared with so many features. It mainly
helps the front-end developers as compared with the back-end developers. But as per some
user’s opinions, it is equally helpful. It supports most of the languages used by most of the
programmers, but other languages might have to download, or extensions may have to be used
for them. Along with this common zoom-in, zoom-out brightness, theme selection features too
are made available.
• Till recent times, there’s hardly been an IDE or code editor that has been so user friendly that
even first-time users can use each and every feature without any hassles.
• The coding-friendly feature and code error recognition also helps users a long way into
making the code more efficient and error-less
SYSTEM DESIGN
The system design controls the major structural characteristics of the system. It as a major
impact on the testability and modifiability of the system, and it affects its efficiency. Much of
the designing software is spent in creating the system design. In the first level of the design
process, the focus is on deciding which modules are needed for the system, the specification of
these modules, and how the modules should be interconnected.
This is called the system design or toplevel design. The design activity begins when the
requirement documents for the software to be developed is available. The goal of the design
process is to produce a model or representation of the system, which can be used later to bind
the system. The produced model is called design of the system.
A structured design is a top down approach to minimize complexity and make a problem
manageable by sub dividing it into smaller segments. The most creative and challenging phase
of the system development of life cycle is system design. The design phase is translation from
user oriented document to document oriented programmers.
1. Weather prediction
2. Yield prediction
3. Crop selection
Our project aims at minimizing these problems and looks forward to easing the activities of
the farmers.
4.3 OBJECTIVE OF THE APPLICATION
The objective of our project is to build a project which helps the farmers to carry out better
farming. Help the farmers to predict the weather and climatic changes. To enable easy
communication between the farmers
4.4 FLOWCHART
The above figure 1 - is the design of our project Crop yield predictor for better crop production.
4.5 DATASET DESCRIPTION
This dataset comprises historical records of crop yields from various agricultural fields over
multiple years. It includes information on factors such as weather conditions, soil properties,
agricultural practices, and crop types. The primary objective of this dataset is to facilitate the
prediction of crop yields based on these factors, aiding farmers, researchers, and policymakers
in optimizing agricultural productivity and sustainability.
Features:
Crop Type: The type of crop grown in the field (e.g., wheat, corn, rice).
Field Characteristics:
Data Source: The data is collected through various sources including agricultural research
institutions, government agencies, and agricultural surveys.
Kaggle : https://www.kaggle.com/code/charlessamuel/tamil-nadu-crop-production-eda-
analysis
Use Case: This dataset can be used for crop yield prediction, identifying the impact of different
factors on crop productivity, and optimizing agricultural practices for improved yields and
sustainability.
• State_Name
• District_Name
• Crop_Year
• Season
• Crop
• Area
• Production
2. Crop Prediction Dataset
This dataset contains information on various agricultural parameters and environmental factors
associated with the cultivation of different crops. The primary goal of this dataset is to facilitate
the prediction of suitable crops for a given region based on factors such as climate, soil
characteristics, and agronomic practices. It aims to assist farmers, agricultural researchers, and
policymakers in making informed decisions regarding crop selection and land use planning.
• State_Name
• District_Name
• Season
• Crop
Use Case: This dataset can be used for crop suitability mapping, recommending suitable crops
for specific regions, optimizing land use planning, and assessing the potential impact of climate
change on crop production.
3. Rainfall Dataset
This dataset comprises historical records of rainfall measurements from various meteorological
stations across different regions. It includes information on daily, monthly, or yearly
precipitation levels, providing insights into precipitation patterns, variability, and trends over
time. The dataset aims to support research, analysis, and applications related to hydrology,
climate studies, agriculture, water resource management, and weather forecasting.
Features:
Rainfall Measurement
• Monthly Rainfall: Total rainfall recorded in milli meters for a specific month.
• Yearly Rainfall: Total rainfall recorded in milli meters for a particular year.
Use Case: This dataset can be used for various purposes, including analysing long-term rainfall
trends, assessing seasonal variations in precipitation, studying the impact of climate change on
rainfall patterns, modelling hydrological processes, and supporting decision-making in
agriculture, water resource management, and disaster preparedness.
• SUBDIVISION
• YEAR
• JAN
• FEB
• MAR
• APR
• MAY
• JUN
• JUL
• AUG
• SEP
• OCT
• NOV
• DEC
• ANNUAL
• Jan-Feb
• Mar-May
• Jun-Sep
• Oct-Dec
Kaggle: https://www.kaggle.com/code/anbarivan/indian-rainfall-analysis-and-
prediction/input?select=rainfall+in+india+1901-2015.csv
4. Crop Recommendation Dataset
Description:
This dataset comprises agricultural parameters, environmental factors, and crop performance
data collected from various regions and farming practices. The primary objective of this dataset
is to facilitate the recommendation of suitable crops for specific agricultural conditions,
considering factors such as soil properties, climate conditions, and historical crop performance.
It aims to assist farmers, agricultural extension services, and policymakers in making informed
decisions regarding crop selection and land use planning to optimize productivity and
sustainability.
• Temperature: Average, minimum, and maximum temperature (in Celsius) during the
growing season.
• Humidity: Average relative humidity (as a percentage) during the growing season.
• pH Level: Soil pH level indicating acidity or alkalinity.
• Yearly Rainfall: Total rainfall recorded in milli meters for a particular year.
• Recommended Crops: Crops recommended based on the analysis of soil, climate, and
historical performance data.
• Nitrogen (N), Phosphorus (P), Potassium (K): Concentrations of major nutrients in the
soil (in parts per million or kilograms per hectare).
Use Case: This dataset can be used for crop recommendation systems, precision agriculture,
land use planning, and sustainable farming practices.
• N
• P
• K
• Temperature
• Humidity
• pH
• Rainfall
• Label
5. Fertilizer Recommendation Dataset
This dataset comprises agricultural parameters, soil nutrient data, crop requirements, and
fertilizer application records collected from various farming systems and experimental
trials. The primary objective of this dataset is to support the recommendation of appropriate
fertilizer types and application rates for specific crops and soil conditions, aiming to
optimize crop productivity, nutrient use efficiency, and environmental sustainability. It
serves as a valuable resource for farmers, agronomists, and agricultural extension services
seeking guidance on effective fertilizer management practices.
Features:
• Nitrogen (N), Phosphorus (P), Potassium (K): Concentrations of major nutrients in the
soil (in parts per million or kilograms per hectare).
• pH Level: Soil pH level indicating acidity or alkalinity.
• Temperature: Average, minimum, and maximum temperature (in Celsius) during the
growing season.
• Humidity: Average relative humidity (as a percentage) during the growing season.
• Crop Type: The type of crop grown in the field (e.g., wheat, corn, rice).
Use Case: This dataset can be used to develop fertilizer recommendation models, decision
support systems for precision agriculture, and advisory tools for optimizing nutrient
management practices in crop production.
• Temperature
• Humidity
• Soil Moisture
• Soil Type
• Crop Type
• Nitrogen
• Phosphorous
• Potassium
• Fertilizer Name
4.6 MACHINE LEARNING ALGORITHMS :
1. DECISION TREES :
Decision trees are versatile machine learning algorithms used for both classification and
regression tasks. They mimic human decision-making processes by recursively partitioning the
data into subsets based on features’ values, creating a tree-like structure of decisions.
• Splitting Criteria: Decision trees split data based on the most informative features.
Common criteria include information gain, Gini impurity, or entropy.
• Recursive Splitting: The algorithm recursively splits data based on the selected criteria
until a stopping condition is met.
• Stopping Conditions: Include reaching a maximum tree depth, having nodes with pure
subsets, or reaching a minimum number of data points in a node.
2. KNN
The k-Nearest neighbours (kNN) algorithm is a simple yet effective machine learning
technique used for classification and regression tasks. It operates on the principle of similarity,
where the prediction for a new data point is based on the majority class or average value of its
k nearest neighbors in the feature space.
2. k-Nearest Neighbours: The value of k specifies the number of nearest neighbours to consider
when making predictions. Typically, k is chosen empirically or through cross-validation.
3. Classification: For classification tasks, the majority class among the k nearest neighbours is
assigned to the new data point.
4. Regression: For regression tasks, the average (or weighted average) value of the target
variable among the k nearest neighbours is used as the prediction.
Construction of KNN:
1. Training Phase: In the training phase, the algorithm stores the feature vectors and
corresponding class labels or target values of the training dataset.
2. Prediction Phase: In the prediction phase, for each new data point, the algorithm calculates
the distances to all training data points and selects the k nearest neighbours.
3.Decision Rule: The decision rule determines the prediction based on the majority class
(classification) or average value (regression) of the k nearest neighbours.
3. NAÏVE BAYES GAUSSIAN :
The Naïve Bayes Gaussian algorithm is a probabilistic classification technique based on Bayes’
theorem with the assumption of Gaussian (normal) distribution of features. It’s particularly
useful for classification tasks involving continuous features. Despite its simplicity, Naïve
Bayes Gaussian often performs surprisingly well, especially with high-dimensional data.
1. Bayes’ Theorem:
2. Naïve Assumption:
The “naïve” assumption of Naïve Bayes is that features are conditionally independent
given the class label. This simplifies the computation, as it allows us to calculate the
joint probability of the features as the product of the individual conditional
probabilities.
3. Gaussian Distribution:
Naïve Bayes Gaussian assumes that the continuous features follow a Gaussian (normal)
distribution. This assumption simplifies the calculation of conditional probabilities and
makes the algorithm suitable for continuous data.
4.7 MODULES
PREDICTION
1. Prediction module
Crop Prediction :
The crop prediction module employs machine learning algorithms to forecast crop yields and
production outcomes based on a multitude of factors including historical yield data, weather
patterns, soil conditions, and agronomic practices. By analysing these diverse datasets, the
module generates predictive models capable of estimating future crop yields, planting
schedules, and potential risks such as pest infestations or droughts. These predictions empower
farmers, policymakers, and agricultural stakeholders to make informed decisions regarding
crop selection, resource allocation, and adaptation strategies, ultimately enhancing agricultural
productivity, sustainability, and food security.
Yield Prediction :
The yield prediction module is a crucial component of agricultural decision support systems,
leveraging machine learning techniques to forecast crop yields based on various input factors
such as weather data, soil conditions, crop type, and management practices. By analysing
historical yield data and correlating it with environmental and agronomic variables, the module
generates predictive models capable of estimating future crop yields with a certain degree of
accuracy. These predictions enable farmers, agronomists, and policymakers to make informed
decisions regarding crop planning, resource allocation, and risk management, ultimately
improving productivity, sustainability, and profitability in agriculture.
Rainfall Prediction :
The rainfall prediction module utilizes statistical and machine learning models to forecast
future precipitation patterns based on historical weather data, atmospheric conditions, and
geographical factors. By analysing past rainfall records, satellite imagery, and atmospheric
pressure data, the module generates predictive models capable of estimating upcoming rainfall
amounts, timing, and spatial distribution. These predictions are invaluable for a wide range of
applications, including agriculture, water resource management, disaster preparedness, and
infrastructure planning. By providing early warnings and insights into potential weather-related
events, the rainfall prediction module helps stakeholders make informed decisions to mitigate
risks and maximize opportunities related to precipitation variability.
2. RECOMMENDATION MODULE :
RECOMMENDATION
The crop recommendation module utilizes machine learning algorithms and agricultural
expertise to suggest suitable crop choices to farmers based on various factors such as soil type,
climate conditions, market demand, and agronomic practices. By analysing data on soil
characteristics, historical crop performance, climate patterns, and market trends, the module
generates personalized recommendations tailored to the specific needs and constraints of
individual farmers or agricultural regions. These recommendations empower farmers to make
informed decisions about crop selection, diversification, and rotation, ultimately optimizing
yields, profitability, and sustainability in agriculture while minimizing risks associated with
environmental variability and market fluctuations
Fertilizer Recommendation :
The fertilizer recommendation module utilizes soil nutrient analysis, crop nutrient
requirements, and agronomic best practices to suggest optimal fertilizer formulations and
application rates for specific crops and soil conditions. By analysing soil nutrient levels, crop
nutrient demands, and environmental factors, such as rainfall patterns and temperature, the
module generates personalized recommendations aimed at maximizing crop productivity while
minimizing nutrient wastage and environmental impact. These recommendations empower
farmers to make informed decisions about fertilizer management, ensuring efficient use of
resources and sustainable agricultural practices, ultimately leading to improved yields,
profitability, and soil health
METHODOLOGY OF THE SYSTEM
• In our research, which we found in the previous research papers is that everyone uses
climatic factors like rainfall, sunlight and agricultural factors like soil type, nutrients
possessed by the soil (Nitrogen, Potassium, etc.)
• But the problem is we need to gather the data and then a third party does this prediction
and then it is explained to the farmer and this takes a lot of effort for the farmer and he
doesn’t understand the science behind these factors.
• Machine Learning Projects: These projects utilize machine learning algorithms to
analyze historical agricultural data and predict crop yields. Python libraries like Scikit-
Learn and TensorFlow are commonly used for building predictive models. These
models can take into account various factors such as weather conditions, soil quality,
and crop characteristics to make accurate predictions .
• Web Applications: Platforms like GitHub host web applications specifically designed
for crop yield prediction. These applications typically utilize historical data to provide
insights into future crop harvests. Users can access these platforms to analyze crop yield
trends, perform data visualization, and make informed decisions about agricultural
practices .
• Flask Deployment: Some systems deploy crop yield prediction models using Flask, a
Python web framework. Flask allows developers to create web services that can be
easily accessed and integrated into agricultural practices. This deployment method
enables farmers and agricultural professionals to conveniently access crop yield
predictions and make real-time decisions .
• Visualization Tools: Python is used to develop visualization and prediction tools for
analysing crop production data. These tools enable users to visualize historical trends
in crop yield, weather patterns, and other relevant factors. By understanding these
trends, stakeholders can make informed decisions about crop management and resource
allocation.
• These systems collectively contribute to enhancing agricultural productivity and
sustainability by providing valuable insights into crop yield prediction.
5.2 PROPOSED SYSTEM
• The proposed system for crop yield prediction using Python integrates various
components and methodologies to provide accurate predictions and valuable insights
for agricultural decision-making. Here's a deeper explanation of each aspect:
• -Data Collection and Pre processing: The system gathers diverse datasets containing
information on weather conditions, soil quality, historical crop yields, and other
relevant environmental factors. These datasets undergo pre processing steps such as
cleaning, normalization, and feature engineering to ensure data quality and relevance to
the prediction models.
• Machine Learning Models: Utilizing Python libraries like Scikit-Learn, TensorFlow, or
PyTorch, the system employs machine learning algorithms such as regression, decision
trees, or neural networks to build predictive models. These models analyze the pre
processed data to forecast future crop yields based on historical patterns and
environmental variables .
• Flask Deployment: To make the predictive models accessible to end-users, the system
utilizes Flask, a lightweight Python web framework. Flask allows for easy deployment
of machine learning models as RESTful APIs, enabling integration into web
applications or other systems .
• Visualization Tools: Python's visualization libraries such as Matplotlib, Seaborn, or
Plotly are employed to create intuitive visualizations of the predicted crop yields. These
visualizations aid stakeholders in understanding the trends, patterns, and potential risk
factors affecting crop production .
• Continuous Improvement: The system incorporates mechanisms for continuous
learning and improvement. It regularly updates its models with new data, adjusts
parameters based on feedback, and explores advanced techniques to enhance prediction
accuracy and reliability over time.
• By integrating these components, the proposed system aims to empower farmers,
agricultural researchers, and policymakers with actionable insights to optimize crop
production, mitigate risks, and improve food security.
5.3 STEPS IN METHODOLOGY
Figure 4 - Methodology
The methodology of developing and deploying a machine learning model, which typically
involves the following steps: data acquisition and pre processing, model development, model
training, model testing, and deployment
• Identify the problem statement and the type of data required to solve it.
• Clean the data by removing any irrelevant or inconsistent entries, handling missing
values, and dealing with outliers.
• Pre process the data by performing tasks like normalization, feature scaling, feature
engineering, and encoding categorical variables.
2. Model Development:
• Define the model architecture or structure, including the number and type of layers
(in the case of neural networks) or the configuration of the algorithm.
• Set hyperparameters, such as learning rate, regularization strength, and batch size,
which control the learning process.
3. Model Training:
• Feed the training data into the model and use an optimization algorithm (e.g., gradient
descent) to update the model's parameters iteratively.
• Monitor the model's performance on the validation set during training to detect
overfitting or underfitting and adjust hyperparameters accordingly.
• Continue training until the model achieves satisfactory performance on the validation
sector converges to a stable state.
4. Model Testing:
• Prepare the model for deployment by packaging it in a format suitable for the chosen
deployment environment (e.g., a serialized model file or a containerized application).
• Integrate the model into the target system, which may involve writing code to handle
input/output, data pre processing, and interacting with other components of the system.
• Test the deployed model thoroughly to ensure it functions correctly in the production
environment.
• Monitor the model's performance and collect feedback from real-world usage to
continuously improve and update the model if necessary.
Figure 5 - Methodology-preprocessing
The pre processing step in machine learning involves several important tasks to prepare the
data for model training. Let's break down each task:
1. Acquiring Dataset:
• Determine the data sources that are relevant to your problem statement.
• Gather the required data from these sources, such as databases, APIs, or web scraping.
• Ensure that the collected data is in a structured format, such as CSV, JSON, or a
database table.
• Identify any missing values in the dataset, represented as NaN (Not a Number) or null
values.
• Decide on an appropriate strategy to handle missing values based on the nature of the
data and the missing data patterns.
➢ Removing the rows or columns with missing values if they are few and the loss of
information is acceptable.
➢ Imputing the missing values by filling them with a statistical measure like the mean,
median, or mode of the respective feature.
➢ Using more advanced imputation techniques such as regression or machine learning
algorithms to predict missing values.
3. Handling Outliers:
• Detect and handle outliers, which are data points that significantly deviate from the
normal range or distribution of the dataset.
• Visualize the data using techniques like box plots or scatter plots to identify potential
outliers.
• Decide on an appropriate strategy based on the nature of the data and the specific
problem:
➢ Removing outliers if they are due to data entry errors or measurement issues and have a
significant impact on the analysis.
➢ Transforming the data using techniques like log transformation or fissurization to reduce
the impact of outliers.
➢ Applying robust statistical techniques or algorithms that are less sensitive to outliers.
4. Feature Scaling:
• Normalize or scale the features in the dataset to ensure that they are on a similar scale and
have comparable ranges.
• Feature scaling is important to prevent features with larger magnitudes from dominating
the learning process and to enable algorithms to converge faster.
• After completing the above steps, you will have a pre processed dataset ready for model
training.
• This dataset should be cleaned, with missing values handled, outliers managed, and
features appropriately scaled.
• It is advisable to save the pre processed dataset separately for future reference and to
ensure consistency during model development.
SOURCE CODE
Yield Prediction.py
import pandas as pd
import numpy as np
import json
import sys
df = df.drop(['Crop_Year'], axis=1)
X = df.drop(['Production'], axis=1)
y = df['Production']
ohe = OneHotEncoder(handle_unknown='ignore')
ohe.fit(X_train[categorical_cols])
X_train_categorical = ohe.transform(X_train[categorical_cols])
X_test_categorical = ohe.transform(X_test[categorical_cols])
model.fit(X_train_final, y_train)
# Get the input parameters as command line arguments
Jstate = sys.argv[1]
Jdistrict = sys.argv[2]
Jseason = sys.argv[3]
Jcrops = sys.argv[4]
Jarea = sys.argv[5]
#Get the user inputs and store them in a numpy array - ans is 427.64
user_input = np.array([[Jstate,Jdistrict,Jseason,Jcrops,Jarea]])
prediction = model.predict(user_input_final)
print(str(prediction[0]))
6.2 CROP PREDICITON
ZDecision_Tree_Model.py
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
# In[2]:
data = pd.read_csv('preprocessed2.csv')
# In[3]:
data.head()
# In[4]:
data['Season'] = data['Season'].str.rstrip()
# In[5]:
for i in data['Season']:
print(len(i))
# In[6]:
list(data)
# In[7]:
training_data = list(np.array(data))
# In[9]:
# In[10]:
# In[11]:
def unique_vals(Data,col):
# In[12]:
def class_counts(Data):
counts= {}
label =row[-1]
counts[label] = 0
counts[label] += 1
return counts
# In[13]:
class_counts(training_data)
# In[14]:
class Question:
def __init__(self,column,value):
self.column =column
self.value=value
def match(self,example):
val = example[self.column]
def match2(self,example):
return True
else:
return False
def __repr__(self):
header[self.column],"==",str(self.value))
# In[15]:
Question(0,'Bihar')
# In[16]:
def partition(Data,question):
true_rows,false_rows = [],[]
if(question.match(row)):
true_rows.append(row)
else:
false_rows.append(row)
return true_rows,false_rows
# In[17]:
def gini(Data):
counts = class_counts(Data)
impurity = 1
prob_of_lbl = counts[lbl]/float(len(Data))
impurity-=prob_of_lbl**2
return impurity
# In[18]:
def info_gain(left,right,current_uncertainity):
p = float(len(left))/(len(left)+len(right))
# In[19]:
def find_best_split(Data):
best_gain = 0
best_question = None
current_uncertainity = gini(Data)
n_features = len(Data[0]) - 1
values = unique_vals(Data,col)
question = Question(col,val)
true_rows,false_rows = partition(Data,question)
if(len(true_rows) == 0 or len(false_rows) == 0 ):
continue
gain = info_gain(true_rows,false_rows,current_uncertainity)
if gain>best_gain:
return best_gain,best_question
# In[20]:
class Leaf:
def __init__(self,Data):
self.predictions = class_counts(Data)
# In[21]
class Decision_Node:
def __init__(self,question,true_branch,false_branch):
self.question=question
self.true_branch = true_branch
self.false_branch = false_branch
# In[22]:
def build_tree(Data,i=0):
return Leaf(Data)
true_rows,false_rows =partition(Data,question)
true_branch = build_tree(true_rows,i)
false_branch = build_tree(false_rows,i)
return Decision_Node(question,true_branch,false_branch)
# In[23]:
my_tree = build_tree(training_data)
print(my_tree)
# In[24]:
def print_tree(node,spacing=""):
if isinstance(node,Leaf):
print(spacing + "Predict",node.predictions)
return
print(spacing+str(node.question))
print(spacing + "--> True:")
# In[25]:
print_tree(my_tree)
# In[26]
def print_leaf(counts):
total = sum(counts.values())*1.0
probs = {}
return probs
# In[27]:
def classify(row,node):
if is instance(node,Leaf):
return node.predictions
if node.question.match(row):
return classify(row,node.true_branch)
else:
return classify(row,node.false_branch)
# In[28]:
joblib.dump(my_tree, 'filetest2.pkl')
ZDecision_Tree_Model_Call.py
import pandas as pd
import numpy as np
import joblib
import cgitb
cgitb.enable()
import sys
class Question:
def __init__(self,column,value):
self.column =column
self.value=value
def match(self,example):
val = example[self.column]
def match2(self,example):
return True
else:
return False
def __repr__(self):
header[self.column],"==",str(self.value))
def class_counts(Data):
counts= {}
label =row[-1]
counts[label] = 0
counts[label] += 1
return counts
class Leaf:
def __init__(self,Data):
self.predictions = class_counts(Data)
class Decision_Node:
def __init__(self,question,true_branch,false_branch):
self.question=question
self.true_branch = true_branch
self.false_branch = false_branch
def print_tree(node,spacing=""):
if isinstance(node,Leaf):
print(spacing + "Predict",node.predictions)
return
print(spacing+str(node.question))
def print_leaf(counts):
total = sum(counts.values())*1.0
probs = {}
return probs
def classify(row,node):
if isinstance(node,Leaf):
return node.predictions
if node.question.match(row):
return classify(row,node.true_branch)
else:
return classify(row,node.false_branch)
dt_model_final= joblib.load('ML/crop_prediction/filetest2.pkl')
state =sys.argv[1]
district=sys.argv[2]
season=sys.argv[3
testing_data = [[state,district,season]]
Predict_dict = (print_leaf(classify(row,dt_model_final))).copy()
for key, value in Predict_dict.items() :
print (key)
rainfall_prediction.py
import pandas as pd
import sys
df = pd.read_csv('ML/rainfall_prediction/rainfall_in_india_1901-2015.csv')
# Filter the dataframe to only include rows with the given district
# Calculate the average rainfall for the given month across all the years
avg_rainfall = state_data[month].mean()
return avg_rainfall
# Get the input parameters as command line arguments
Jregion = sys.argv[1]
Jmonth = sys.argv[2]
print(predicted_rainfall)
Recommend.py
import pandas as pd
import numpy as np
import json
import sys
jsonn = sys.argv[1]
jsonp = sys.argv[2]
jsonk = sys.argv[3]
jsont = sys.argv[4]
jsonh = sys.argv[5]
jsonph = sys.argv[6]
jsonr = sys.argv[7]
n_params = json.loads(jsonn)
p_params = json.loads(jsonp)
k_params = json.loads(jsonk)
t_params = json.loads(jsont)
h_params = json.loads(jsonh)
ph_params = json.loads(jsonph)
r_params = json.loads(jsonr)
dataset = pd.read_csv('ML/crop_recommendation/Crop_recommendation.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
classifier.fit(X_train, y_train)
user_input =
np.array([[n_params,p_params,k_params,t_params,h_params,ph_params,r_params]])
predictions = classifier.predict(user_input)
print(str(predictions[0]))
6.5 FERTILIZER_RECOMMENDATION
fertilizer_recommendation.py
import pandas as pd
import sys
data = pd.read_csv("ML/fertilizer_recommendation/fertilizer_recommendation.csv")
le_soil = LabelEncoder()
le_crop = LabelEncoder()
X = data.iloc[:, :8]
y = data.iloc[:, -1]
dtc = DecisionTreeClassifier(random_state=0)
dtc.fit(X, y)
jsonn = sys.argv[1]
jsonp = sys.argv[2]
jsonk = sys.argv[3]
jsont = sys.argv[4]
jsonh = sys.argv[5]
jsonsm = sys.argv[6]
jsonsoil = sys.argv[7]
jsoncrop = sys.argv[8]
soil_enc = le_soil.transform([jsonsoil])[0]
crop_enc = le_crop.transform([jsoncrop])[0]
# Get the user inputs and store them in a numpy array - Urea
#user_input = [[26,52,38,'Sandy','Maize',37,0,0]]
user_input = [[jsont,jsonh,jsonsm,soil_enc,crop_enc,jsonn,jsonk,jsonp]]
fertilizer_name = dtc.predict(user_input)
print(str(fertilizer_name[0]))
6.6 PHP SOURCES
Index.php
<!DOCTYPE html>
<html>
<div class="wrapper">
<div class="container">
<p class="text-white">
</p>
<div class="cg">
<blockquote cite="blockquote">
<em
><b
> “Farming looks mighty easy when your plow is a pencil, and you're a
thousand miles from the corn field..”</b
></em>
</h6>
<br />
DWIGHT D. EISENHOWER
</footer>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<!--
==================================================================
==================================================================
==== -->
<div class="section features-6 text-dark bg-white" id="services">
<div class="row">
</div>
</div>
<br>
<div class="col-lg-6">
<p class=" ">Farmers can get recommendations for crop and fertilizer and even
predictions for crop, yield and rainfall. All these are implemented using ML with
proper dataset. </p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--
==================================================================
==================================================================
==== -->
<div class="container">
<div class="pr-md-5">
<p>The time is now for the next step in farming. We bring you the future of
farming along with great tools for asisting the farmers.</p>
<li class="py-2">
<div>
</div>
<div>
<h6 class="mb-0">Crop Prediction and Recommendation</h6>
</div>
</div>
</li>
<li class="py-2">
<div>
</div>
<div>
</div>
</div>
</li>
<li class="py-2">
<div>
</div>
<div>
</div>
</li>
<li class="py-2">
<div>
</div>
<div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!--
==================================================================
==================================================================
==== -->
<div class="row">
</div>
</div>
<div class="col-md-4">
<div class="info">
</div>
</div>
<div class="col-md-4">
<div class="info">
<img class=" img-fluid" src="assets/img/css3.png" alt="CSS3">
</div>
</div>
<div class="col-md-4">
<div class="info">
</div>
</div>
</div>
<div class="info">
</div>
</div>
<div class="info">
</div>
</div>
<div class="info">
</div>
</div>
</div
</div>
</div>
</body>
</html>
header.php
<head>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-
ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"
integrity="sha384-
AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p"
crossorigin="anonymous"/>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700"
rel="stylesheet">
<script src="assets/js/state_district_crops_dropdown.js"></script>
</head>
footer.php
<footer class="footer">
<div class="container">
<div class="row">
</div>
<h5>Our Address</h5>
<address>
</div>
</address>
</div>
</button>
</button>
</button>
</button>
</button>
</div>
</div>
</div>
<hr>
<div class="col-auto">
<p>© Copyright 2024 Crop Yield Prediction, All Rights Reserved </p>
</div>
</div>
</div>
</footer>
<script src="https://cdn.staticfile.org/jquery/3.6.3/jquery.min.js"></script
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-
UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-
JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/ee1c3da296.js"></script>
nav.php
<nav
id="navbar-main"
class="
bg-default
navbar-light
position-sticky
top-0
shadow
py-0
“>
<div class="container-fluid">
</a>
</li>
</ul>
<button
class="navbar-toggler bg-white"
type="button"
data-toggle="collapse"
data-target="#navbar_global"
aria-controls="navbar_global"
aria-expanded="false"
aria-label="Toggle navigation">
</button>
<div class="navbar-collapse-header">
<div class="row">
<a href="index.html">
</a>
</div>
<button
type="button"
class="navbar-toggler"
data-toggle="collapse"
data-target="#navbar_global"
aria-controls="navbar_global"
aria-expanded="false"
aria-label="Toggle navigation">
<span></span>
<span></span>
</button>
</div>
</div>
</div>
</a>
</div>
</div>
</li>
<li class="nav-item" id="recommendation">
</a>
<a class="dropdown-item"
href="fertilizer_recommendation.php">Fertilizer Recommendation</a>
</div>
</div>
</li>
</ul>
</div>
</div>
</nav>
<style>
.topnav a {
.topnav a:hover {
opnav a.activa {
border-bottom: 3px solid red;
</style>
<script>
$("#nav li a").each(function() {
if (this.href == window.location.href) {
$(this).addClass("activaa");
});
</script>
crop_prediction.php
<!DOCTYPE html>
<html>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<!--
==================================================================
==================================================================
==== -->
<div class="row">
</div>
</div>
<div class="card-header">
</div>
<thead>
<th><center>District</center></th>
<th><center>Season</center></th>
<th><center>Prediction</center></th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td>
<div class="form-group">
<script language="javascript">print_state("sts");</script>
</div>
</td>
<td>
</select>
<script language="javascript">print_state("sts");</script>
</div>
</td>
<td>
<option name="Autumn"
value="Autumn">Autumn</option>
<option name="Summer"
value="Summer">Summer</option>
</select>
</div>
</td>
<td>
<center>
</div>
</center>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<h4>
<?php
if(isset($_POST['Crop_Predict'])){
$state=trim($_POST['stt']);
$district=trim($_POST['district']);
$season=trim($_POST['Season']);
echo "Crops grown in ".$district." during the ".$season." season are :- ";
$JsonState=json_encode($state);
$JsonDistrict=json_encode($district);
$JsonSeason=json_encode($season);
$command = escapeshellcmd("python
ML/crop_prediction/ZDecision_Tree_Model_Call.py $JsonState $JsonDistrict
$JsonSeason");
$output = passthru($command);
echo $output;
?>
</h4>
</div>
</div>
</div>
</div>
</section>
<?php require("footer.php");?>
</body>
</html>
yield_prediction.php
<!DOCTYPE html>
<html>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<!--
==================================================================
==================================================================
==== -->
<div class="row">
</div>
</div>
<div class="card-header">
</div>
<thead>
<th><center> State</center></th>
<th><center>District</center></th>
<th><center>Season</center></th>
<th><center>Crop</center></th>
<th><center>Area</center></th>
<th><center>Prediction</center></th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td>
<div class="form-group">
<option value="Karnataka">TAMILNADU</option>
</select>
</div>
</td>
<td>
<option value="VILLUPURAM">VILLUPURAM</option>
<option value="DHARMAPURI ">DHARMAPURI</option>
<option value="KALLAKURICHI">KALLAKURICHI</option>
</select>
</div>
</td>
<td>
</select>
</div>
</td>
<td>
</select>
</div>
</td>
<script>
document.getElementById("season").addEventListener("change", function() {
console.log(districtDropdown);
console.log(seasonDropdown);
console.log(cropDropdown);
// If both district and season are selected, add the corresponding crop options to the
dropdown
optionElement.text = option;
cropDropdown.appendChild(optionElement);
}
});
</script>
<td>
<div class="form-group">
</div>
</td>
<td>
<center>
</div>
</center>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
<div class="card-header">
<span class=" text-success display-4" > Result </span>
</div>
<h4>
<?php
if(isset($_POST['Yield_Predict'])){
$state=trim($_POST['state']);
$district=trim($_POST['district']);
$season=trim($_POST['Season']);
$crops=trim($_POST['crops']);
$area=trim($_POST['area']);
$Jstate=json_encode($state);
$Jdistrict=json_encode($district);
$Jseason=json_encode($season);
$Jcrops=json_encode($crops);
$Jarea=json_encode($area);
$output = passthru($command);
echo $output;
?>
</h4>
</div>
</div>
</div>
</div>
</section>
<?php require("footer.php");?>
</body>
</html>
rainfall_prediction.php
<!DOCTYPE html>
<html>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<!--
==================================================================
==================================================================
==== -->
<div class="row">
</div>
</div>
<div class="card-header">
</div>
<thead>
<th><center>Region</center></th>
<th><center>Month</center></th>
<th><center>Prediction</center></th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td>
</select>
</div>
</td>
<td>
</select>
</div>
</td>
<td>
<center>
</div>
</center>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
<div class="card-header">
</div>
<h4>
<?php
if(isset($_POST['Rainfall_Predict'])){
$region=trim($_POST['region']);
$month=trim($_POST['month']);
echo "Predicted Rainfall for the Region $region in the month $month is (in mm) : ";
$Jregion=json_encode($region);
$Jmonth=json_encode($month);
$command = escapeshellcmd("python
ML/rainfall_prediction/rainfall_prediction.py $Jregion $Jmonth ");
$output = passthru($command);
echo $output;
?>
</h4>
</div>
</div>
</div>
</div>
</section>
<?php require("footer.php");?>
</body>
</html>
crop_recommendation.php
<!DOCTYPE html>
<html>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<!--
==================================================================
==================================================================
==== -->
<div class="row">
</div>
</div>
<div class="card-header">
<span class="pull-right">
</span>
</div>
<thead>
<th><center> Nitrogen</center></th>
<th><center>Phosporous</center></th>
<th><center>Potasioum</center></th>
<th><center>Temparature</center></th>
<th><center>Humidity</center></th>
<th><center>PH</center></th>
<th><center>Rainfall</center></th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
<input type = 'number' name = 'ph' step =0.01 placeholder="PH Eg:6.5" required
class="form-control">
</div>
</td>
<td>
<div class="form-group">
<input type = 'number' name = 'r' step =0.01 placeholder="Rainfall Eg:203" required
class="form-control">
</div>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
<div class="card-header">
</div>
<h4>
<?php
if(isset($_POST['Crop_Recommend'])){
$n=trim($_POST['n']);
$p=trim($_POST['p']);
$k=trim($_POST['k']);
$t=trim($_POST['t']);
$h=trim($_POST['h']);
$ph=trim($_POST['ph']);
$r=trim($_POST['r']);
$Jsonp=json_encode($p);
$Jsonk=json_encode($k);
$Jsont=json_encode($t);
$Jsonh=json_encode($h);
$Jsonph=json_encode($ph);
$Jsonr=json_encode($r);
$output = passthru($command);
echo $output;
?>
</h4>
</div>
</div>
</div>
</div>
</section>
<?php require("footer.php");?>
</body>
</html>
fertilizer_recommendation.php
<!DOCTYPE html>
<html>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<!--
==================================================================
==================================================================
==== -->
<div class="row">
</div>
</div>
<div class="row row-content">
<div class="card-header">
<span class="pull-right">
</span>
</div>
<thead>
<th><center> Nitrogen</center></th>
<th><center>Phosporous</center></th>
<th><center>Potasioum</center></th>
<th><center>Temparature</center></th>
<th><center>Humidity</center></th>
<th><center>Soil Moisture</center></th>
<th><center>Soil Type</center></th>
<th><center>Crop</center></th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<div class="form-group">
</div>
</td>
<td>
<option value="Sandy">Sandy</option>
<option value="Loamy">Loamy</option>
<option value="Black">Black</option>
<option value="Red">Red</option>
<option value="Clayey">Clayey</option>
</select>
</div>
</td>
<td>
<option value="Maize">Maize</option>
<option value="Sugarcane">Sugarcane</option>
<option value="Cotton">Cotton</option>
<option value="Tobacco">Tobacco</option>
<option value="Paddy">Paddy</option>
<option value="Barley">Barley</option>
<option value="Wheat">Wheat</option>
<option value="Millets">Millets</option>
<option value="Pulses">Pulses</option>
</select>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
<div class="card-header">
</div>
<h4>
<?php
if(isset($_POST['Fert_Recommend'])){
$n=trim($_POST['n']);
$p=trim($_POST['p']);
$k=trim($_POST['k']);
$t=trim($_POST['t']);
$h=trim($_POST['h']);
$sm=trim($_POST['soilMoisture']);
$soil=trim($_POST['soil']);
$crop=trim($_POST['crop']);
$Jsonn=json_encode($n);
$Jsonp=json_encode($p);
$Jsonk=json_encode($k);
$Jsont=json_encode($t);
$Jsonh=json_encode($h);
$Jsonsm=json_encode($sm);
$Jsonsoil=json_encode($soil);
$Jsoncrop=json_encode($crop);
$command = escapeshellcmd("python
ML/fertilizer_recommendation/fertilizer_recommendation.py $Jsonn $Jsonp $Jsonk $Jsont
$Jsonh $Jsonsm $Jsonsoil $Jsoncrop ");
$output = passthru($command);
echo $output;
?>
</h4>
</div>
</div>
</div>
</div>
</section>
<?php require("footer.php");?>
</body>
</html>
RESULTS
7.1 SNAPSHOTS
Crop prediction will predict different kinds of crops suitable to be grown for the area which
has been selected through the input
In yield prediction yield for the particular area which is selected is predicted, this will give
the farmer an idea about the production of the crop
Figure 9 - Rainfall prediction
Rainfall prediction will predict the rainfall for the particular region which is selected according
to the inputs from the list. This will help farmers from incurring losses.
Crop recommendation recommends the particular crop to be grown in that particular area
Figure 11 - Fertilizer prediction
Fertilizer prediction will recommend the particular fertilizer suitable for that area. That
fertilizer will be helpful for the crop which is to be grown.
FUTURE ENHANCEMENT
As a future scope, the web-based application can be made more user-friendly by targeting more
populations by including all the different regional languages in the interface and providing a
link to upload information instead of entering the test value manually. This research work can
be enhanced to a high level by building a recommender system of agriculture production and
distribution for farmers. By which farmers can make their own decision like which season
which crop should sow so that they can get better profit. This system works for structured
datasets or databases
Incorporating satellite imagery and remote sensing data can provide real-time information on
crop health, moisture levels, and environmental conditions. This integration can enhance the
accuracy and timeliness of crop yield predictions.
Deploying IoT sensors in agricultural fields can enable the collection of high-resolution data
on soil moisture, temperature, and nutrient levels. Integrating this data with crop yield
prediction models can offer more granular insights for farmers to optimize their farming
practices.
Deep learning algorithms such as convolutional neural networks (CNNs) and recurrent neural
networks (RNNs) have shown promise in handling complex spatial and temporal data.
Leveraging these techniques can improve the predictive capabilities of crop yield models,
especially for crops with intricate growth patterns.
Expanding the geographic coverage of crop yield prediction models to encompass diverse
regions and crops can enhance their applicability and utility. Incorporating data from different
climatic zones and agricultural practices can improve the models' adaptability and accuracy
across varied agricultural landscapes.
Designing user-friendly interfaces and mobile applications can facilitate the adoption of crop
yield prediction tools by farmers and stakeholders. Intuitive dashboards and visualization tools
can empower users to interpret the model outputs effectively and incorporate them into their
decision-making processes.
Continuous refinement and validation of crop yield prediction models are essential to ensure
their accuracy and reliability over time. Incorporating feedback from farmers, agronomists, and
domain experts can help identify areas for improvement and refine the models' performance in
real-world scenarios.
This paper presents the various machine learning algorithms for predicting the yield of the crop
on the basis of weather and other conditions. This project develops a website for predicting
crop yield, weather, and fertilizer recommendation using machine learning algorithms. The
decision tree is found to provide the most accurate predictions for crop yield, weather, and
fertilizer recommendation. The prediction system takes the inputs from the user and provides
the best and most accurate predictive analysis for crop yield. The website also provides
information on the best crop that is suitable and also which particular fertilizers are required
for that crop. Results also revealed that the Random Forest classifier gives the highest weather
prediction and fertilizer recommendation accuracy. These will not only help farmers maintain
the proper crop supply to grow but also in cost management also it can be helpful. It will
empower farmers to make informed decisions regarding crop selection, fertilizer usage, and
overall cost management. The robustness and reliability of our system have been validated
through experiments conducted on a reliable dataset
. REFERENCES
[1] Prameya R Hegde, Ashok Kumar A R, “Crop Yield and Price Prediction System for
Agriculture Application”,International Journal of Engineering Research & Technology
(IJERT) Vol. 11 Issue 07, July-2022. Shangping Wang, Xu Wang, and Yaling Zhang, “A
Secure Cloud Storage Framework with Access Control based on Blockchain”.
[2] E. Manjula, S. Djodiltachoumy, “Model for Prediction of Crop Yield”, International Journal
of Computational Intelligence and Informatics, Vol. 6: No. 4,March 2017
[4] R.B.Saroo Raj, Ankush Rai, Ronit Dharmik, Siddharth Bhattacharjee, ”Weather
Forecasting System using Machine Learning”, International Journal of Emerging Technologies
in Engineering Research (IJETER),Volume 6, Issue 10, October(2018).
[5] Andrew Crane-Droesch,”Machine learning methods for crop yield prediction and climate
change impact assessment in agriculture”, Environ. Res. Lett. 13 (2018)114003.
[6] Potnuru Sai Nishant, Pinapa Sai Venkat, Bollu Lakshmi Avinash3, B. Jabber. “Crop Yield
Prediction based on Indian Agriculture using Machine Learning”, International Conference for
Emerging Technology (INCET) Belgaum, India. Jun 5-7, 2020
[7] Shivani Turamari, Pooja Patil, Mallappa Hallad, Manjunath Bilagi, “Weather Forecast
Prediction for Agriculture”, (IJERT) ISSN: 2278-0181 ,Special Issue - 2022.
[8] Pallavi Shankarrao Mahore, Dr. Aashish A. Bardekar, “Crop Yield Prediction using
Different Machine Learning Techniques”, International Journal of Scientific Research in
Computer Science, Engineering and Information Technology ISSN : 2456- 3307,Volume 7,
Issue 3,May-June- 2021.