我正在探索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 lib代码的以下部分,但仍然无法弄清实际问题。
# 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] ]
}
Ref-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)
。为我工作。