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.
Latihan ini adalah bagian dari kursus
Machine Learning with Tree-Based Models in Python
Petunjuk latihan
- 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.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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))