votes up 0

y_prob contains values greater than 1.

Package:
Exception Class:
ValueError

Raise code

    if y_type != "binary":
        raise ValueError(
            f"Only binary classification is supported. The type of the target "
            f"is {y_type}."
        )

    if y_prob.max() > 1:
        raise ValueError("y_prob contains values greater than 1.")
    if y_prob.min() < 0:
        raise ValueError("y_prob contains values less than 0.")

    try:
        pos_label = _check_pos_label_consistency(pos_label, y_true)
    except ValueError:
        classes = np.unique(y_true)

Ways to fix

votes up 3 votes down

The cause of this error is that the y_prob array contains values greater than 1. Since y_prob is the probabilities of the positive class it is illogical to have an element that is greater than or less than 0.

How to reproduce the error:

import numpy as np
from sklearn.metrics import brier_score_loss
y_true = np.array([0, 1, 1, 0])
y_true_categorical = np.array(["spam", "ham", "ham", "spam"])
y_prob = np.array([2, 0.9, 0.8, 0.3])
brier_score_loss(y_true, y_prob)

Fix: make sure y_prob contains valid values.

import numpy as np
from sklearn.metrics import brier_score_loss
y_true = np.array([0, 1, 1, 0])
y_true_categorical = np.array(["spam", "ham", "ham", "spam"])
y_prob = np.array([1, 0.9, 0.8, 0.3])
brier_score_loss(y_true, y_prob)
Jun 10, 2021 kellemnegasi answer
kellemnegasi 2.7k

Add a possible fix

Please authorize to post fix