相关疑难解决方法(0)

使用XGBClassifier进行功能重要性

希望我读错了,但是在XGBoost库文档中,有一些提示使用feature_importances_很多像sklearn的随机森林来提取特征重要性属性.

但是,出于某种原因,我不断收到此错误: AttributeError: 'XGBClassifier' object has no attribute 'feature_importances_'

我的代码段如下:

from sklearn import datasets
import xgboost as xg
iris = datasets.load_iris()
X = iris.data
Y = iris.target
Y = iris.target[ Y < 2] # arbitrarily removing class 2 so it can be 0 and 1
X = X[range(1,len(Y)+1)] # cutting the dataframe to match the rows in Y
xgb = xg.XGBClassifier()
fit = xgb.fit(X, Y)
fit.feature_importances_
Run Code Online (Sandbox Code Playgroud)

您似乎可以Booster通过调用get_fscore属性来使用对象计算要素重要性.我使用的唯一理由XGBClassifierBooster,是因为它能够被包裹在一个sklearn管道.有关功能提取的任何想法?还有其他人遇到过这种情况吗?

python scikit-learn xgboost

12
推荐指数
4
解决办法
2万
查看次数

标签 统计

python ×1

scikit-learn ×1

xgboost ×1