Satellite-based crop type classification for the Western Cape of South Africa using multi-temporal Sentinel-2 imagery.
# South Africa Crop Classification
**Satellite-based crop type classification for the Western Cape of South Africa using multi-temporal Sentinel-2 imagery.** This repository benchmarks classical machine learning, deep learning, and hybrid approaches against one another on a single region, with a deliberate emphasis on *out-of-sample* spatial transfer rather than the in-region cross-validation that most studies report.
The data originate from the Radiant Earth Spot The Crop Challenge. Models train on two tiles (`34S_19E_258N`, `34S_19E_259N`) and are evaluated on a spatially disjoint holdout tile (`34S_20E_259N`) that no training pixel touches.
**Crop classes (9):** Lucerne/Medics, Small grain grazing, Barley, Canola, Wheat, and others.
**Primary metric:** macro F1 (Cohen's Kappa and weighted F1 also reported).
## Why this repository
Most crop-classification papers validate within a single region and report that dense temporal deep nets (CNN-BiLSTM, TempCNN, L-TAE) win. We evaluate every model *twice* — once with conventional field-wise cross-validation inside the training region, and once on a holdout tile — and find that this dual evaluation reorders the models. The dense temporal networks that look strongest in-region suffer the largest generalization gaps under spatial transfer, while parsimonious, sparse-feature models (Random Forest, gradient-boosted trees, TabNet) transfer with much smaller losses. Inputs are restricted to optical Sentinel-2 time series alone — no SAR — to isolate the signal available from spectral time series.
The full analysis is written up in `writeup/sn-article.tex`.
## Models
- **Classical (field-level):** XGBoost + Optuna, LightGBM, Random Forest, logistic regression, SMOTE meta-learner, voting/stacking ensembles
- **Deep learning (pixel/field-level):** TabNet, CNN-BiLSTM, L-TAE, TempCNN
- **Patch-level:** 3D CNN
- **Features:** `xr_fresh` automated time-series statistics over bands B2, B6, B11, B12, EVI, and hue (months 05 and 0 …