Reputation: 115
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
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