Computes the logarithmic loss (cross-entropy loss) for binary probabilistic predictions.
Arguments
- x
a numeric vector containing predicted probabilities in \([0,1]\)
- ...
further arguments passed to methods
- ref
numeric or logical vector containing the observed binary outcomes (0/1), the reference the predictions are scored against. Factors are not accepted, as the choice of the positive level would have to be guessed.
- eps
Numeric scalar in \((0, 0.5)\) used to clip probabilities away from 0 and 1. Defaults to
.Machine$double.eps.
Details
Log loss is defined as
$$LL = -\frac{1}{n}\sum_{i=1}^n \left[y_i \log(\hat p_i) + (1-y_i)\log(1-\hat p_i)\right],$$
where \(y_i \in \{0,1\}\) and \(\hat p_i\) is the predicted probability of the positive class. Lower values indicate better probabilistic predictions; a perfect model has log loss 0.
Before taking logarithms the predictions are clipped into the closed
interval \([\epsilon, 1-\epsilon]\), so that a prediction of exactly 0
or 1 contributes a finite penalty of at most \(-\log(\epsilon)\)
(about 36.0 for the default eps) instead of Inf.
Being the negative Bernoulli log-likelihood per observation, log loss
equals deviance(fit) / (2 * n) for a binomial glm fitted to
ungrouped data. Methods for fitted models are provided by the package
alloy.
See also
Other model.metrics:
auc(),
averagePrecision(),
brierScore(),
mae(),
mape(),
mse(),
nmae(),
nmse(),
rmse(),
smape()
