Calculate logloss or cross-entropy for a set of predictions.

logloss(prediction, outcome, tol = .Machine$double.neg.eps)

Arguments

prediction

A vector of estimated probabilities.

outcome

A vector of observed outcomes.

tol

Numerical tolerance. Can also be used to threshold errors for really bad predictions, or when you don't want a model to be penalized too strongly in the presence of high dispersion. Default is .Machine$double.neg.eps.

Value

a numeric vector

Examples

preds <- c(0.9, 0.1, 0.8, 0.5) outcomes <- c(1, 0, 1, 0) logloss(preds, outcomes)
#> [1] 0.2817529
# Thresholding large errors for bad predictions preds <- c(0.000001) outcomes <- c(1) logloss(preds, outcomes)
#> [1] 13.81551
logloss(preds, outcomes, 0.01)
#> [1] 4.60517