The simplest way to implement hard voting in Python is to use scikit-learn to create base learners, train them on some data, and combine their predictions on test data. In order to do so, we will go through the following steps:
- Load the data and split it into train and test sets
- Create some base learners
- Train them on the train data
- Produce predictions for the test data
- Combine predictions using hard voting
- Compare the individual learner's predictions as well as the combined predictions with the ground truth (actual correct classes)
Although scikit-learn has implementations for voting, by creating a custom implementation, it will be easier to understand how the algorithm works. Furthermore, it will enable us to better understand how to process and analyze a base learner's outputs.