Here is the code
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")
I got the following error
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.
Error in estimate.feature.imp(feature, data.sample = data.sample, y = y, : task 1 failed - "Feature names stored in
object
andnewdata
are different!"
I tried checking the feature names in model and data but both of them are similar. Hence, I dont understand what exactly is this error
"Feature names stored in object
and newdata
are different!"
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"