【问题标题】:Error: "Not compatible with requested type" when plotting varImp错误:绘制 varImp 时“与请求的类型不兼容”
【发布时间】:2018-10-28 23:50:01
【问题描述】:

使用 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。

【问题讨论】:

  • 寻求帮助时,您应该包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出。您正在使用的变量的数据类型是什么。似乎一个人可能是一个角色,而绘图功能有问题。
  • 感谢您的信息,下次我会这样做。你是对的,公式中的一个参数是基于字符值的因素。如果我从公式中删除它,varImp 有效。

标签: r machine-learning data-mining r-caret


【解决方案1】:

来自 cmets:原因是公式中的一个参数是基于字符值的。解决办法是去掉这个参数(或者映射/转换成另一种数据类型)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多