The voting classifier supports two types of voting.
- Hard voting. In hard voting, the predicted output class is — it is the class with the highest majority of votes, that is, the class that has the highest probability of being predicted by each of the classifiers. Suppose three classifiers predicted output class (A, A, B) , so here most people predicted A as output. Therefore, A will be the final prediction.
- Soft vote: With soft vote, the output class is — it is a prediction based on the average probability given to this class. Suppose given some input for three models: the prediction probability for the class A = (0.30, 0.47, 0.53) and B = (0.20, 0, 32, 0.40) . Thus, the average for class A is 0.4333, and B — 0.3067 , the winner is clearly A, as it had the highest probability averaged over each classifier.
Note. Make sure you include the different models for the submission of the qualifier to vote to ensure that a mistake made by one can be corrected by the other.
Code: Python code to implement the voting classifier
|
Exit :
Hard Voting Score 1 Soft Voting Score 1
Examples :
Input: 4.7, 3.2, 1.3, 0.2 Output: Iris Setosa
In practice, the output accuracy will be higher for a soft vote, since this is the average probability of all evaluators combined, since for we are already retraining our basic iris dataset, so there won’t be much difference in the output.