Macroeconomic Downturn Prediction using Linear Algebra and Machine Learning

This project builds a country-year macroeconomic panel from World Bank indicators and uses linear algebra, Rust-based feature engineering, Python modelling, and a Streamlit dashboard to estimate next-year economic downturn risk.

Core idea: represent each country-year as a vector in macroeconomic feature space, then add temporal structure through lag features, annual changes, and three-year trend slopes.

๐Ÿ’ป Tech Stack:

๐Ÿงช Data Pipeline:

๐Ÿ“Š Code Snippets & Visualisations:

# Country-year macroeconomic feature vector
features = [
    "gdp_growth",
    "inflation",
    "unemployment",
    "life_expectancy",
    "population_growth",
    "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]

From macro indicators to downturn-risk interpretation

The modelling path is easier to read as three vertical transformations: raw country-year rows, engineered movement in feature space, and an interpretable risk output.

1. Country-year panel

country year x โˆˆ Rโฟ
ZAF 2018 [gdp, ฯ€, u, ...]
BRA 2019 [gdp, ฯ€, u, ...]
IND 2020 [gdp, ฯ€, u, ...]
KEN 2021 [gdp, ฯ€, u, ...]

Raw indicators become comparable observations

World Bank indicators are aligned into a country-year panel. Each row becomes a macroeconomic profile that can be treated as a vector rather than as isolated columns.

2. Feature-space view

Rust prepares the panel for scale

Rust is used for the deterministic feature pipeline because it gives 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 data moves into Python.

3. Risk output

Classifier + dashboard

low risk
0.68

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 output is not only a class label, but an interpretable downturn-risk score that can be tested through scenarios.

๐ŸŒŸ Key Insights:

๐Ÿง—๐Ÿพ Challenge Faced:

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.

View on GitHub Open Live App

โ† Back to Projects