8.19.1.16. sklearn.metrics.zero_one_loss

sklearn.metrics.zero_one_loss(y_true, y_pred, normalize=True)

Zero-One classification loss

If normalize is True, return the fraction of misclassifications (float), else it returns the number of misclassifications (int). The best performance is 0.

Parameters:

y_true : array-like

y_pred : array-like

normalize : bool, optional

If False (default), return the number of misclassifications. Otherwise, return the fraction of misclassifications.

Returns:

loss : float or int,

If normalize == True, return the fraction of misclassifications (float), else it returns the number of misclassifications (int).

Examples

>>> from sklearn.metrics import zero_one_loss
>>> y_pred = [1, 2, 3, 4]
>>> y_true = [2, 2, 3, 4]
>>> zero_one_loss(y_true, y_pred)
0.25
>>> zero_one_loss(y_true, y_pred, normalize=False)
1
Previous
Next