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:
Rust for deterministic CSV ingestion, validation, lag features, annual changes, and trend feature generation, chosen as an efficiency and scalability precaution for larger panel-processing workloads
Python for machine-learning data processing, exploratory analysis, PCA, similarity analysis, model training, and dashboard integration
Scikit-learn for supervised downturn-risk classification
Streamlit for scenario testing and multi-country comparison
๐งช Data Pipeline:
Panel construction: Country-year observations are built from macroeconomic indicators including GDP growth, inflation, unemployment, life expectancy, and population growth.
Vector representation: Each observation is treated as a feature vector x โ Rโฟ, allowing countries to be compared geometrically.
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.
๐ 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
countryyearx โ Rโฟ
ZAF2018[gdp, ฯ, u, ...]
BRA2019[gdp, ฯ, u, ...]
IND2020[gdp, ฯ, u, ...]
KEN2021[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
lowrisk
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:
The strongest modelling move is shifting from static economic indicators to a feature-space representation with temporal movement.
Lag, annual-change, and trend features make downturn risk easier to reason about than raw levels alone.
The Rust/Python split keeps deterministic feature engineering separate from modelling and dashboard experimentation.
๐ง๐พ 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.