0
0
TensorFlowml~10 mins

Precision-recall curves in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function that computes precision and recall.

TensorFlow
from sklearn.metrics import [1]
Drag options to blanks, or click blank then click option'
Aprecision_recall_curve
Broc_curve
Caccuracy_score
Dconfusion_matrix
Attempts:
3 left
💡 Hint
Common Mistakes
Importing roc_curve instead, which is for ROC curves.
Importing accuracy_score, which does not provide precision or recall values.
2fill in blank
medium

Complete the code to compute precision and recall from true labels and predicted scores.

TensorFlow
precision, recall, thresholds = precision_recall_curve(y_true, [1])
Drag options to blanks, or click blank then click option'
Ay_labels
By_pred
Cy_scores
Dy_prob
Attempts:
3 left
💡 Hint
Common Mistakes
Passing binary predictions instead of scores.
Passing true labels again instead of predicted scores.
3fill in blank
hard

Fix the error in the code to plot the precision-recall curve correctly.

TensorFlow
plt.plot(recall, [1])
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.title('Precision-Recall Curve')
plt.show()
Drag options to blanks, or click blank then click option'
Ay_scores
Bthresholds
Cy_true
Dprecision
Attempts:
3 left
💡 Hint
Common Mistakes
Plotting thresholds instead of precision.
Plotting true labels or scores instead of precision.
4fill in blank
hard

Fill both blanks to compute average precision score and print it.

TensorFlow
from sklearn.metrics import [1]
avg_precision = [2](y_true, y_scores)
print(f'Average Precision: {avg_precision:.2f}')
Drag options to blanks, or click blank then click option'
Aaverage_precision_score
Bprecision_recall_curve
Droc_auc_score
Attempts:
3 left
💡 Hint
Common Mistakes
Importing roc_auc_score instead, which is for ROC AUC.
Using precision_recall_curve instead of average_precision_score.
5fill in blank
hard

Fill all three blanks to create a dictionary of precision and recall values for thresholds above 0.5.

TensorFlow
pr_dict = {threshold: ([1], [2]) for precision, recall, threshold in zip(precision, recall, [3]) if threshold > 0.5}
Drag options to blanks, or click blank then click option'
Aprecision
Brecall
Cthresholds
Dy_scores
Attempts:
3 left
💡 Hint
Common Mistakes
Using y_scores instead of thresholds in the zip.
Swapping precision and recall order in the tuple.