Question: Implement a Naive Bayes Classifier to classify individuals as Democrats or Republicans using the 1 6 attributes and 2 classes from the Congressional Voting Records

Implement a Naive Bayes Classifier to classify individuals as Democrats or Republicans using the 16 attributes and 2 classes from the Congressional Voting Records dataset.
Some of the features contain the value "?", which generally indicates a missing value. However, in this dataset, it explicitly denotes "neither yes nor no," representing a third value, abstained. Solve the task in two ways:
Treat the value "?" as a third option (abstained).
Replace the missing values ("?") with a method of your choice and justify your selection. Analyze the results.
In a Naive Bayes classifier, zero probabilities can lead to inaccurate classifications. To address this, apply appropriate solutions such as Laplace Smoothing and logarithms. For Laplace smoothing, test with different values of the parameter \lambda, which controls the degree of smoothing. Analyze the results.
To test the algorithm, split the dataset into training and testing sets in an 80:20 ratio after shuffling it. The split should be stratified to preserve the class ratio (267 Democrats, 168 Republicans) in the newly created training and test sets.
The input will accept two values: 0 or 1:
0 means treat "?" as a third value (abstained).
1 means replace the missing values ("?") with a chosen approach.
The output should display the model's performance as follows:
- Accuracy on the training set (trained and tested on the training set).
- Mean accuracy and standard deviation from 10-fold cross-validation on the training set.
- Accuracy on the test set.
Using data structures like DataFrames is allowed for solving the problem.
Example Input:
0
Example Output:
1. Train Set Accuracy:
Accuracy: 92.80%
10-Fold Cross-Validation Results:
Accuracy Fold 1: 92.00%
Accuracy Fold 2: 91.50%
Accuracy Fold 3: 90.00%
Accuracy Fold 4: 93.00%
Accuracy Fold 5: 91.00%
Accuracy Fold 6: 92.50%
Accuracy Fold 7: 93.00%
Accuracy Fold 8: 91.50%
Accuracy Fold 9: 92.00%
Accuracy Fold 10: 93.50%
Average Accuracy: 92.10%
Standard Deviation: 1.10%
2. Test Set Accuracy:
Accuracy: 92.50%
Please solve the task in C++ programming language. Do not use any other embedded STL function. And let the implementation be a product of your own understanding, not a copy from somebody else's code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!