A Voting Classifier is a machine learning model that trains on an ensemble of numerous models and predicts an output (class) based on their highest probability of chosen class as the output.
It simply aggregates the findings of each classifier passed into Voting Classifier and predicts the output class based on the highest majority of voting. The idea is instead of creating separate dedicated models and finding the accuracy for each them, we create a single model which trains by these models and predicts output based on their combined majority of voting for each output class.
Voting Classifier supports two types of votings.
- Hard Voting: In hard voting, the predicted output class is a class with the highest majority of votes i.e the class which had the highest probability of being predicted by each of the classifiers. Suppose three classifiers predicted the output class(A, A, B), so here the majority predicted A as output. Hence A will be the final prediction.
- Soft Voting: In soft voting, the output class is the prediction based on the average of probability given to that class. Suppose given some input to three models, the prediction probability for class A = (0.30, 0.47, 0.53) and B = (0.20, 0.32, 0.40). So the average for class A is 0.4333 and B is 0.3067, the winner is clearly class A because it had the highest probability averaged by each classifier.
Note: Make sure to include a variety of models to feed a Voting Classifier to be sure that the error made by one might be resolved by the other.
Code : Python code to implement Voting Classifier
Hard Voting Score 1 Soft Voting Score 1
Input :4.7, 3.2, 1.3, 0.2 Output :Iris Setosa
In practical the output accuracy will be more for soft voting as it is the average probability of the all estimators combined, as for our basic iris dataset we are already overfitting, so there won’t be much difference in output.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- ML | Implementation of KNN classifier using Sklearn
- Voting System Project Using Django Framework
- Image Classifier using CNN
- ML | Training Image Classifier using Tensorflow Object Detection API
- IBM HR Analytics on Employee Attrition & Performance using Random Forest Classifier
- Random Forest Classifier using Scikit-learn
- Python | Decision Tree Regression using sklearn
- Python | Create Test DataSets using Sklearn
- Python | Linear Regression using sklearn
- ML | Dummy classifiers using sklearn
- Implementing DBSCAN algorithm using Sklearn
- Implementing Agglomerative Clustering using Sklearn
- ML | Implementing L1 and L2 regularization using Sklearn
- ML | OPTICS Clustering Implementing using Sklearn
- ML | Ridge Regressor using sklearn
- Calculating the completeness score using sklearn in Python
- homogeneity_score using sklearn in Python
- NLP | Classifier-based Chunking | Set 2
- Calculate Efficiency Of Binary Classifier
- NLP | Classifier-based tagging
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.