Skip to content

MarvMa/Election-Bayes-Network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Election Bayes Network

Overview

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.

Research Questions

  • 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?

Objective

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.


Data

Sources

Data Preparation

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

Methodology

Bayesian Network

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.

Beta Distribution Analysis

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

Average Model

To generalize results, multiple Beta distributions were averaged per category to smooth out uncertainty and capture tendencies across terms.


Prediction Example (2024 Election)

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

Benchmark Results

  • 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).

Algorithm Workflow

  1. Split data: One election as test data, remaining 18 as training data.
  2. Categorize features using quantiles.
  3. Apply Beta distributions for each category and compute CPTs.
  4. Run Bayesian inference on the test instance.
  5. Compare predicted vs. actual results (party and electoral votes).
  6. Write results to a CSV for further analysis.

Setup

# Create a virtual environment
python3 -m venv venv

# Activate the environment
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

About

This project applies Bayesian networks to analyze and predict the outcomes of U.S. presidential elections based on key economic indicators.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages