IniziaInizia gratis

Soft vs. hard voting

You've now practiced building two types of ensemble methods: Voting and Averaging (soft voting). Which one is better? It's best to try both of them and then compare their performance. Let's try this now using the Game of Thrones dataset.

Three individual classifiers have been instantiated for you:

  • A DecisionTreeClassifier (clf_dt).
  • A LogisticRegression (clf_lr).
  • A KNeighborsClassifier (clf_knn).

Your task is to try both voting and averaging to determine which is better.

Questo esercizio fa parte del corso

Ensemble Methods in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Prepare the list of (string, estimator) tuples. Use 'dt' as the label for clf_dt, 'lr' for clf_lr, and 'knn' for clf_knn.
  • Build a voting classifier called clf_vote.
  • Build an averaging classifier called clf_avg.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# List of (string, estimator) tuples
estimators = ____

# Build and fit a voting classifier
clf_vote = ____
clf_vote.fit(X_train, y_train)

# Build and fit an averaging classifier
clf_avg = ____
clf_avg.fit(X_train, y_train)

# Evaluate the performance of both models
acc_vote = accuracy_score(y_test, clf_vote.predict(X_test))
acc_avg = accuracy_score(y_test,  clf_avg.predict(X_test))
print('Voting: {:.2f}, Averaging: {:.2f}'.format(acc_vote, acc_avg))
Modifica ed esegui il codice