Error: "Not compatible with requested type" when plotting varImp

Error: "Not compatible with requested type" when plotting varImp

使用 caret 包在 R 中训练模型时,在绘制模型的变量重要性时出现错误。几种挖掘算法(bayesglm、glm、naive_bayes、...)都会发生这种情况。

control <- trainControl(method = "repeatedcv",
                      number = iterations,
                      savePredictions = TRUE,
                      classProbs = TRUE,
                      sampling = "smote");

modelFit <- train(formulaToUse,
                data = dataToAnalyze,
                method = miningAlgorithm, 
                family = "binomial", 
                preProcess = NULL, 
                trControl = control,
                tuneLength = 4);

plot(varImp(modelFit, scale = TRUE));

结果:

Error in auc_(actual, predicted, ranks) : 
Not compatible with requested type: [type=character; target=double].

请注意,模型已成功挖掘,summary(modelFit) 显示有关模型的信息。

有什么想法吗?

R 版本为 3.4.3,插入符号为 caret_6.0-79.

来自评论:原因是公式中的一个参数基于字符值。解决方案是删除此参数(或将其映射/转换为另一种数据类型)。