nll: Risk for Cross-Entropy Loss

Description Usage Arguments Examples

View source: R/risk.R

Description

Compute the empirical risk under cross-entropy loss for binary predictions.

Usage

1
nll(prediction, outcome)

Arguments

prediction

A numeric vector of predicted probabilities.

outcome

A numeric vector of binary outcomes actually observed.

Examples

1
2
3
4
5
6
7
8
n_obs <- 100
x <- rnorm(n_obs)
y <- rbinom(n_obs, 1, plogis(x^2))
test_x <- rnorm(n_obs)
test_y <- rbinom(n_obs, 1, plogis(test_x^2))
mod <- glm(y ~ x, family = "binomial")
pred <- predict(mod, newx = as.data.frame(test_x), type = "response")
error <- nll(prediction = unname(pred), outcome = test_y)

nhejazi/nima documentation built on March 10, 2020, 1:10 a.m.