Get startedGet started for free

Plotting the Precision Recall Curve

You can also plot a Precision-Recall curve, to investigate the trade-off between the two in your model. In this curve Precision and Recall are inversely related; as Precision increases, Recall falls and vice-versa. A balance between these two needs to be achieved in your model, otherwise you might end up with many false positives, or not enough actual fraud cases caught. To achieve this and to compare performance, the precision-recall curves come in handy.

Your Random Forest Classifier is available as model, and the predictions as predicted. You can simply obtain the average precision score and the PR curve from the sklearn package. The function plot_pr_curve() plots the results for you. Let's give it a try.

This exercise is part of the course

Fraud Detection in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate average precision and the PR curve
average_precision = ____(____, ____)
Edit and Run Code