Regression modeling of crop yield per hectare from geographic/weather/soil data, with two real data-quality bugs found and fixed before modeling.
# 🌾 Maji Ndogo Farm Yield Prediction
**Regression modeling of crop yield per hectare from geographic, weather, and soil data — with two real data-quality bugs found and fixed before any model was trained**
> Interactive dashboard: dashboard/farm_yield_dashboard.html
---
## Problem
5,654 agricultural fields across 5 provinces, 8 crop types, with geographic, weather, soil, and farm-management data. The obvious modeling target — a column literally named `Annual_yield` — turns out to be the wrong one to predict (see below). This project finds the right target, engineers a clean feature set, and builds a yield-prediction model that explains which environmental factors actually drive yield.
**Research questions:**
- What does "yield" actually mean in this dataset, and is the most obviously-named column the right one to model?
- Which environmental factors (soil, weather, pollution, geography) correlate with yield?
- Can yield per hectare be predicted from field characteristics, and how well?
---
## Dataset
Source: `Maji_Ndogo_farm_survey_small.db` (4 linked tables: geographic, weather, soil/crop, farm-management features — 5,654 fields) + `Weather_Station_Dataset.zip` (1,843 free-text weather-station messages).
---
## Two real bugs found before modeling
1. **`Crop_type` and `Annual_yield` are swapped in the source schema.** The column labeled `Crop_type` held continuous numbers; the column labeled `Annual_yield` held crop-name strings (with typos: "wheatn", "teaa", "cassaval"). Verified and fixed in `notebooks/01_data_cleaning.ipynb`.
2. **`Annual_yield` is not a usable modeling target.** It correlates at r=0.95 with `Plot_size` — it's just total farm output, which scales with farm size almost by definition. The `Standard_yield` column, despite its name suggesting a fixed benchmark, turns out to be **exactly** `Annual_yield / Plot_size` (r=1.0, verified in `notebooks/02_exploratory_analysis.ipynb`) — the real, size-independent yield-per-hectare rate, and the c …