Skip to content

Instantly share code, notes, and snippets.

@Mehdi-Amine
Last active November 30, 2019 04:36
Show Gist options
  • Save Mehdi-Amine/923e682e2fda336a06c48c829a86a89b to your computer and use it in GitHub Desktop.
Save Mehdi-Amine/923e682e2fda336a06c48c829a86a89b to your computer and use it in GitHub Desktop.
Creating, training, predicting, and evaluating an ensemble
# Combining the three models into an ensemble
from sklearn.ensemble import VotingClassifier
# The ensemble is a voting classifier that aggregates our three models
voting_clf = VotingClassifier(estimators=[('svm', svm_clf), ('tree', tree_clf), ('log', log_clf)],
voting='hard')
voting_clf.fit(X_train, y_train) # training
y_pred_voting = voting_clf.predict(X_test) # predicting
accuracy_score(y_test, y_pred_voting) # evaluating
# Output of the evaluation: 0.904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment