Learn R Programming

rfUtilities (version 2.1-5)

logLoss: Logarithmic loss (logLoss)

Description

Evaluation of estimate quality in binomial models using cross-entropy or log likelihood loss

Usage

logLoss(y, p, likelihood = FALSE, global = TRUE,
  eps = 0.000000000000001)

Arguments

y

vector of observed binomial values 0,1

p

vector of predicted probabilities 0-1

likelihood

(FALSE/TRUE) return log likelihood loss, default is (FALSE) for log loss

global

(TRUE/FALSE) return local or global log loss values, if FALSE local values are returned

eps

epsilon scaling factor to avoid NaN values

Value

If likelihood TRUE the log likelihood loss will be returned. If global FALSE, a list with observed (y), probability (p) and log loss (log.loss) otherwise, a vector of global log loss value

References

C.M. Bishop (2006). Pattern Recognition and Machine Learning. Springer, p. 209.

Examples

Run this code
# NOT RUN {
  require(randomForest)
    data(iris)
    iris$Species <- ifelse( iris$Species == "versicolor", 1, 0 ) 
    # Add some noise
      idx1 <- which(iris$Species %in% 1)
      idx0 <- which( iris$Species %in% 0)
      iris$Species[sample(idx1, 2)] <- 0
      iris$Species[sample(idx0, 2)] <- 1
    
 ( mdl <- randomForest(x=iris[,1:4], y=as.factor(iris[,"Species"])) )
	
  # Global log loss	
    logLoss(y = iris$Species, p = predict(mdl, iris[,1:4], type="prob")[,2]) 
			   
  # Local log loss
    ( ll <- logLoss(y = iris$Species, p = predict(mdl, iris[,1:4], 
                   type="prob")[,2], global = FALSE) )

  # Log likelihood loss
    logLoss(y = iris$Species, p = predict(mdl, iris[,1:4], 
			    type="prob")[,2], likelihood = TRUE) 
				   
# }

Run the code above in your browser using DataLab