Skip to content

CongressionalVotingModel

Barry Stahl edited this page Feb 21, 2020 · 2 revisions

The Congressional Voting Model

This model is based on the house-votes-84 dataset of 16 votes from the US House of Representatives taken during the 1984 congressional session. This dataset can be found in many places on the Internet but in this case was downloaded from the UCI Machine Learning Repository. All 435 voting members of the House of Representatives are represented in the dataset. A sample record is shown below.

democrat,y,y,y,n,y,y,n,n,n,n,y,?,y,y,y,y

The goal of the model is to predict the political party of the voter, based on his or her votes on these 16 issues. A simple structure is used for this tooling: 16 input nodes (1 for each vote), 1 output node to represent the political party of the voter, and 16 edges to connect the inputs to the output. No hidden layers are used in this implementation.

Congressional Voting Model

The model is trained by taking a 75% sample of the data and using the Amoeba Optimization method to find the weights and biases in the model that minimize the error between the predicted values and the actual values. This Error Function uses the sum of the squares of all the errors piped through the Activation Function to produce an ouput between 0 and 1.

The VotingData Project

The project called VotingData within the Visual Studio Solution holds all of the model and orchestration pieces.

The program outputs to the console the list of voters that were incorrectly predicted by the model as well as statistical information about the model's quality. In the example below, the best model produced had a 99.06% accuracy on the test set, which consisted of approximately 25% of the data set. This model was then able to accurately predict the political party of 410 of the 435 representatives in the full data set.

Incorrect Predictions:
Voter 00006 - Party:   democrat (0.9654)
Voter 00071 - Party: republican (0.1557)
Voter 00075 - Party:   democrat (0.7155)
Voter 00081 - Party:   democrat (0.9504)
Voter 00085 - Party:   democrat (0.9928)
Voter 00096 - Party:   democrat (0.9754)
Voter 00097 - Party:   democrat (0.9986)
Voter 00100 - Party:   democrat (0.9640)
Voter 00147 - Party:   democrat (0.9906)
Voter 00161 - Party:   democrat (1.0000)
Voter 00173 - Party:   democrat (0.9999)
Voter 00215 - Party:   democrat (0.8768)
Voter 00248 - Party: republican (0.0505)
Voter 00280 - Party:   democrat (0.6408)
Voter 00315 - Party: republican (0.0810)
Voter 00355 - Party: republican (0.3213)
Voter 00363 - Party: republican (0.0866)
Voter 00372 - Party:   democrat (0.8251)
Voter 00375 - Party:   democrat (0.9978)
Voter 00382 - Party:   democrat (0.7063)
Voter 00384 - Party:   democrat (0.8858)
Voter 00388 - Party:   democrat (0.9977)
Voter 00390 - Party:   democrat (0.9059)
Voter 00393 - Party: republican (0.0003)
Voter 00407 - Party:   democrat (1.0000)

Mean: 90.43  Min: 76.92  Max: 99.06  StDev: 4.31

The following are the key modules in this code project:

  • Program.cs - The entry point of the program. This module loads the voter data from the text file and then loops through a large number of training/testing cycles to determine the effectiveness of the model produced. This module also holds the Error function used to determine how effective the model is, and the Activation function used within the model. In the current code base, 3 activation functions are defined: Sigmoid, Relu, and NoActivation. Only Sigmoid is used at this time.

  • Model.cs - Holds the weights and biases needed to calculate the output of the model from a set of inputs. This object also holds the functionality to train and thus produce a new model, and to test its own effectiveness against supplied data.

  • VotingDataRepository.cs - Contains the functionality to load the dataset. In this case, the data is loaded from a CSV file stored with the project.

  • Voter.cs - Represents a voter and his or her votes. Each row in the dataset file results in a single Voter object being returned from the VotingDataRepository.

  • PredictionResult.cs - Represents the results of a prediction. Holds the input data in the Voter object, the prediction in the Value property, and the Score used to determine the prediction. The more extreme (closer to 0 or 1) the Score is, the more certain the model is of its prediction.

Clone this wiki locally