Statistical crop yield predictor for Kwara State farmers — OLS from scratch + Bayesian uncertainty
# Statistical Agricultural Yield Predictor
### Kwara State, Nigeria — Phase 1 AI Engineering Project
> *Farmers in Kwara State have no data-driven way to estimate crop yields.*
> *This project builds a statistical model using regression fundamentals and*
> *Bayesian probability to predict yield based on rainfall, temperature, soil pH,*
> *and fertilizer application data.*
---
## Problem Statement
Agricultural planning in Kwara State, Nigeria relies heavily on intuition and historical memory.
This project demonstrates how statistical modeling — built from mathematical first principles —
can give farmers and agricultural planners a data-driven yield estimate with calibrated uncertainty bounds.
---
## Technical Approach
### 1. OLS Regression (From Scratch)
Implemented using the **Normal Equation** with NumPy only:
$$\theta = (X^TX)^{-1}X^Ty$$
No scikit-learn in the core model. This validates mathematical understanding before reaching for abstractions.
### 2. Bayesian Linear Regression
Extended OLS with a conjugate Normal prior to produce **full predictive distributions**:
- **Posterior mean** — best estimate of yield
- **95% Credible Interval** — probabilistic uncertainty bounds
- **Epistemic uncertainty** — how uncertain the model is in sparse data regions
Key insight: A farmer planning fertilizer budgets benefits more from knowing the *range* of possible yields than a single point estimate.
---
## Dataset
| Field | Description |
|---|---|
| `year` | 2010–2023 |
| `lga` | 16 Local Government Areas in Kwara State |
| `crop` | Maize, Rice, Sorghum, Yam, Cassava |
| `rainfall_mm` | Annual rainfall (mm) |
| `temp_celsius` | Mean temperature (°C) |
| `soil_ph` | Soil pH reading |
| `fertilizer_kg_ha` | Fertilizer application rate |
| `yield_kg_ha` | **Target** — crop yield in kg/hectare |
> **Note:** Current dataset is synthetic, statistically calibrated to Kwara State conditions.
> Real FMARD/FAO Nigeria data integration is planned for v2.
---
## Proje …