【问题标题】:R: Plotting importance feature using FeatureImp$newR:使用 FeatureImp$new 绘制重要性特征
【发布时间】:2018-08-28 20:37:57
【问题描述】:

这里是代码

library(mlr)
library(xgboost)
library(iml)
data("iris")
tsk = makeClassifTask(data = iris, target = "Species")
lrn = makeLearner("classif.xgboost",predict.type = "prob")
mod = mlr:::train(lrn, tsk)
X = iris[which(names(iris) != "Species")]
predictor = Predictor$new(mod, data = X, y = iris$Species)
imp = FeatureImp$new(predictor, loss = "ce")

我收到以下错误

imp = FeatureImp$new(predictor, loss = "ce")
Warning in predict.WrappedModel(model, newdata = newdata) :
  Provided data for prediction is not a pure data.frame but from class data.table, 
  hence it will be converted.

estimate.feature.imp(feature, data.sample = data.sample, y = y, 中的错误: 任务 1 失败 - “存储在 objectnewdata 中的功能名称不同!”

我尝试检查模型和数据中的特征名称,但它们都相似。因此,我不明白这个错误到底是什么 "存储在objectnewdata 中的功能名称不同!"

colnames(X)
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width" 

mod$learner.model$feature_names    
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width" 

【问题讨论】:

  • PredictorFeatureImp 来自哪里?
  • 它们来自 iml 包
  • 看起来像 iml 包中的一个错误——从帮助中运行示例时我也遇到了错误。你应该为此open an issue
  • 我打开了一个问题:github.com/christophM/iml/issues/46

标签: r xgboost mlr


【解决方案1】:

这是一个xgboost 问题:https://github.com/dmlc/xgboost/issues/1809

关于变量的顺序。

X = X[mod$learner.model$feature_names]

应该解决它。几天前我遇到了同样的问题。

编辑:错误仍然存​​在,可能是因为iml 的洗牌再次出现了一些混乱。但修复绝对是可行的方法,因为使用 xgboost 的预测调用也会发生此错误。

【讨论】:

    猜你喜欢
    • 2017-11-14
    • 2020-08-24
    • 2021-11-13
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 1970-01-01
    相关资源
    最近更新 更多