← Back to Projects Research & Modelling

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.

RustPythonLinear AlgebraMachine Learning
Question Can country-year macroeconomic indicators be represented with temporal features that make next-year downturn risk easier to model and interpret?
Focus Feature engineering · Rust + Python pipeline · Risk classification
Outcome A reproducible country-year feature pipeline feeding a classifier and interactive scenario explorer.

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.

Question

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.

  1. Panel construction: Country-year observations are built from macroeconomic indicators including GDP growth, inflation, unemployment, life expectancy, and population growth.
  2. 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.
  3. 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.
  4. Model training: Python consumes the engineered dataset and trains a classifier to estimate downturn probability in the following year.
  5. 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]
Why this matters

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.

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

Country Year Macro profile
ZAF 2018 [GDP growth, inflation, unemployment, ...]
BRA 2019 [GDP growth, inflation, unemployment, ...]
IND 2020 [GDP growth, inflation, unemployment, ...]
KEN 2021 [GDP growth, inflation, unemployment, ...]

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

Low High
0.68

illustrative downturn probability

Scenario testing

Python 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.

Conceptual representation of the project's modelling pipeline. The displayed risk value is illustrative rather than a reported empirical result.

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.
Full implementation: use the GitHub link in the project header for the complete notebook/code rather than expanding the case study into a full source listing.