r - R:使用 FeatureImp$new 绘制重要性特征
问题描述
这是代码
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 失败 - “存储的特征名称
object
不同newdata
!”
我尝试检查模型和数据中的特征名称,但它们都相似。因此,我不明白这个错误究竟是什么“存储的功能名称object
不同newdata
!”
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"
解决方案
这是一个xgboost
问题:https ://github.com/dmlc/xgboost/issues/1809
它关于变量的顺序。
X = X[mod$learner.model$feature_names]
应该解决它。几天前我遇到了同样的问题。
编辑:错误仍然存在,可能是因为iml
. 但修复绝对是要走的路,因为使用xgboost
.
推荐阅读
- html - 如何在不使用图像的情况下在 css 中创建曲线
- javascript - 用nodejs处理mysql连接
- c# - 带改装的多部分内容
- asp.net - 'IEnumerable
' 不包含 'Alert_Identifier' ... 和 'IEnumerable 的定义 ' 不包含 'AlertIndex' 的定义 - latex - 使用 paracol 和 \setlength{\columnseprule}{} 改变垂直线的颜色
- spring-boot - Spring Boot 1 Actuator 是否在外部 Tomcat 中工作
- reactjs - 无法使用 Create-React-App 在 github 页面中发布我的反应应用程序 - 控制台出现错误
- r - 带置信区间的滚动回归(tidyverse)
- javascript - 每秒运行一次函数 X 次
- sql - 卡在 SQL Server 过程代码上