Aan de slagGa gratis aan de slag

Evaluate individual classifiers

In this exercise you'll evaluate the performance of the models in the list classifiers that we defined in the previous exercise. You'll do so by fitting each classifier on the training set and evaluating its test set accuracy.

The dataset is already loaded and preprocessed for you (numerical features are standardized) and it is split into 70% train and 30% test. The features matrices X_train and X_test, as well as the arrays of labels y_train and y_test are available in your workspace. In addition, we have loaded the list classifiers from the previous exercise, as well as the function accuracy_score() from sklearn.metrics.

Deze oefening maakt deel uit van de cursus

Machine Learning with Tree-Based Models in Python

Cursus bekijken

Oefeninstructies

  • Iterate over the tuples in classifiers. Use clf_name and clf as the for loop variables:
    • Fit clf to the training set.
    • Predict clf's test set labels and assign the results to y_pred.
    • Evaluate the test set accuracy of clf and print the result.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Iterate over the pre-defined list of classifiers
for clf_name, clf in ____:    
 
    # Fit clf to the training set
    ____.____(____, ____)    
   
    # Predict y_pred
    y_pred = ____.____(____)
    
    # Calculate accuracy
    accuracy = ____(____, ____) 
   
    # Evaluate clf's accuracy on the test set
    print('{:s} : {:.3f}'.format(clf_name, accuracy))
Code bewerken en uitvoeren