我正在使用Caret的trainControl训练一个glmnet正则化逻辑回归模型,并使用metric =“ROC”训练函数如下,并得到以下错误:
> ctrl_s10_2class <- trainControl(method = "repeatedcv", number = 10, repeats = 10 , savePredictions = TRUE, classProbs = TRUE)
> model_train_glmnet_s10_2class <- train(Class ~ ZCR + Energy + SpectralC + SpectralS + SpectralE + SpectralF + SpectralR + MFCC1 + MFCC2 + MFCC3 + MFCC4 + MFCC5 + MFCC6 + MFCC7 + MFCC8 + MFCC9 + MFCC10 + MFCC11 + MFCC12 + MFCC13, data = training_s10_2class, method="glmnet", trControl = ctrl_s10_2class, metric = "ROC")
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, ...) :
You are trying to do regression and your outcome only has two possible values Are you trying to do classification? If so, use a 2 level factor as your outcome column.
2: In train.default(x, y, weights = w, ...) :
cannnot compute class probabilities for regression
但是我已经在trainControl函数中打开了classProbs = TRUE。另外,为了解决警告信息,我想我必须重新整理我的2类数据才能找到这个错误:
> sensor6data_s10_2class <- within(sensor6data_s10_2class, Class <- as.factor(Class))
> sensor6data_s10_2class$Class2 <- relevel(sensor6data_s10_2class$Class,ref="1")
> model_train_glmnet_s10_2class <- train(Class2 ~ ZCR + Energy + SpectralC + SpectralS + SpectralE + SpectralF + SpectralR + MFCC1 + MFCC2 + MFCC3 + MFCC4 + MFCC5 + MFCC6 + MFCC7 + MFCC8 + MFCC9 + MFCC10 + MFCC11 + MFCC12 + MFCC13, data = training_s10_2class, method="glmnet", trControl = ctrl_s10_2class, metric = "ROC")
Error in train.default(x, y, weights = w, ...) :
At least one of the class levels is not a valid R variable name; This will cause errors when class probabilities are generated because the variables names will be converted to X1, X0 . Please use factor levels that can be used as valid R variable names (see ?make.names for help).
非常感谢任何帮助解决这个问题,无论有没有重新定位!感谢。
答案 0 :(得分:0)
1:在train.default(x,y,weights = w,...)中: 您正在尝试进行回归,而您的结果只有两个可能的值您是否尝试进行分类?如果是这样,请使用2级因子作为结果列。
似乎是使用数据形式的错误。您可以尝试将其转换为一个因素:
training_s10_2class$Class2 = as.factor(training_s10_2class$Class2)
有了这个,你不再需要
classProbs = TRUE
当你删除它时,它应该处理你的第二个警告
2:在train.default(x,y,weights = w,...)中: 无法计算回归的类概率