Skip to contents

Negative Log Loss

Usage

negative_log_loss(predicted_densities, ...)

Arguments

predicted_densities

The predicted densities from a learner predicted at newdata.

...

Because nadir::compare_learners() passes estimates, truth to the loss_metric passed to it, negative_log_loss accepts ... but doesn't do anything with it.

Value

A sum of the negative log loss given a vector of predicted probabilities/densities for some observed outcome.

Details

negative_log_loss encodes the logic: if \(\hat p_n\) is a good model of the conditional densities, then it should minimize: $$ -\sum(\log(\hat p_n(X_i)) $$

Examples

# suppose we have some prediction probabilities _at the true values_:
predicted_probabilities <- lnr_logistic(mtcars, am ~ hp)(mtcars)
# we can calculate the -log(loss) for binary predicted probabilities like so:
negative_log_loss(predicted_probabilities)
#> [1] 30.57476