CROP & FERTILIZER RECOMANDATION SYSTEM USING ML
CROP & FERTILIZER RECOMANDATION SYSTEM USING ML
USING ML
By
2024
CERTIFICATE
This is to certify that the project report entitled “CROP & FERTILIZER
RECOMANDATION SYSTEM USING ML”being submitted by ASHUTOSH
RAWAT, ANKUR UPADHYAY, ANKIT YADAV, ROHIT KUMAR , Gaurav
Kumer in partial fulfillment for the award of the Degree of Master of Computer
Applications is a record of bonafide work carried out by him under my guidance and
supervision.
[i]
DECLARATION
not formed the basis or submitted for the award of any degree,
university.
Name:
Signatur
e: Place:
Date:
[ii]
ACKNOWLEDGEMENT
On the very outset of this report, we would like to extend our sincere and
heartful obligation towards all the personages who have helped me in this
endeavor. Without their active guidance, help, cooperation and
encouragement, we would not have made headway in the project. We are
extremely thankful and pay our gratitude to our guide Dr. Ashish Saini
for valuable guidance and support on completion of this project in its
presently. We extend our gratitude to Quantum University for giving us
this opportunity. We also acknowledge with a deep sense of reverence,
our gratitude towards our parents and member of our family, who has
always supported us morally as well as economically.
At last, but not the least, gratitude goes to all my friends who directly
or indirectly helped me to complete this project report.
Thanking You
[iii]
TABLE OF CONTENTS
ACKNOWLEDGEMENT iii
TABLE OF CONTENTS iv
LIST OF FIGURES vi
ABSTRACT vii
1. Introduction
1.1 Overview ......................................................................................... 02
1.2 What is crop fertilization and recommendation system..................... 02
1.3Importance of crop fertilization and recommendation system ……...03
2. Literature Review...................................................................................... 05
3. Methodology
3.1 Data Pre-processing ....................................................................... 13
3.2 Splitting dataset into testing and traing data sets…………………....13
3.3 Random Forest……………………………………………………….14
3.4 Support Vector Machine(SVM)……………………………………...14
3.5 Gradient Descent……………………………………………………….15
3.6 Long Short – term memory(LSTM)……………………………………16
3.7 Logistic Regression…………………………………………………….17
3.8 Decision Tree……………….………………………………………….18
3.9 KNN (K- Nearest Neighbors)………………………………………. 19
3.10 Linear Regression……………………………………………………20
[iv]
4. Implementation
4.1 Crop_app.py
4.2 Home_1.html
4.3 index.html
4.4 Prediction.html
4.5 First.css
4.6 My home.css
4.7 Prediction_css.css
5. Conclusion
6. Future Work
7. References
[iv]
TABLE OF FIGURES
02 Yield Forecast 04
03 Data Preprocessing 08
04 Splitting Dataset 09
06 Working of SVM 11
08 Working of LSTM 13
11 Linear Regression 21
12 Working of K-Means 26
[vi]
ABSTRACT
2
Our observations regarding this study are beneficial not only for
researchers in this field but also for practitioners who would like to
develop novel crop yield prediction models for their own usage. For
researchers in this field, the challenges are important since they will
be aware of these issues before they develop their own models. For
practitioners, the development of new crop yield prediction models
involves several challenging steps that are addressed in this SLR
paper. For instance, the selection of model parameters and the
algorithms require critical thinking using the literature.
1.1 OVERVIEW
Nutrient Supply:
Improved Yield:
Soil Health:
Economic Benefits:
Sustainable Agriculture:
Balanced Use: Proper fertilization practices ensure the balanced use of nutrients,
preventing soil degradation and promoting sustainable farming practices.
Environmental Protection: It reduces the risk of nutrient runoff and leaching,
protecting water bodies from contamination.
5
2. LITERATURE REVIEW:-
[1] In this paper SVM method used to classify crop data and CNN is
used to reduce the relative error. By using these, methods losses of
crop yield reduce irrespective of environment distraction.
[3] In this paper Decision tree uses greedy methodology and Random
Forest algorithm used to predict the best crop. It helps the farmers in
decision making of which crop of to cultivate in the field.
[4] In this paper K nearest algorithm, Naïve Bayes and Decision tree
are used to predict the crop yield. It helps the farmers to identify the
yield of crops in different soil and atmospheric conditions.
[5] In this paper J48 and IBK are used for classification, LWL used to
assign instance weights, LAD tree used to classify based on binary
target value. It is useful to the farmers for early prediction and
decision making.
[6] In this paper naïve Bayes and KNN algorithm have been used in
order to achieve maximum crop yield. By this we can also get the
accuracy yield by checking for different method.
6
[7] In this paper LSTM and Simple RNN methods are used to predict
the temperature and rainfall. Finally, we got know to that Random
Forest Regressor will more accuracy.
[8] In this paper Feed Forward Neural and Recurrent Neural Network
techniques is used. Comparing the FNN and RNN based on loss of
error RNN has low error rate at the same it is better for crop yield
prediction.
[9] In this paper they have developed a user friendly webpage and the
accuracy of predictions are above 75 percent by Random Forest
Algorithm.
7
3. METHODOLOGY:-
8
3.2. Splitting Dataset into Testing and Training Sets:
The final step of data preprocessing is testing and training the data.
The train -test- split method has been used to split the data, with the
test set being 2% of the total dataset and the random state set to 71.
9
3.3. Random Forest: Random forest is a very famous machine
learning algorithm that felicitates in cases of both classification and
regression issues. This algorithm works on the notion of ensemble
learning, which works on the principle of merging several classifiers
to give the solution for any complex problem and improve the
precision and performance of the applied model. l. Random Forest is
a classifier that uses numerous decision trees on subsets of a dataset
and takes the average into account to increase the dataset's prediction
accuracy.
10
3.4. Support Vector Machine (SVM): The goal of the support
vector machine algorithm is to discover a hyperplane in N-
dimensional space (N refers to the number of features present in the
dataset) that classifies the data points very distinctly. To detach the
two classes of information points, various possible hyperplanes could
be chosen. Extending the edge distance gives some help so future data
points can be organized with more assurance.
11
3.5. Gradient Descent: Gradient descent is a well-known
optimization algorithm that is frequently used in machine learning and
deep learning. It finds the coefficients that minimize the cost function
as far as possible by identifying a local minimum of the differentiable
function. Gradient descent begins by characterizing the initial
parameter values and then uses analytics and calculus to iteratively
change the values so that they limit the given cost function. The
greater the gradient, the greater the slope, and thus the faster the
model's learning rate.
The following equation describes what the given algorithm does:
𝑏 = 𝑎 − 𝛾∇𝑓(𝑎)
Whereas:
b = next position
a = current position
(-) = The negative sign denotes the minimization component of
gradient descent
𝛾 = gamma denotes the waiting feature and the gradient term
(Δf(a)) = direction of the sharpest decrease.
Key Points:
Logistic regression predicts the output of a categorical dependent
variable. Therefore, the outcome must be a categorical or discrete
value.
It can be either Yes or No, 0 or 1, true or False, etc. but instead of
giving the exact value as 0 and 1, it gives the probabilistic values
which lie between 0 and 1.
In Logistic regression, instead of fitting a regression line, we fit an
“S” shaped logistic function, which predicts two maximum values
(0 or 1).
Sigmoid Function
Now we use the sigmoid function where the input will be z and we
find the probability between 0 and 1. i.e. predicted y.
(𝑧)=11−e−𝑧σ(z)=1−e−z1
Sigmoid function
There are specialized terms associated with decision trees that denote
various components and facets of the tree structure and decision-
making procedure. :
Root Node: A decision tree’s root node, which represents the
original choice or feature from which the tree branches, is the
highest node.
Internal Nodes (Decision Nodes): Nodes in the tree whose choices
are determined by the values of particular attributes. There are
branches on these nodes that go to other nodes.
Leaf Nodes (Terminal Nodes): The branches’ termini, when
choices or forecasts are decided upon. There are no more branches
on leaf nodes.
Branches (Edges): Links between nodes that show how decisions
are made in response to particular circumstances.
Splitting: The process of dividing a node into two or more sub-
nodes based on a decision criterion. It involves selecting a feature
and a threshold to create subsets of data.
Parent Node: A node that is split into child nodes. The original
node from which a split originates.
Child Node: Nodes created as a result of a split from a parent node.
Decision Criterion: The rule or condition used to determine how
the data should be split at a decision node. It involves comparing
feature values against a threshold.
Pruning: The process of removing branches or nodes from a
decision tree to improve its generalisation and prevent overfitting.
Understanding these terminologies is crucial for interpreting and
working with decision trees in machine learning applications.
The dataset is divided into two parts, namely, feature matrix and
the response vector.
4.1 Crop_app.py
import joblib
from flask import Flask, render_template,request,redirect
#from flask import Flask, render_template, request, redirect
app = Flask(__name__)
@app.route('/')
def home():
return render_template('Home_1.html')
@app.route('/Predict')
def prediction():
return render_template('Index.html')
@app.route('/form', methods=["POST"])
def brain():
Nitrogen=float(request.form['Nitrogen'])
Phosphorus=float(request.form['phosphorus'])
Potassium=float(request.form['potassium'])
Temperature=float(request.form['temperature'])
Humidity=float(request.form['humidity'])
Ph=float(request.form['ph'])
Rainfall=float(request.form['rainfall'])
values=[Nitrogen,Phosphorus,Potassium,Temperature,Humidity,Ph,Rainfall]
4.2 Home_1.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Crop Recommendation System</title>
<style>
body{
background-image:url(./one.jpg);
background-repeat: no-repeat;
background-size: cover;
}
padding: 20px;}
nav ul {
list-style: none;
margin: 0;
padding: 0;
text-decoration: none;
display: flex;
justify-content: space-between;
color:#ffff;
}
nav li {
display: inline-block;
margin-right: 20px;
text-decoration: none;
}
nav ul li a{
color:#ffff;
text-decoration: none;
}
main {
text-align: center;
padding: 50px;
}
h1 {
font-size: 36px;
margin-bottom: 20px;
}
p {
font-size: 16px;
color: rgb(218, 213, 213);
}
h3 {
font-size: 20px;
color: rgb(224, 221, 221);
}
h2 {
font-size: 25px;
color: rgb(218, 216, 216);
}
form{text-align: center;}
input{color: gold;
background-color: black;
font-size: 25px;
font-weight: bold;
width: 10%;
border-radius: 5%;
font-family: Arial, Helvetica, sans-serif;}
#p{
color: black;
font-size: 23px;
font-weight: 500;
}
</style>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<h1>Crop Recommendation System</h1>
<p id="p">RS Farming Welcomes you on our website, Hope you are earning
well from your farm
but we are here for you to provide some suggetions about your crop
cultivation
We recommends you to which crop you should grow in your farm for better
yields. Its
very easy to predict which crop you should grow on the basis of your
soil nutrients
just you need to know your soil nutrients for this you can test your
soil in lab.</p>
<br>
<h3 style="color: black;">Let's Start New Journey With RS Farming</h3>
<br>
<h2 style="color: black;">Click following button for Crop
recommandation</h2>
</main>
<form action="/Predict">
<input style="cursor: pointer;" type="submit" id="Predict"
name="Predict" action="/Predict" value="Predict">
</form>
</body>
</html>
4.3 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>crop Recommendation System</title>
<style>
body{background-image:url(./image.jpg);
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<form action="/form" method="POST">
<label for="Nitrogen">Nitrogen:</label>
<input type="text" id="Nirogen" name="Nitrogen" min="0" max="100"
placeholder="Nitrogen" required><br><br>
<label for="phosphorus">phosphorus:</label>
<input type="text" id="phosphorus" name="phosphorus" min="0" max="100"
placeholder="Phosphorus" required><br><br>
<label for="potassium">potassium:</label>
<input type="text" id="potassium" name="potassium" min="0" max="100"
placeholder="Potassium" required><br><br>
<label for="temperature">temperature:</label>
<input type="text" id="temperature" name="temperature" min="0" max="100"
placeholder="Temperature in Degree Celcius" required><br><br>
<label for="humidity">humidity:</label>
<input type="text" id="humidity" name="humidity" min="0" max="100"
placeholder="Relative Humidity in Percentage" required><br><br>
<label for="ph">ph:</label>
<input type="text" id="ph" name="ph" min="0" max="14" placeholder="ph should
be in between 0-14" required><br><br>
<label for="rainfall">rainfall:</label>
<input type="text" id="rainfall" name="rainfall" placeholder="Rainfall in
MM" required min="0" max="10000"><br><br>
</body>
</html>
4.4 Prediction.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>crop recommandation System</title>
<style>
body {
background-color: blanchedalmond;
background-size: cover;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
font-size: 36px;
color:greenyellow;
font-family: Arial, sans-serif;
text-shadow: 2px 2px #333;
}
</style>
</head>
<body>
<h4>According to your soil neutrients</h4>
<h4> You Should Grow -> </h4>
<br>
<br>
<h4>{{prediction}}</h4>
</body>
</html>
4.5 first.css
body {
background-image:url(prediction_back.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
form {
width: 500px;
margin: 0 auto;
text-align: center;
padding: 20px;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 10px;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-top: 10px;
border-radius: 5px;
border: none;
}
input[type="submit"] {
width: 100%;
padding: 10px;
margin-top: 10px;
border-radius: 5px;
border: none;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
label {
font-size: 16px;
margin-top: 20px;
display: block;
}
4.6 Myhome.css
input[type="submit"] {
display: block;
margin: 0 auto;
width: 100px;
padding: 10px;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
body {
background-image: url(one.jpg);
background-size: cover;
background-repeat: no-repeat;
}
header {
background-color: #333;
color: white;
padding: 20px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
}
nav li {
display: inline-block;
margin-right: 20px;
}
nav a {
color: white;
text-decoration: none;
}
main {
text-align: center;
padding: 50px;
}
h1 {
font-size: 36px;
margin-bottom: 20px;
}
p {
font-size: 16px;
color: rgb(218, 213, 213);
}
h3 {
font-size: 20px;
color: rgb(224, 221, 221);
}
h2 {
font-size: 25px;
color: rgb(218, 216, 216);
}
4.7 Prediction_css.css
body {
background-image: url('image.jpg');
background-size: cover;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
font-size: 36px;
color: white;
font-family: Arial, sans-serif;
text-shadow: 2px 2px #333;
}
5. CONCLUSION:-
Based on all the discussions and analyses, it is clear that the machine
learning models used – Random Forest, Support Vector Machine
(SVM), and Lasso Regression – outperform the deep learning models
used – Gradient Descent and long short – Term Memory (LSTM) – in
terms of accuracy. This could be because, when compared to other
models, models like LSTM require a larger quantum of data for a
better predictive analysis. Furthermore, based on the observations,
most of the models perform better on the specified parameters, where
as models such as Gradient Descent and Lasso Regression perform
better when applied to the dataset with all of the characteristic. While
soil and rainfall quantity are important in crop production and general
farming, it can be concluded that a deeper investigation of these
elements, as well as a larger database, is required for real-life research
of such elements using prediction models. Finally, it can be concluded
that the Random Forest algorithm outperforms all other models when
applied to any of the datasets. The current research can be extended
into performing further analysis and forecasting the factors that
influence crop yield. A larger dataset and more historically accurate
data about the environment and weather during each crop year is
required to identify best performing model between deep learning and
machine learning models. To find the best- performing technique,
more deep learning models need to be tested on the datasets. In the
field of crop yield prediction, remote sensing data could be merged
with the district-level statistical data to improve the model’s
performance.
6 Future Work
Advanced Crop Fertilization Techniques
1. Precision Agriculture:
o Variable Rate Technology (VRT): Implementing VRT to apply fertilizers at
variable rates across a field based on soil nutrient levels and crop
requirements.
o Remote Sensing and Drones: Using drones equipped with sensors to monitor
crop health and soil conditions, enabling precise application of fertilizers.
2. Organic and Sustainable Fertilizers:
o Biofertilizers: Researching and developing biofertilizers that use beneficial
microbes to enhance soil fertility.
o Organic Amendments: Promoting the use of organic matter such as compost
and manure to improve soil structure and nutrient content.
3. Integrated Nutrient Management (INM):
o Combining Organic and Inorganic Fertilizers: Developing strategies that
combine the use of organic and inorganic fertilizers to optimize nutrient
availability and soil health.
o Nutrient Recycling: Investigating methods for recycling nutrients from
agricultural waste and other organic materials back into the soil.
4. Smart Fertilizers:
o Controlled-Release Fertilizers: Advancing the development of fertilizers that
release nutrients slowly over time, matching the crop's growth cycle.
o Nano-fertilizers: Exploring the use of nanotechnology to create fertilizers that
improve nutrient uptake efficiency.
[1] Kavita, and Pratistha Mathur. (2021) “Satelite - Based Crop Yield
Prediction Using Machine Learning Algorithm. “In 2021 Asian
Conference on Invocation in Technology (ASIANCON), 1-5
dio:10.1109/ASIANCON5146.2021.9544562.
[2] Bali, Nishu, and Anshu Singla. (2022) “Emerging Trends in
Machine Learning to Predict Crop Yield and Study Its Influential
Factors: A Survey.” Archives of Computational Methods in
Engineering 29 (1): 95–112. doi:10.1007/s11831-021-09569-8.
[3] van Klompengs, Thomas, Ayalew Kassahun, and Cagatay Cate.
(2020) “Crop Yield Prediction Using Machine Learning: A
Systematic Literature Review.” Computers and Electronics in
Agriculture 177 (October): 105709.
doi:10.1016/j.compag.2020.105709.
[12] Shen, Dinggang, Guorong Wu, and Heung-Il Suk. (2017) “Deep
Learning in Medical Image Analysis.” Annual Review of Biomedical
Engineering 19 (1): 221–248. doi:10.1146/annurev-bioeng-071516-
044442.