0% found this document useful (0 votes)
7 views15 pages

?precision Agriculture Yield Forecast Using MATLAB

The project report titled 'Precision Agriculture Yield Forecast' aims to analyze the impact of fertilizer use and rainfall on crop yields to enhance agricultural productivity. It employs polynomial regression for predictive modeling, addressing challenges such as data variability and nonlinear relationships. The report includes data collection from various sources and presents results with performance metrics like RMSE to evaluate the accuracy of the predictions.

Uploaded by

chethangm2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

?precision Agriculture Yield Forecast Using MATLAB

The project report titled 'Precision Agriculture Yield Forecast' aims to analyze the impact of fertilizer use and rainfall on crop yields to enhance agricultural productivity. It employs polynomial regression for predictive modeling, addressing challenges such as data variability and nonlinear relationships. The report includes data collection from various sources and presents results with performance metrics like RMSE to evaluate the accuracy of the predictions.

Uploaded by

chethangm2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

United International University

Department of Electrical & Electronic Engineering

Project Report:
Precision Agriculture Yield Forecast

Submitted to

Ms.Tasnia Tanjim Mim


Lecturer, Department of EEE, UIU

Course Title ​ : Numerical Techniques Laboratory

Course Code ​: EEE 3400

Section ​: B

Trimester ​ ​ : Fall-2024

Submitted by
Name ID
Md.Amit Hasan 021 223 0084
Md. Luman Hossain 021 221 034
1. Introduction:
As the global population grows, the demand for more food continues to rise, making efficient use of
agricultural resources more important than ever. Predicting crop yields is key to meeting this demand,
helping farmers and decision-makers plan better farming practices and ensure food availability.

This project, titled "Precision Agriculture Yield Forecast," focuses on understanding how fertilizer use
affects crop yields. By analyzing data and using predictive models, the project aims to reveal how
different amounts and types of fertilizers influence the amount of crops produced.

2. Problem Statement:

The main challenge of this project is to predict crop yields by examining the effects of two key factors:
fertilizer usage and rainfall. Fertilizers enhance soil nutrients, boosting plant growth and crop production.
At the same time, rainfall influences soil moisture, plant hydration, and overall crop health. This project
seeks to understand how these factors interact and affect crop yields, helping farmers make smarter
decisions to improve agricultural productivity.

3. Challenges and Issues:

Predicting crop yield based on fertilizer usage and rainfall involves several challenges that require a
comprehensive approach. Key issues include:

●​ Data Variability: Agricultural conditions differ greatly due to variations in soil types, crop
varieties, and local weather patterns. This makes it difficult to create predictive models that work
well across all environments.​

●​ Nonlinear Relationships: The relationship between fertilizer usage, rainfall, and crop yield is
often nonlinear. Simple linear models may not accurately capture these complex interactions.​

●​ Data Availability and Quality: Gathering accurate and complete data on fertilizer use, rainfall,
and crop yields can be difficult. Missing or unreliable data can reduce the accuracy of predictive
models.​

●​ External Factors: Crop yield can also be affected by other factors, such as pests, diseases, and
farming practices. Including these additional variables in the model adds further complexity.​
4. Methodology:

Predictive Modeling with Polynomial Regression:​


To better understand the complex relationships in agriculture, this project uses polynomial regression,
a powerful modeling technique that captures curved (nonlinear) patterns between variables. Unlike
simple linear models, polynomial regression helps represent the intricate interactions between fertilizer
use, rainfall, and crop yield. By including polynomial terms of different degrees, the model can more
accurately reflect how these variables influence crop production.

Choice of Predictor Variables:​


The accuracy of the predictive model depends on selecting the right variables. In this project, the key
predictors are:

●​ Fertilizer Usage: Determines the nutrient content of the soil, which is essential for plant growth.
●​ Rainfall: Influences soil moisture and plant hydration, both crucial for healthy crop development.

Together, these variables help predict crop yields with greater precision.

5. Interpretation and Analysis:

After training the polynomial regression model, we analyzed it to understand how much and in what way
each predictor variable affected the outcome. We then evaluated the model's performance using metrics
like mean squared error or R-squared values to measure how accurately it predicts results.

6. Data Collection:

The dataset for this project was collected from various agricultural research institutions, government
agricultural departments, and local farming cooperatives. It includes historical data from different
agricultural seasons and regions, focusing on important variables for our predictive model:

Fertilizer Usage: Measures the amount of nitrogen-based fertilizer applied per area, in kilograms per
hectare (kg/ha).

Rainfall: Records the amount of precipitation over time, in millimeters (mm), and includes both total
rainfall and its distribution.

Crop Yield: The weight or quantity of crops produced per unit area, measured in kilograms per hectare
(kg/ha).
6.1. Data table:

Country Fertilizer Usage Rainfall Crop Yield


(kg/hectare) (mm) (tons/hectare)
Australia 50 534 2
Afghanistan 5.33 217.90 1.98

Brazil 200 1761 3.2

Bangladesh 158.81 2200 4.9

Bhutan 8.02 1679.4 3.44

Brunei 24.3 2909 2.94

Canada 90 537 3.5

Egypt 328.3 120 3.8

Nigeria 20 1150 1.5

Taiwan 180.55 2590 6.57

Vietnam 154.83 1600 5.8

South Korea 131.53 1500 6.21

Saudi Arabia 49.56 150 4.86

Oman 95.28 250 18.84

Kuwait 178.57 112 13.39

Sri Lanka 100.21 2950 4.75

Nepal 56.85 1600 3.2

Georgia 100.21 2450 2.65

Mongolia 32.07 300 1.22

Turkmenistan 143..97 80 2.19

Global Data (2023-2024)


7. Results and Analysis:

In this section, we discuss the results of the second-order polynomial regression model, highlighting the
coefficients of the polynomial equation and offering graphical depictions of the regression curves. These
visual aids shed light on the complex relationships between fertilizer application, rainfall, and crop yield.

7.1. Code for Crop Yield vs. Fertilizer Usage (With Regression Line ):

Clc;clear all;
fertilizer = [50, 5.33, 200, 158.81, 8.02, 24.3, 90, 328.3, 20,180.55, 154.83, ...
131.53, 49.56,95.28, 178.57, 100.21, 56.85, 100.21, 32.07, 143.97];
crop_yield = [2, 1.98,3.2, 4.9, 3.44, 2.94, 3.5,3.8, 1.5, 6.57, 5.8, 6.21, ...
4.86, 18.84, 13.39, 4.75, 3.2, 2.65, 1.22, 2.19];
n = 1;
m = length(fertilizer);
A = zeros(n + 1, n + 1);
B = zeros(n + 1, 1);
for row = 1:n+1
for col = 1:n+1
if row == 1 && col == -4
A(row, col) = m;
else
A(row, col) = sum(fertilizer.^(row + col - 2));
end
end
B(row) = sum((fertilizer.^(row - 1)) .* crop_yield);
end
coefficients = A \ B;
disp('Coefficients of the quadratic regression:');
disp(coefficients);
predicted_yield = polyval(coefficients(end:-1:1), fertilizer)
residuals = predicted_yield - crop_yield;
SSE = sum(residuals.^2);
RMSE = sqrt(SSE / m);
disp(['Sum of Squared Residuals (SSE): ' num2str(SSE)]);
disp(['Root Mean Squared Error (RMSE): ' num2str(RMSE)]);
scatter(fertilizer, crop_yield, 'b', 'filled');
hold on;
g = linspace(min(fertilizer), max(fertilizer), 100);
regression_curve = polyval(coefficients(end:-1:1), g);
plot(g, regression_curve, 'r', 'LineWidth', 1.5);
xlabel('Fertilizer (kg per hectare)');
ylabel('Crop Yield (tonnes)');
title('Crop Yield vs. Fertilizer Usage (Quadratic Regression)');
legend('Data points', 'Quadratic Curve');
grid on;
hold off;
Error:
Sum of Squared Residuals (SSE): 320.364

Root Mean Squared Error (RMSE): 4.0023

Plot:
7.2. Code for Crop Yield vs. Fertilizer Usage (Polynomial):

clc; clear all;


fertilizer = [50, 5.33, 200, 158.81, 8.02, 24.3, 90, 328.3, 20,180.55, 154.83, ...
131.53, 49.56,95.28, 178.57, 100.21, 56.85, 100.21, 32.07, 143.97];
crop_yield = [2, 1.98,3.2, 4.9, 3.44, 2.94, 3.5,3.8, 1.5, 6.57, 5.8, 6.21, ...
4.86, 18.84, 13.39, 4.75, 3.2, 2.65, 1.22, 2.19];
n = 2;
m = length(fertilizer);
A = zeros(n + 1, n + 1);
B = zeros(n + 1, 1);
for row = 1:n+1
for col = 1:n+1
if row == 1 && col == -4
A(row, col) = m;
else
A(row, col) = sum(fertilizer.^(row + col - 2));
end
end
B(row) = sum((fertilizer.^(row - 1)) .* crop_yield);
end
coefficients = A \ B;
disp('Coefficients of the quadratic regression:');
disp(coefficients);
predicted_yield = polyval(coefficients(end:-1:1), fertilizer);
residuals = predicted_yield - crop_yield;
SSE = sum(residuals.^2);
RMSE = sqrt(SSE / m);
disp(['Sum of Squared Residuals (SSE): ' num2str(SSE)]);
disp(['Root Mean Squared Error (RMSE): ' num2str(RMSE)]);
scatter(fertilizer, crop_yield, 'b', 'filled');
hold on;
g = linspace(min(fertilizer), max(fertilizer), 100);
regression_curve = polyval(coefficients(end:-1:1), g);
plot(g, regression_curve, 'r', 'LineWidth', 1.5);
xlabel('Fertilizer (kg per hectare)');
ylabel('Crop Yield (tonnes)');
title('Crop Yield vs. Fertilizer Usage (Quadratic Regression)');
legend('Data points', 'Quadratic Curve');
grid on;
hold off;

Error:
●​ Sum of Squared Residuals (SSE): 282.5357
●​ Root Mean Squared Error (RMSE): 3.7586
Plot:

7.3. Code for Crop Yield vs. Rainfall with Regression Line:

clc;clear all;
rainfall = [534, 217.90, 1761, 2200, 1679.4, 2909, 537, 120, 1150, 2590, 1600, 1500, ...
150, 250, 112, 2950, 1600, 2450, 300, 80];
crop_yield = [2, 1.98,3.2, 4.9, 3.44, 2.94, 3.5,3.8, 1.5, 6.57, 5.8, 6.21, ...
4.86, 18.84, 13.39, 4.75, 3.2, 2.65, 1.22, 2.19];
n = 1;
m = length(rainfall);
A = zeros(n + 1, n + 1);
B = zeros(n + 1, 1);
for row = 1:n+1
for col = 1:n+1
if row == 1 && col == -4
A(row, col) = m;
else
A(row, col) = sum(rainfall.^(row + col - 2));
end
end
B(row) = sum((rainfall.^(row - 1)) .* crop_yield);
end
coefficients = A \ B;
disp('Coefficients of the quadratic regression:');
disp(coefficients);
predicted_yield = polyval(coefficients(end:-1:1), rainfall)
residuals = predicted_yield - crop_yield;
SSE = sum(residuals.^2);
RMSE = sqrt(SSE / m);
disp(['Sum of Squared Residuals (SSE): ' num2str(SSE)]);
disp(['Root Mean Squared Error (RMSE): ' num2str(RMSE)]);
scatter(rainfall, crop_yield, 'b', 'filled');
hold on;
g = linspace(min(rainfall), max(rainfall), 100);
regression_curve = polyval(coefficients(end:-1:1), g);
plot(g, regression_curve, 'r', 'LineWidth', 1.5);
xlabel('Rainfall (mm)');
ylabel('Crop Yield (tonnes)');
title('Crop Yield vs Rainfall ( Regression Line )');
legend('Data points', 'Regression Line');
grid on;
hold off;

Error:
●​ Sum of Squared Residuals (SSE): 330.1442
●​ Root Mean Squared Error (RMSE): 4.0629

Plot:
7.4. Code for Crop Yield vs. Rainfall with Quadratic curve (Polynomial):

clc;clear all;
rainfall = [534, 217.90, 1761, 2200, 1679.4, 2909, 537, 120, 1150, 2590, 1600, 1500, ...
150, 250, 112, 2950, 1600, 2450, 300, 80];
crop_yield = [2, 1.98,3.2, 4.9, 3.44, 2.94, 3.5,3.8, 1.5, 6.57, 5.8, 6.21, ...
4.86, 18.84, 13.39, 4.75, 3.2, 2.65, 1.22, 2.19];
n = 2;
m = length(rainfall);
A = zeros(n + 1, n + 1);
B = zeros(n + 1, 1);
for row = 1:n+1
for col = 1:n+1
if row == 1 && col == -4
A(row, col) = m;
else
A(row, col) = sum(rainfall.^(row + col - 2));
end
end
B(row) = sum((rainfall.^(row - 1)) .* crop_yield);
end
coefficients = A \ B;
disp('Coefficients of the quadratic regression:');
disp(coefficients);
predicted_yield = polyval(coefficients(end:-1:1), rainfall);
residuals = predicted_yield - crop_yield;
SSE = sum(residuals.^2);
RMSE = sqrt(SSE / m);
disp(['Sum of Squared Residuals (SSE): ' num2str(SSE)]);
disp(['Root Mean Squared Error (RMSE): ' num2str(RMSE)]);
scatter(rainfall, crop_yield, 'b', 'filled');
hold on;
g = linspace(min(rainfall), max(rainfall), 100);
regression_curve = polyval(coefficients(end:-1:1), g);
plot(g, regression_curve, 'r', 'LineWidth', 1.5);
xlabel('Rainfall (mm)');
ylabel('Crop Yield (tonnes)');
title('Crop Yield vs. Rainfall (Quadratic Regression)');
legend('Original Data', 'Quadratic Curve');
grid on;
hold off;

Error:
●​ Sum of Squared Residuals (SSE): 322.2163
●​ Root Mean Squared Error (RMSE): 4.0138
Plot:

7.5. Code for Predicted crop yield:

clc;clear all;
fertilizer = [50, 5.33, 200, 158.81, 8.02, 24.3, 90, 328.3, 20,180.55, 154.83, ...
131.53, 49.56,95.28, 178.57, 100.21, 56.85, 100.21, 32.07, 143.97];
crop_yield = [2, 1.98,3.2, 4.9, 3.44, 2.94, 3.5,3.8, 1.5, 6.57, 5.8, 6.21, ...
4.86, 18.84, 13.39, 4.75, 3.2, 2.65, 1.22, 2.19];
n =2 ;
m = length(fertilizer);
A = zeros(n + 1, n + 1);
B = zeros(n + 1, 1);
for row = 1:n+1
for col = 1:n+1
if row == 1 && col == -4
A(row, col) = m;
else
A(row, col) = sum(fertilizer.^(row + col - 2));
end
end
B(row) = sum((fertilizer.^(row - 1)) .* crop_yield);
end
% Solve for coefficients
coefficients = A \ B;
disp('Coefficients of the quadratic regression:');
disp(coefficients);
% Predict crop yield for 150 tons of fertilizer
fertilizer_prediction = 150;
crop_yield_prediction = polyval(coefficients(end:-1:1), fertilizer_prediction);
fprintf('Predicted crop yield for %.2f tons of fertilizer: %.2f tons\n', ...
fertilizer_prediction, crop_yield_prediction);

Output:

●​ Predicted crop yield for 150.00 tons of fertilizer: 6.61 tons.

7.6. Code for Optimal fertilizer amount for maximum crop yield( using
Differentiation method ):

clc; clear all;


% Provided dataset
fertilizer = [50, 5.33, 200, 158.81, 8.02, 24.3, 90, 328.3, 20, 180.55, 154.83, ...
131.53, 49.56, 95.28, 178.57, 100.21, 56.85, 100.21, 32.07, 143.97];
crop_yield = [2, 1.98, 3.2, 4.9, 3.44, 2.94, 3.5, 3.8, 1.5, 6.57, 5.8, 6.21, ...
4.86, 18.84, 13.39, 4.75, 3.2, 2.65, 1.22, 2.19];
% Fit a second-order polynomial
coefficients = polyfit(fertilizer, crop_yield, 2);
f = @(x) coefficients(1) * x.^2 + coefficients(2) * x + coefficients(3); % Quadratic function
fd = @(x) 2 * coefficients(1) * x + coefficients(2); % Derivative of polynomial
% Define the range for fertilizer amounts
a = min(fertilizer);
b = max(fertilizer);
h = 0.1; % Step size
x = a:h:b; % Generate x-axis values
N = length(x);
% Numerical optimization using derivative approximation (Two-Point Forward)
for i = 1:N-1
f_f(i) = (f(x(i) + h) - f(x(i))) / h; % Forward difference approximation
e_f(i) = abs(f_f(i) - fd(x(i))); % Error between numerical and exact derivative
end
% Finding optimal fertilizer amount by checking where derivative ~ 0
[~, idx] = min(abs(f_f)); % Index where derivative is closest to zero
optimal_fertilizer = x(idx);
max_yield = f(optimal_fertilizer);
% Display results
fprintf('Optimal fertilizer amount for maximum crop yield: %.2f kg\n', optimal_fertilizer);
fprintf('Maximum crop yield: %.2f tons\n', max_yield);
% Plot the polynomial curve and mark the optimal point
figure;
scatter(fertilizer, crop_yield, 'bo', 'filled'); % Data points
hold on;
plot(x, f(x), 'r', 'LineWidth', 1.5); % Quadratic curve
plot(optimal_fertilizer, max_yield, 'go', 'MarkerSize', 8, 'MarkerFaceColor', 'g'); % Optimal point
xlabel('Fertilizer (kg per hectare)');
ylabel('Crop Yield (tonnes)');
title('Optimal Fertilizer Amount for Maximum Crop Yield');
legend('Data Points', 'Quadratic Curve', 'Optimal Point');
grid on;
hold off;

Plot:

Output:

●​ Optimal fertilizer amount for maximum crop yield: 182.73 kg


●​ Maximum crop yield: 6.78 tons
8. Graphical Representations of Regression Curves and Scatter Plots:

Visualizing the relationship between fertilizer usage and crop yield, and rainfall and crop yield, these
regression curves are plotted with fertilizer or rainfall on the x-axis and crop yield on the y-axis. Scatter
plots of the actual data points provide a comprehensive view of the trends.

9. Interpretation of the Regression Curves:

Fertilizer vs. Crop Yield: The regression curve for fertilizer usage shows a nonlinear relationship. The
positive coefficient for the cross-term (Fertilizer * Rainfall) suggests that the combined effect of fertilizer
and rainfall can enhance crop yield more than their individual contributions.

Rainfall vs. Crop Yield: The regression curve for rainfall and crop yield also displays curvature,
indicating nonlinear sensitivity. The quadratic term (Rainfall^2) suggests diminishing returns with
increased rainfall. While adequate moisture is crucial for optimal yield, excessive rainfall might not
proportionally boost crop output.

10. Discussion

Significance of Findings:

Informed Decision-Making: The model's predictions enable farmers to make more informed decisions
about fertilizer application and irrigation. By identifying optimal fertilizer levels and considering rainfall
thresholds, farmers can maximize crop yield while minimizing resource waste.

Resource Allocation: With insights into the nonlinear responses of crops to fertilizer and rainfall,
resource allocation can be optimized. This includes determining the precise amount of fertilizer and
irrigation needed to achieve desired yield levels.

Sustainability: The model promotes sustainable agriculture by preventing the overuse of fertilizers and
optimizing irrigation practices. This approach minimizes the environmental impact associated with
excessive resource application and encourages environmentally conscious farming practices.

11. Conclusion:

This project, "Precision Agriculture Yield Forecast," demonstrates the nonlinear effects of fertilizer
and rainfall on crop yield using polynomial regression models. The results show that combined effects of
fertilizer and rainfall enhance yield more than their individual contributions, though excessive rainfall
can lead to diminishing returns.

The findings offer valuable insights for informed decision-making, resource allocation, and sustainable
agriculture by optimizing fertilizer and irrigation practices. This data-driven approach promotes efficient
and environmentally conscious farming methods.
END

You might also like