Skip to content

Instantly share code, notes, and snippets.

@Mehdi-Amine
Created November 30, 2019 23:19
Show Gist options
  • Save Mehdi-Amine/b4ce19f1735ae77bee296049fdb4a211 to your computer and use it in GitHub Desktop.
Save Mehdi-Amine/b4ce19f1735ae77bee296049fdb4a211 to your computer and use it in GitHub Desktop.
An ensemble classifier that relies on soft voting.
# Out of the three models,
# only SVC requires some tweaking to output its confidence
# this is done by setting probability=True:
svm_clf_tweaked = SVC(gamma='scale', probability=True, random_state=42)
soft_voting_clf = VotingClassifier(estimators=[('svm', svm_clf_tweaked), ('tree', tree_clf), ('log', log_clf)],
voting='soft')
soft_voting_clf.fit(X_train, y_train) # training
y_pred_voting = soft_voting_clf.predict(X_test) # predicting
accuracy_score(y_test, y_pred_voting) # evaluating
# Output of the evaluation: 0.912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment