我希望利用caret包,使用一个不是默认选项的度量标准。在下面的例子中,我使用Metrics包。我已经阅读了StackOverflow上所有相关的问题以及caret网站上的指南,但仍然收到错误提示。
在下面的例子中,我希望使用平均绝对误差。
创建一个函数:
maefunction<-function(data, lev=NULL, model=NULL){
require(Metrics)
MAE<-mae(data[, "obs"], data[, "pred"])
out<-c(MAE)
out
}
现在我将该函数插入到trainControl中。
library(caret)
GBM<-train(train$result~., data=train, method="gbm", trControl=trainControl(summaryFunction=maefunction), metric=MAE)
我收到以下信息。
Error in list_to_dataframe(res, attr(.data, "split_labels"), .id, id_as_factor) :
Results must be all atomic, or all data frames
In addition: Warning messages:
1: In if (metric %in% c("Accuracy", "Kappa")) stop(paste("Metric", :
the condition has length > 1 and only the first element will be used
2: In if (metric == "ROC" & !ctrl$classProbs) stop("train()'s use of ROC codes requires class probabilities. See the classProbs option of trainControl()") :
the condition has length > 1 and only the first element will be used
3: In if (!(metric %in% perfNames)) { :
the condition has length > 1 and only the first element will be used
4: In train.default(x, y, weights = w, ...) :
The metric "4" was not in the result set. will be used instead.The metric "0.5" was not in the result set. will be used instead.