Hard voting combines a number of predictions by assuming that the most voted class is the winner. In a simple case of two classes and three base learners, if a target class has at least two votes, it becomes the ensemble's output, as shown in the following diagram. Implementing a hard voting classifier is as simple as counting the votes for each target class:
For example, let's say that there are three different base learners, who are predicting whether a sample belongs to one of three classes with a certain probability (Table 1).
In the following table, each learner predicts the probability that the instance belongs to a certain class:
Class A |
Class B |
Class C |
|
Learner 1 |
0.5 |
0.3 |
0.2 |
Learner 2 |
0 |
0.48 |
0.52 |
Learner 3 |
0.4 |
0.3 |
0.3 |
In this example, class A has two votes, while class C has only one. According to hard voting, class A will be the prediction of the ensemble. It's a fairly robust method of combining many base learners, although it doesn't take into account that some classes may be chosen by a base learner only because they are marginally better than the others.