cross.en: cross.en

Description Usage Arguments Details Value Author(s) Examples

View source: R/adaptive_refinement_help.R

Description

Calculates the weighted cross entropy / log-loss for a vector of observations and predicted probabilities (weighted by class proportions)

Usage

1
cross.en(pred, obs, sdpred=NULL, weighted=T)

Arguments

pred

a numeric vector, the predicted probabilities of the reference class

obs

the vector of observations, a categorical variable with 2-4 levels

sdpred

either NULL or a vector containing the standard deviations of every estimate

weighted

a boolean, if FALSE, the unweighted logloss is calculated. By default, the weighted cross entropy is calculated.

Details

if sdpred contains the standard deviations for each estimated probability, then a lower bound of the log loss is returned.

Value

a numeric value: cross entropy / log loss for comparison of classifiers. The smaller, the better.

Author(s)

Ann-Kristin Becker

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#observations
obs<-as.factor(c("A","A","B"))
#correct prediction
pred1<-c(1,1,0)
#wrong prediction
pred2<-c(0,0,1)

cross.en(pred=pred1, obs=obs) #small
cross.en(pred=pred2, obs=obs) #large

#prediction of only majority class
pred3<-c(1,1,1)
#prediction of only minority class
pred4<-c(0,0,0)

cross.en(pred=pred3, obs=obs, weighted=TRUE)
cross.en(pred=pred4, obs=obs, weighted=TRUE)
#both equal (as weighted)

cross.en(pred=pred3, obs=obs, weighted=FALSE)
cross.en(pred=pred4, obs=obs, weighted=FALSE)
#unweighted, majority class is favored

GroupBN documentation built on March 7, 2021, 5:06 p.m.

Related to cross.en in GroupBN...