我一直在为XGBClassifier的这种古怪行为而头疼,它应该表现得像RandomForestClassifier一样好:
import xgboost as xgb
from sklearn.ensemble import RandomForestClassifier
class my_rf(RandomForestClassifier):
def important_features(self, X):
return super(RandomForestClassifier, self).feature_importances_
class my_xgb(xgb.XGBClassifier):
def important_features(self, X):
return super(xgb.XGBClassifier, self).feature_importances_
c1 = my_rf()
c1.fit(X,y)
c1.important_features(X) #works
当此代码失败时:(
^{pr2}$我盯着两个代码位看,它们看起来都一样!我错过了什么?? 抱歉,如果这是noob,python OOP的奥秘就在我之外。在
编辑:
如果我使用vanilla xgb,而不继承,则一切正常:
import xgboost as xgb
print "version:", xgb.__version__
c = xgb.XGBClassifier()
c.fit(X_train.as_matrix(), y_train.label)
print c.feature_importances_[:5]
version: 0.4
[ 0.4039548 0.05932203 0.06779661 0.00847458 0. ]
输出显示代码在0.4版本上,repository tree of last stable version of 0.4x(已发布}。
这个特性实际上是在this提交
Jan 15, 2016
)显示{a2}文件还没有{Feb 8, 2016
中引入的。在我克隆了当前的github存储库,从头构建并安装了
xgboost
,代码运行良好:输出:
^{pr2}$编辑:
如果使用的是}被移动到}访问。在
XGBRegressor
,请确保在Dec 1, 2016
之后克隆了存储库,因为根据this提交,此时{base XGBModel
进行{将此添加到上述代码中:
输出:
据我所知,
feature_importances_
在XGBoost中没有实现。您可以使用排列功能重要性之类的方法进行自己的滚动:相关问题 更多 >
编程相关推荐