Voting

Ensemble Methods in Python

Román de las Heras

Data Scientist, Appodeal

Ask the audience

ask-the-audience.gif

Wisdom of the crowd

  • Collective intelligence
  • Large group of individuals >= Single expert
  • Problem solving
  • Decision making
  • Innovation
  • Prediction
Ensemble Methods in Python

Majority voting

Properties

  • Classification problems
  • Majority Voting: Mode
  • Odd number of classifiers (3+)

multi-modal-prediction.png

Wise Crowd Characteristics:

  • Diverse: different algorithms or datasets
  • Independent and uncorrelated
  • Use individual knowledge
  • Aggregate individual predictions
Ensemble Methods in Python

Voting ensemble using scikit-learn

from sklearn.ensemble import VotingClassifier

clf_voting = VotingClassifier( estimators=[ ('label1', clf_1), ('label2', clf_2), ('labelN', clf_N)])

Evaluate the performance

# Get the accuracy score 
acc = accuracy_score(y_test, y_pred)
print("Accuracy: {:0.3f}".format(acc))
Accuracy: 0.938
# Create the individual models
clf_knn = KNeighborsClassifier(5)
clf_dt = DecisionTreeClassifier()
clf_lr = LogisticRegression()

# Create voting classifier clf_voting = VotingClassifier( estimators=[ ('knn', clf_knn), ('dt', clf_dt), ('lr', clf_lr)])
# Fit it to the training set and predict clf_voting.fit(X_train, y_train) y_pred = clf_voting.predict(X_test)
Ensemble Methods in Python

Let's give it a try!

Ensemble Methods in Python

Preparing Video For Download...