Giter Site home page Giter Site logo

election-model's Introduction

election-model

This code predicts the 2016 presidential election results by county in California

V3 (15 June 2017):

added nearest neighbors regression models

Update (6 April 2017):

I implemented two linear regression models using data from the 2015 ACS; the supporting code is in vote_predicter_redux.py and the outputs are recorded in results.txt. The files lin_regr_2010_data.png, lin_regr_2015_data.png, ridge_regr_2010_data.png, and ridge_regr_2015_data.png all show histograms of the residuals.

The numerical scores were better for the models using the 2015 data, and the means of the difference between the predicted data and testing data were smaller for the 2015 data. However, examing the histograms of the residuals tell a different story. IN particular, examining the residuals for the two least squares models reveals that the models using 2010 data had some extreme outliers, but clustered its residuals close to zero much more often than the model using 2015 data. The same ridge regression models displayed the same relative behavior, but it was less pronounced. For this reason, I would actually say that one can build a better model using 2010 census data, as opposed to 2015 ACS data, which is a little strange.

Additionally, I ran five-fold cross validation on all models, which resulted in another oddity. Namely, all models behaved terribly on the second of the five folds, and had much better predictive power on the other four folds.

I used data age, sex, and race deomgraphic data from the 2010 census to train three regression models: linear regression (aka least squares fit), Ridge regression, and Lasso regression. It seems the linear regression modeled the data the best, though I would personally rate the performance of all the models as poor. Additionally, all models over-estimated Clinton's preformance and under-estimated Trump's performance.

In the future I'd like to improve this model. A first step would be to use data from the 2015 ACS, and incorporate some other variables (such as income and education). I expect these new variables would improve performance. Once I have a working model for the California vote I would like to expand to other states.

In this repository you'll find a file of Python code, some census data as .csv files, and three histograms of residuals for the three models. The code should be self-contained, though you might have to edit the python file to change the path of the .csv files (depending on where you put them).

election-model's People

Contributors

jratzkin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.