Weighted classifiers

The only way for inferior models to overrule the best (expert) model is for them to collectively and confidently agree on an alternative.

To avoid this scenario, we can use a weighted majority vote—but why weighting?

Usually, we want to give a better model more weight in a vote. The simplest, but computationally inefficient, way to do this is to repeat the classifier pipelines under different names, as follows: 

weighted_voting_clf = VotingClassifier(estimators=[('lr', lr_clf), ('lr2', lr_clf),('rf', xtc_clf), ('mnb2', mnb_clf),('mnb', mnb_clf)], voting='soft', n_jobs=-1)weighted_voting_clf.fit(X_train, y_train)

Repeat the experiment with hard voting instead of soft voting. This will tell you how the voting strategy ...

Get Natural Language Processing with Python Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.