在插入符号中使用eml:类概率的错误

时间:2014-11-15 19:57:56

标签: r r-caret

我试图将标准神经网络方法与极端学习机分类器(基于ROC度量)进行比较,使用R包"nnet"中的方法"elm"caret。对于nnet,一切正常,但使用method = "elm"我收到以下错误:

Error in evalSummaryFunction(y, wts = weights, ctrl = trControl, lev = classLevels,  : 
  train()'s use of ROC codes requires class probabilities. See the classProbs option of trainControl()
In addition: Warning messages:
1: In train.default(x, y, weights = w, ...) :
  At least one of the class levels are not valid R variables names; This may cause errors if class probabilities are generated because the variables names will be converted to: X1, X2
2: In train.default(x, y, weights = w, ...) :
  Class probabilities were requested for a model that does not implement them

method = "nnet"时我也遇到了第一个错误,但在这里我可以通过将得分作为因子变量来解决问题。因此,这不是问题所在。

我对R比较新,也许这个错误很简单,但是现在我被卡住了......既然elmNN似乎是相对新实现的,我也无法在网上找到任何关于如何在{ {1}}。

caret

1 个答案:

答案 0 :(得分:4)

我没有回忆为什么我没有包含ELM的概率模型(我可能有充分的理由)。您可以使用custom method获取softmax值:

library(caret)

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

elm_fun <- getModelInfo("elm")[[1]]
elm_fun$prob <- function (modelFit, newdata, submodels = NULL)  {
  out <- exp(predict(modelFit, newdata))
  t(apply(out, 1, function(x) x/sum(x)))
}
mod <- train(Class ~ ., data = dat, 
             method = elm_fun,
             metric = "ROC",
             trControl = trainControl(classProbs = TRUE,
                                      summaryFunction = twoClassSummary))

最高