This project applies Bayesian networks to analyze and predict the outcomes of U.S. presidential elections based on key economic indicators.
It was developed as part of the Interpretierbare Künstliche Intelligenz (Interpretable Artificial Intelligence) course at HTW Berlin.
- Which party — Democrats or Republicans — is more likely to win a given election?
- How do economic factors such as GDP, unemployment, and national debt influence election outcomes?
To build a probabilistic model that estimates the influence of selected economic indicators on U.S. presidential election results and provides interpretable insights into these relationships.
- Election results and electoral votes: Encyclopaedia Britannica – U.S. Presidential Election Results
- Gross Domestic Product (GDP): Federal Reserve Economic Data (FRED)
- Unemployment rates: U.S. Bureau of Labor Statistics
- Government debt: U.S. Treasury Fiscal Data
- Supplementary dataset: Unemployment in America per U.S. State
- Data from 1947–2024 were analyzed for every presidential term.
- Economic indicators were averaged over four-year election periods.
- Values were divided into quantile-based categories: low, medium, high.
- The dataset includes only Democratic and Republican outcomes.
A Bayesian Network represents probabilistic relationships between variables:
- Nodes represent variables (GDP, unemployment, debt, and election result).
- Edges represent causal or influence directions.
- Conditional Probability Tables (CPTs) are derived from historical data.
- The Beta distribution was used to model win probabilities (0–1 range).
- For each category (low, medium, high), we calculated the likelihood of victory for each party.
- Electoral votes were also integrated to improve accuracy.
To generalize results, multiple Beta distributions were averaged per category to smooth out uncertainty and capture tendencies across terms.
| Feature | Value | Category |
|---|---|---|
| GDP | 3.82 | High |
| Unemployment | 4.16 | Low |
| Debt | 0.0712 | Medium |
| Party | Predicted Probability | Actual Result |
|---|---|---|
| Democrats | 0.4687 | 0.4201 |
| Republicans | 0.5313 | 0.5799 |
- 10 out of 19 elections were predicted correctly (party match).
- Model captured general economic trends:
- Low unemployment and high GDP favor Republicans.
- Political bias remains a limiting factor — U.S. elections are historically conservative-leaning (11 Republican wins vs. 8 Democratic wins since 1952).
- Split data: One election as test data, remaining 18 as training data.
- Categorize features using quantiles.
- Apply Beta distributions for each category and compute CPTs.
- Run Bayesian inference on the test instance.
- Compare predicted vs. actual results (party and electoral votes).
- Write results to a CSV for further analysis.
# Create a virtual environment
python3 -m venv venv
# Activate the environment
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt