finalproject
Early-Evening prediction of US presidential elections using DAG and MRF models and MCMC.
A guide to this code
Preprocess.ipynb
: Data was preprocessed going frompresidential_general_polls.csv
tofull_data.csv
. Put final means of predictions from last 3 days infinal_means.csv
.Preproc_results.ipynb
: Puts unorganized election data into organizedresults.csv
which includes clinton%, electoral votes, and poll closing time for each state.Impute.ipynb
: Used MICE 10 times to create 10 filled data matrices. Saved list to pkl file asdata_fill.pkl
. Subtract means to make gaussian easier.Learn_PC.ipynb
: Used PCAlg to learn DAG for each MICE filled graph using BIC score to select best alpha each time. Analyzed results and saved DAG that takes only values that are in 5 or more learned DAGs inDAG_PC.csv
Learn_MRF.ipynb
: Used Glasso to learn MRF for each MICE filled graph. Analyzed results and saved MRF that takes only values that are in 5 or more learned MRFs inMRF.csv
. Save MRF using MLE for weights.MLE_Gaussian.ipynb
learns MLES for Gaussian models for PC DAGs. Saves toMLE_PC.pkl
MCMC.ipynb
: Do conditional queries from DAG and MRF using both simple Metropolis Hastings algo and Goodman & Weare’s Affine Invariant Markov chain Monte Carlo (MCMC) Ensemble sampler. For DAG and MRF keep track of electoral votes and clinton percentage in each swing state after results come in for different time slots. Save to pickle files of the form<MODEL>_<MCMC_TYPE>_<TIME>.pkl
Explore.ipynb
: I explore the results and make some tables and graphs.