2
$\begingroup$

The following code are used to produce the probability output of binary classification with Random Forest.

library(randomForest) 

rf <- randomForest(train, train_label,importance=TRUE,proximity=TRUE)
prediction<-predict(rf, test, type="prob")

Then the result about prediction is as follows:

enter image description here

The true label about test data are known (named test_label). Now I want to compute logarithmic loss for probability output of binary classification. The function about LogLoss is as follows.

LogLoss=function(actual, predicted)
{
  result=-1/length(actual)*(sum((actual*log(predicted)+(1-actual)*log(1-predicted))))
  return(result)
}

How to compute logarithmic loss with probability output of binary classification. Thank you.

$\endgroup$

1 Answer 1

2
$\begingroup$

Looks like you already have everything you need, assuming you also have a vector of labels for the test set (call it test_labels). You can now just say LogLoss(test_labels, prediction[,1]).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.