Skip to content

Plot rate curve

plot_rate_curve(x_values, y_values, plot_type='success_rate')

Plot success rate, prediction rate or ROC curve.

Plot type depends on plot_type argument. Y-axis is always true positive rate, while x-axis can be either false positive rate (roc) or proportion of area (success and prediction rate) depending on plot type.

Parameters:

Name Type Description Default
x_values Union[ndarray, Series]

False positive rate values or proportion of area values.

required
y_values Union[ndarray, Series]

True positive rate values.

required
plot_type Literal[success_rate, prediction_rate, roc]

Plot type. Can be either: "success_rate", "prediction_rate" or "roc".

'success_rate'

Returns:

Type Description
Figure

Success rate, prediction rate or ROC plot figure object.

Raises:

Type Description
InvalidParameterValueException

Invalid plot type.

InvalidParameterValueException

x_values or y_values are out of bounds.

Source code in eis_toolkit/validation/plot_rate_curve.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@beartype
def plot_rate_curve(
    x_values: Union[np.ndarray, pd.Series],
    y_values: Union[np.ndarray, pd.Series],
    plot_type: Literal["success_rate", "prediction_rate", "roc"] = "success_rate",
) -> matplotlib.figure.Figure:
    """Plot success rate, prediction rate or ROC curve.

    Plot type depends on plot_type argument. Y-axis is always true positive rate, while x-axis can be either false
    positive rate (roc) or proportion of area (success and prediction rate) depending on plot type.

    Args:
        x_values: False positive rate values or proportion of area values.
        y_values: True positive rate values.
        plot_type: Plot type. Can be either: "success_rate", "prediction_rate" or "roc".

    Returns:
        Success rate, prediction rate or ROC plot figure object.

    Raises:
        InvalidParameterValueException: Invalid plot type.
        InvalidParameterValueException: x_values or y_values are out of bounds.
    """
    if plot_type == "success_rate":
        label = "Success rate"
        xlab = "Proportion of area"
    elif plot_type == "prediction_rate":
        label = "Prediction rate"
        xlab = "Proportion of area"
    elif plot_type == "roc":
        label = "ROC"
        xlab = "False positive rate"
    else:
        raise InvalidParameterValueException("Invalid plot type")

    if x_values.max() > 1 or x_values.min() < 0:
        raise InvalidParameterValueException("x_values should be within range 0-1")

    if y_values.max() > 1 or y_values.min() < 0:
        raise InvalidParameterValueException("y_values should be within range 0-1")

    fig = _plot_rate_curve(x_values=x_values, y_values=y_values, label=label, xlab=xlab)

    return fig