IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Machine Learning with Tree-Based Models in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Import VotingClassifier from sklearn.ensemble.
  • Instantiate a VotingClassifier by setting the parameter estimators to classifiers and assign it to vc.
  • Fit vc to the training set.
  • Evaluate vc's test set accuracy using the test set predictions y_pred.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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))
Modifica ed esegui il codice