Easy Points
Easy Points

Reputation: 115

log loss should be easy to calculate but it is not

Why it is not working:

from sklearn.metrics import log_loss
y_true = [0, 0, 0, 0]
y_pred = [0.5, 0.5, 0.5, 0.5]
log_loss(y_true, y_pred, eps=1e-15)
Error: ValueError: Unknown label type: ((0.5, 0.5, 0.5, 0.5),)

Upvotes: 0

Views: 246

Answers (1)

Stefan B
Stefan B

Reputation: 1677

log_loss does not know (cannot infer) what labels there are since there's just one unique label in your example.

from sklearn.metrics import log_loss

y_true = [0] * 4
y_pred = [0.5] * 4
log_loss(y_true, y_pred, labels=[0, 1]) # 0.6931471805599453

alternatively labels can be inferred if there is more than one unique label in y_true:

from sklearn.metrics import log_loss

y_true = [0, 0, 0, 0, 1]
y_pred = [0.2, 0.4, 0.3, 0.7, 0.99]
log_loss(y_true, y_pred) # 0.46093345183967405

Upvotes: 2

Related Questions