Better performance with a Voting Classifier
Finally, you'll evaluate the performance of a voting classifier that takes the outputs of the models defined in the list classifiers and assigns labels by majority voting.
X_train, X_test,y_train, y_test, the list classifiers defined in a previous exercise, as well as the function accuracy_score from sklearn.metrics are available in your workspace.
Deze oefening maakt deel uit van de cursus
Machine Learning with Tree-Based Models in Python
Oefeninstructies
- Import
VotingClassifierfromsklearn.ensemble. - Instantiate a
VotingClassifierby setting the parameterestimatorstoclassifiersand assign it tovc. - Fit
vcto the training set. - Evaluate
vc's test set accuracy using the test set predictionsy_pred.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Import VotingClassifier from sklearn.ensemble
____
# Instantiate a VotingClassifier vc
vc = ____(estimators=____)
# Fit vc to the training set
____.____(____, ____)
# Evaluate the test set predictions
y_pred = vc.predict(X_test)
# Calculate accuracy score
accuracy = ____(____, ____)
print('Voting Classifier: {:.3f}'.format(accuracy))