Ensemble Methods in Python
Román de las Heras
Data Scientist, Appodeal
Wisdom of the crowd
Properties
Wise Crowd Characteristics:
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