plot_pr_curve

keras.plot_pr_curve(y_true, y_pred, *, title='Precision-recall curve')

Draw a binary classifier’s precision-recall curve from its predictions.

Parameters

Name Type Description Default
y_true array_like Whether each sample is positive: 1 or True for the positive class, or one-hot rows of two classes. required
y_pred array_like or dict of str to array_like What model.predict returns: one sigmoid output per sample, as a column or flat, or two-class softmax rows, whose second column is the positive class’s score. Several models’ predictions by name draw a line each. required
title str The chart’s title. "Precision-recall curve"

Returns

Name Type Description
matplotlib.figure.Figure The chart, ready for :func:maidr.show, :func:maidr.render or :func:maidr.save_html. Not managed by pyplot.

Raises

Name Type Description
ValueError If the labels are not 0 and 1 (or two-class one-hot rows) or hold no positive sample, if there are no predictions, or if the predictions are not a score per sample or two-class rows.

Notes

Each line is named with its average precision and the precision a classifier guessing at random reaches – the share of positives – which is drawn as a dashed line, as :func:maidr.read_tensorboard_pr_curves draws TensorBoard’s PR curves.

Examples

>>> import maidr
>>> from maidr.keras import plot_pr_curve
>>> maidr.show(plot_pr_curve(y_test, model.predict(x_test)))