2.1. Exercises

Let’s Calculate

404 image

For the next few questions, use the confusion matrix above and assume that Forward is the positive label.

True or False: Measurements

Using Sklearn to Obtain Different Measurements

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Let’s calculate some measurements from our basketball dataset from the previous question.

Tasks:

  • Import the precision, recall, f1 and classification report libraries.
  • Predict the values on X_valid using the pipe_unbalanced and the .predict() function and save the result in an object named predicted_y.
  • Using sklearn tools, calculate precision, recall and f1 scores and save them in the respective names precision, recall, and f1. Make sure you are comparing the true y_valid labels to the predicted labels. You will need to assign a positive label to the β€œForward”(F) position. This can be specified in the pos_label of each function. Round each calculation to 3 decimal places.
  • Print a classification report of all the measurements comparing y_valid and predicted_y and assigning the target_names argument to ["F", "G"]. You can use the digits function to round all the calculations to 3 decimal places.
Hint 1
  • Are you using the arguments y_valid, predicted_y and pos_label="F" for the scoring functions?
  • Are you using the arguments y_valid, predicted_y and digits=3 for the classification_report function?
Fully worked solution: