LoslegenKostenlos loslegen

F-beta score

The F-beta score is a weighted harmonic mean between precision and recall, and is used to weight precision and recall differently. It is likely that one would care more about weighting precision over recall, which can be done with a lower beta between 0 and 1. In this exercise, you will calculate the precision and recall of an MLP classifier along with the F-beta score using a beta = 0.5.

X_train, y_train, X_test, y_test are available in your workspace, and the features have already been standardized. pandas as pd and sklearn are also available in your workspace. fbeta_score() from sklearn.metrics is available as well.

Diese Übung ist Teil des Kurses

Predicting CTR with Machine Learning in Python

Kurs anzeigen

Anleitung zur Übung

  • Split the data into training and testing data.
  • Define a MLP classifier, train using .fit(), and predict using .predict().
  • Use implementations from sklearn to get the precision, recall scores, and F-beta scores.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Set up MLP classifier, train and predict
X_train, X_test, y_train, y_test = ____(
  ____, ____, test_size = .2, random_state = 0)
clf = ____(hidden_layer_sizes = (16, ), 
                    max_iter = 10, random_state = 0)
y_pred = clf.____(____, _____).____(X_test) 

# Evaluate precision and recall
prec = ____(y_test, ____, average = 'weighted')
recall = ____(y_test, ____, average = 'weighted')
fbeta = ____(y_test, ____, ____  = 0.5, average = 'weighted')
print("Precision: %s, Recall: %s, F-beta score: %s" %(prec, recall, fbeta))
Code bearbeiten und ausführen