R xgb.重要性显示错误 - "feature_names has less elements than there are features used in the model"



我正在探索R中的XGBoost。 训练模型后,我想查看特征重要性数据。

xgb.importance(model = bst)

上面的调用显示以下错误。可能出了什么问题?

Error in xgb.model.dt.tree(feature_names = feature_names, text = model_text_dump, : feature_names has less elements than there are features used in the model

PN - 我检查了 xgboost 库代码的以下部分,但仍然无法找出实际问题。

# assign feature_names when available
if (!is.null(feature_names)) {
if (length(feature_names) <= max(as.numeric(td$Feature), na.rm = TRUE))
stop("feature_names has less elements than there are features used in the model")
td[isLeaf == FALSE, Feature := feature_names[as.numeric(Feature) + 1] ]
}

参考 - https://github.com/dmlc/xgboost/blob/master/R-package/R/xgb.model.dt.tree.R

我看到训练模型的nfeatures变量与传递给该模型的特征数量相同。

你的模型有feature_names功能吗? 也许试试xgb.importance(feature_names=colnames(bst$feature_names), model = bst).为我工作。

相关内容

最新更新