Technical case study
Macroeconomic Downturn Prediction using Linear Algebra and Machine Learning
A country-year macroeconomic risk experiment combining Rust feature engineering, Python modelling and a Streamlit scenario dashboard.
The problem
This project builds a country-year macroeconomic panel from World Bank indicators and adds temporal information before estimating next-year downturn risk. The emphasis is on representation, reproducible feature engineering and interpretable scenario testing rather than on presenting the output as a policy-grade forecast.
Can country-year macroeconomic indicators be represented with temporal features that make next-year downturn risk easier to model and interpret?
Approach
Rather than presenting the project as a notebook dump, this case study focuses on the decisions that shaped the analysis.
- Panel construction: Country-year observations are built from macroeconomic indicators including GDP growth, inflation, unemployment, life expectancy, and population growth.
- Vector representation: Each observation becomes a named macroeconomic profile x_country,year , containing indicators such as GDP growth, inflation, unemployment, population growth, and life expectancy.
- Temporal feature engineering: Rust creates lag, annual-change, and three-year least-squares trend features efficiently before exporting the engineered panel for Python-based machine-learning processing.
- Model training: Python consumes the engineered dataset and trains a classifier to estimate downturn probability in the following year.
- Dashboard layer: The dashboard supports country selection, scenario simulation, similar-country comparison, and time-series diagnostics.
Key implementation decision
Separate deterministic feature generation from exploratory modelling
Rust owns repeatable panel ingestion and temporal features, while Python owns exploration, PCA, model fitting and dashboard integration. The split keeps the transformation layer distinct from model experimentation.
features = [
"gdp_growth",
"inflation",
"unemployment",
"gdp_growth_lag_1",
"unemployment_delta_1",
"gdp_growth_trend_3y",
]
X = panel[features]
y = panel["downturn_next_year"]
model.fit(X_train, y_train)
downturn_probability = model.predict_proba(current_country_vector)[0, 1]
Results & evidence
The figures below are the project evidence I would show first. The full implementation remains available through the GitHub link at the top of the page.
From macro indicators to downturn-risk interpretation
The modelling path is shown as three transformations: raw country-year observations, engineered movement in feature space, and an interpretable model output.
1. Country-year panel
Raw indicators become comparable observations
World Bank indicators are aligned into a country-year panel. Each row becomes a macroeconomic profile constructed from interpretable variables such as GDP growth, inflation, unemployment, population growth, and life expectancy.
2. Feature-space view
Rust prepares the panel for scale
Rust is used for the deterministic feature pipeline because it provides efficiency and scalability headroom if the panel grows across more countries, years, indicators, or repeated experiments. It creates lag features, annual changes, and three-year trend slopes before the engineered dataset moves into Python.
3. Risk output
Classifier + dashboard
illustrative downturn probability
Scenario testingPython handles ML interpretation
Python is used for the machine-learning processing layer: exploratory analysis, PCA, similarity analysis, model training, probability estimation, and Streamlit dashboard integration. The resulting workflow produces a probability score that can be explored under alternative scenarios rather than only a binary class label.
What challenged me
The central challenge was turning broad macroeconomic indicators into a reproducible modelling pipeline without overclaiming forecasting precision. The solution was to frame the project as a representation and classification experiment rather than a policy-grade economic forecast.
What I learned
- Temporal movement can be represented explicitly with lag, delta and trend features instead of relying only on raw indicator levels.
- Keeping deterministic feature engineering separate from modelling makes the pipeline easier to reason about and reproduce.
- The resulting probability should be treated as an experimental model output, not a policy-grade economic forecast.
What I would improve next
- Use walk-forward validation to respect the temporal structure of the panel.
- Test feature stability across countries and economic regimes.
- Add probability calibration and uncertainty reporting before treating the output as a decision-support score.
The central modelling move is to represent not only indicator levels but also recent movement. Lag, annual-change and trend features let the classifier see direction while keeping the experiment interpretable.