log_loss#

cuml.metrics.log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None) float[source]#

Log loss, aka logistic loss or cross-entropy loss. This is the loss function used in (multinomial) logistic regression and extensions of it such as neural networks, defined as the negative log-likelihood of a logistic model that returns y_pred probabilities for its training data y_true. The log loss is only defined for two or more labels.

Parameters:
y_truearray-like, shape = (n_samples,)
y_predarray-like of float,

shape = (n_samples, n_classes) or (n_samples,)

epsfloat (default=1e-15)

Log loss is undefined for p=0 or p=1, so probabilities are clipped to max(eps, min(1 - eps, p)).

normalizebool, optional (default=True)

If true, return the mean loss per sample. Otherwise, return the sum of the per-sample losses.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
lossfloat

Notes

The logarithm used is the natural logarithm (base-e).

References

C.M. Bishop (2006). Pattern Recognition and Machine Learning. Springer, p. 209.

Examples

>>> from cuml.metrics import log_loss
>>> import cupy as cp
>>> log_loss(cp.array([1, 0, 0, 1]),
...          cp.array([[.1, .9], [.9, .1], [.8, .2], [.35, .65]]))
0.21616...