r - custom metric using ROCR package in caret -
here minimal example of problem. want use recall performance metric in caret
library(caret) set.seed(1234) x <- matrix(rnorm(10),nrow=5,ncol=2 ) y <- factor(c("y","n","y","y","n")) my.metric <- function (data, lev = null, model = null) { out <- rocr::performance(rocr::prediction(data$pred, as.numeric(data$obs)-1,"rec")) names(out) <- "rec" out } mycontrol <- traincontrol(summaryfunction = my.metric, method="repeatedcv", number=10, repeats=2) fit <- train(y=y,x=x, metric = "rec",method="gbm", trcontrol = mycontrol)
however, error
error in rocr::prediction(data$pred, as.numeric(data$obs) - 1, "rec") : format of predictions invalid.
i haven't used package in while based on example in ?prediction
, need pass class probabilities (and train
doesn't generate these unless use option classprobs = true
in traincontrol
) in argument predictions
. once have done that, use proper column of data
input prediction
function.
also, should read the paper on subject because think need call performance
recall.
max
Comments
Post a Comment