Caret Binary Classification with RMSE

痴心易碎 提交于 2019-12-24 00:30:19

问题


Is there a way to get caret to use RMSE with a binary classification problem?

If you try to use metric = "RMSE" with a classification problem you will receive the message:

Error in train.default(x, y, weights = w, ...) :
    Metric RMSE not applicable for classification models

Which makes sense. But is there a way to define a custom metric? For example, if your outcome is 0 or 1, you can define the error as outcome - p where p is the probability predicted by the model.

EDIT ====================

To give this some context and for some reasoning behind wanting to use this measure, see 2.7.1 in An Experimental Analysis of Classifier Ensembles for Learning Drifting Concepts Over Time in Autonomous Outdoor Robot Navigation by Michael J. Procopio, or the paper on softclassval


回答1:


I don't know why you would want to do this but you can make your own summary function:

library(caret)

set.seed(1)
dat <- twoClassSim(100)

foo <- function(data, lev = NULL, model = NULL) {
  probs <- data[, lev[1]]
  c(rmse = RMSE(pred = probs,
                obs = ifelse(data$obs == lev[1], 1, 0)))
}

ctrl <- trainControl(classProbs = TRUE,
                     summaryFunction = foo)
set.seed(2)
mod <- train(Class ~ ., data = dat,
             method = "lda",
             metric = "rmse",
             minimize = TRUE,
             trControl = ctrl)

Max




回答2:


Y should be a factor. Use as.factor() on it before training the model.



来源:https://stackoverflow.com/questions/20376668/caret-binary-classification-with-rmse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!