Question: Implement a Naive Bayes Classifier that classifies individuals as Democrats or Republicans, using the 1 6 attributes and two classes from the Congressional Voting Records

Implement a Naive Bayes Classifier that classifies individuals as Democrats or Republicans, using the 16 attributes and two classes from the Congressional Voting Records dataset
Some of the features contain the value "?", which typically represents a missing value. In this case, the data explicitly states that this symbol means neither "yes" nor "no." It represents a third value, "abstained." Solve the task in two ways: first, by treating the "?" value as the third option (abstained), and second, by filling the missing values with an approach of your choice, and justify why you selected that approach. Analyze the results.
For the Naive Bayes classifier, zero probabilities may occur, leading to inaccurate classification. To address this issue, apply the appropriate solutions: "Laplace Smoothing" and logarithms. When applying Laplace smoothing, test with different values of the parameter , which indicates the degree of smoothing. Analyze the results.
To test the algorithm, split the data into training and testing sets in an 80:20 ratio, ensuring the data is shuffled first. The split should be stratified to preserve the class distribution (267 Democrats, 168 Republicans) in the resulting training and test sets.
The input should accept two possible values: 0 and 1:
0 means to process the data by treating the "?" symbols as a third value, "abstained."
1 means to fill the missing values (marked with "?") using an approach of your choice.
The output should display the accuracy of the model on the training set (trained and tested on it), the accuracy and standard deviation of the model during 10-fold cross-validation on the training set, and the accuracy of the model on the test set.
Example input: 0
Example output:
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%
Test Set Accuracy:
Accuracy: 92.50%
For solving the task, you are allowed to use data structures such as DataFrame.
It is required to implement the algorithm from scratch! The use of external libraries is not allowed, except for standard libraries and those specifically related to data structures needed for implementing the algorithm. Please ensure that your solution reflects your understanding of the algorithm and does not rely on pre-existing implementations. WRITE THIS IN C++

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!