← Back to Table of Contents
Chapter 03

Machine Learning Fundamentals

3.1 Introduction to Machine Learning for Agriculture

Machine learning (ML) enables computers to learn patterns from data without being explicitly programmed. In agriculture, ML algorithms learn relationships between factors like weather, soil, and inputs to predict crop yields.

Why ML for Yield Prediction?

3.2 Types of Machine Learning

Supervised Learning

The algorithm learns from labeled training data (historical yields with known outcomes). This is the primary approach for yield prediction.

Example: Given 10 years of weather and yield data, predict next year's yield.

Unsupervised Learning

Finds patterns in data without labels. Useful for clustering similar farms or identifying yield anomalies.

Time Series Forecasting

Specialized technique for sequential data over time, accounting for trends and seasonality.

3.3 Regression Models

Regression predicts continuous values (like yield in kg/ha).

Linear Regression

Simplest form: assumes linear relationship between inputs and yield.

yield = β₀ + β₁×rainfall + β₂×temperature + β₃×fertilizer + ε

Pros: Simple, interpretable, fast
Cons: Too simplistic for complex agricultural systems

Polynomial Regression

Extends linear regression with polynomial terms to capture non-linear relationships:

yield = β₀ + β₁×temp + β₂×temp² + β₃×rain + β₄×rain² + ...

Ridge and Lasso Regression

Regularized regression that prevents overfitting by penalizing large coefficients.

3.4 Tree-Based Models

Decision Trees

Creates a tree of if-then rules based on feature values.

Example tree logic:

If rainfall > 800mm:
  If temperature < 25°C:
    Predict 5200 kg/ha
  Else:
    Predict 4800 kg/ha
Else:
  Predict 4200 kg/ha

Random Forest

Ensemble of many decision trees, averaging their predictions. Excellent for yield prediction due to:

Gradient Boosting (XGBoost, LightGBM)

Builds trees sequentially, each correcting errors of previous ones. Often achieves highest accuracy for yield prediction.

3.5 Neural Networks

Feedforward Neural Networks

Multi-layer networks that learn complex non-linear patterns.

LSTM (Long Short-Term Memory)

Recurrent neural network variant excellent for time series yield prediction. Remembers long-term patterns across seasons.

Architecture for yield prediction:

Input: [5 years × weather/soil/input data]
  ↓
LSTM Layer (128 units)
  ↓
LSTM Layer (64 units)
  ↓
Dense Layer (32 units)
  ↓
Output: Predicted yield

3.6 Time Series Analysis

ARIMA Models

AutoRegressive Integrated Moving Average - classical time series method.

ARIMA(p,d,q) where:

Seasonal Decomposition

Separates yield data into:

3.7 Model Selection Guidelines

Model TypeBest ForTypical Accuracy
Linear RegressionBaseline, interpretabilityR² 0.65-0.75
Random ForestGeneral purpose, robustR² 0.80-0.88
Gradient BoostingHighest accuracyR² 0.85-0.92
LSTMTime series, trendsR² 0.82-0.90
Recommendation: Use an ensemble combining Random Forest (40%), Gradient Boosting (30%), LSTM (20%), and Ridge Regression (10%) for optimal results.