Yield Prediction: My Thesis Project on Predicting Crop Yields Using Machine Learning

Machine LearningFeb 2025By Tinotenda Linton

Machine learning thesis comparing Random Forest, XGBoost, and neural networks to forecast maize and soyabean yields in Zimbabwe.

PythonTensorFlowscikit-learnXGBoostRandom ForestArtificial Neural NetworksArt Neural Networks

Machine learning model designed to predict maize and soyabean yields in Mashonaland West, Zimbabwe.
This project compares multiple algorithms - including Random Forest, XGBoost, ANN, and Linear Regression - to identify the most accurate approach for agricultural forecasting.

Introduction

Agriculture is the backbone of Zimbabwe's economy, yet climate variability, poor farming practices, and limited technology adoption have contributed to declining crop yields.

The goal of this thesis project was to leverage machine learning to predict yields for maize and soyabeans, two staple crops, while identifying the most influential factors driving productivity.

Research Aim

To perform a comparative analysis of XGBoost, Linear Regression, Random Forest, and Artificial Neural Network models for predicting crop yields in Mashonaland West.

Research Objectives

  1. Identify the main factors influencing maize and soyabean crop yields.
  2. Design and implement yield prediction models using XGBoost, Linear Regression, Random Forest, and ANN.
  3. Compare model performance using standard evaluation metrics.
  4. Recommend the best-performing model for real-world use.

Methodology

This study followed the CRISP-DM framework:

  • Data Collection: Climatic, management, and crop-specific data were gathered from the seven districts of Mashonaland West - Chegutu, Hurungwe, Kadoma, Kariba, Makonde, Mhondoro-Ngezi, and Zvimba.
  • Data Preprocessing: Cleaning, normalization, and encoding were applied to ensure compatibility with ML algorithms.
  • Model Training: Implemented in Python using scikit-learn, xgboost, and tensorflow.
  • Model Evaluation: Compared using MSE, MAE, and R-score.

Records distribution chart (coming soon).

Dataset Features

  • Climatic: Rainfall, temperature, humidity
  • Management: Fertilizer, pesticide, herbicide usage
  • Crop-specific: Area under cultivation, farming scale (small-scale, large-scale, A2)

Models Implemented

  1. Linear Regression (LR) - interpretable baseline.
  2. Random Forest (RF) - strong ensemble method for non-linear data.
  3. XGBoost (XGB) - optimized gradient boosting for high accuracy.
  4. Artificial Neural Network (ANN) - deep learning approach for complex relationships.

Evaluation Metrics

  • MSE - Mean Squared Error
  • MAE - Mean Absolute Error
  • R-score - Explained variance

Results

ModelR-score
Random Forest0.8753
XGBoost0.8709
ANN0.8481
Linear Regression0.7254

Base models evaluation chart (coming soon).

Key Insights

  • Random Forest achieved the highest accuracy (R = 0.8753).
  • XGBoost was a close second, making it a strong alternative.
  • ANN showed potential but required more tuning.
  • Linear Regression underperformed due to non-linearity in data.

Feature Importance

Feature importance analysis revealed that area under cultivation, farming scale, and pesticide/herbicide value were the most significant predictors.

Feature importance plot (coming soon).

Conclusions

  • Best Model: Random Forest for yield prediction in Mashonaland West.
  • Practical Use: Supports data-driven agricultural planning and precision farming.
  • Policy Recommendations:
    • Promote climate resilience strategies.
    • Increase technology adoption for farmers.
    • Expand agricultural data collection programs.

Video Demo

Installation & Usage

Prerequisites

  • Python 3.8+
  • Jupyter Notebook
  • Libraries: numpy, pandas, scikit-learn, xgboost, tensorflow, matplotlib, seaborn

Setup

git clone https://github.com/tinolinton/Yield-Predictive-Model.git
cd Yield-Predictive-Model
pip install -r requirements.txt
jupyter notebook