Skip to content

giotto-ai/us-election-tda

Repository files navigation

logo

The shape of the United States presidential elections

The accompanying blog post can be found here .

Want to dive right in? Find the accompanying blog post Go directly to the Getting started section!

What it is

A guide on how to gain insight in socio-economic and election data of U.S. counties using the Mapper algorithm implemented in Giotto-learn. See the accompanying blog post for further details.

Data

The socio-economic data has been taken from the U.S. Bureau of Economic Analysis (BEA). The voting data is provided by the MIT Election Data and Science Lab (MEDSL).

Results

Our study shows that we can divide the counties into five main regions based on economic indicators:

  1. High net worth
  2. High net worth per inhabitant
  3. High per capita retirement
  4. Elevated and average net worth
  5. Low net worth

When combined with election results, we find that in 2016, the high per capita retirement, and low net worth regions are strongholds for the Republicans. The remaining three regions vote predominantly Democrat with an exception for some clusters of elevated and medium net worth counties.

Getting started

1. Linux / MacOS

If you have pip and anaconda installed, it suffices to run the following commands in a terminal:

conda create --name mapper python=3.7 && conda activate mapper
conda install jupyter -y
pip install -r requirements.txt
pip install python-igraph

2. Windows

You first have to download from here the wheel corresponding to your Python version and architecture. Then, you need to run the following commands in a terminal:

conda create --name mapper python=3.7 && conda activate mapper
conda install jupyter -y
pip install -r requirements.txt
pip install python_igraph‑0.7.1.post6‑cp{YOUR_PYTHON_VERSION}‑cp{YOUR_PYTHON_VERSION}‑win_amd64.whl

JupyterLab setup

To see the Plotly graphs in JupyterLab, some extra steps are required:

1. Linux / MacOS

# Avoid "JavaScript heap out of memory" errors during extension installation
export NODE_OPTIONS=--max-old-space-size=4096
# Jupyter widgets extension
jupyter labextension install @jupyter-widgets/jupyterlab-manager@1.1 --no-build
# FigureWidget support
jupyter labextension install plotlywidget@1.4.0 --no-build
# and jupyterlab renderer support
jupyter labextension install jupyterlab-plotly@1.4.0 --no-build
# Build extensions (must be done to activate extensions since --no-build is used above)
jupyter lab build
# Unset NODE_OPTIONS environment variable
unset NODE_OPTIONS

2. Windows

# Avoid "JavaScript heap out of memory" errors during extension installation
set NODE_OPTIONS=--max-old-space-size=4096
# Jupyter widgets extension
jupyter labextension install @jupyter-widgets/jupyterlab-manager@1.1 --no-build
# FigureWidget support
jupyter labextension install plotlywidget@1.4.0 --no-build
# and jupyterlab renderer support
jupyter labextension install jupyterlab-plotly@1.4.0 --no-build
# Build extensions (must be done to activate extensions since --no-build is used above)
jupyter lab build
# Unset NODE_OPTIONS environment variable
set NODE_OPTIONS=

After running these steps, deactivate and reactivate your conda environment before spinning up JupyterLab.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •