Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Log_loss is calculated incorrectly when only 1 class present #6703

@snv2

Description

@snv2

Description

Log_loss uses LabelBibarizer to transform only original y_true, but not to transform y_pred.
Hence array y_true=[1,1,1] is transformed into [0,0,0], while y_pred is unchanged. This makes the result to be quite different from expected.

Sample code

from sklearn.metrics import log_loss
y_true = [1,1,1]
y_pred = [0,0,0]
print(log_loss(y_true,y_pred))  # incorrect, because y_true is transformed into [0,0,0]
print(log_loss(y_pred,y_true))  # correct

Expected Results

34.5395759923
34.5395759923

Actual Results

9.99200722163e-16
34.5395759923

Versions

Windows-7-6.1.7601-SP1
Python 3.4.4 |Anaconda 2.3.0 (64-bit)| (default, Feb 16 2016, 09:54:04) [MSC v.1600 64 bit (AMD64)]
NumPy 1.10.4
SciPy 0.16.0
Scikit-Learn 0.16.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions