我试图为给定数据集选择重要特征(或至少了解哪些特征解释更多可变性)。为了实现这个我同时使用ExtraTreesClassifier和GradientBoostingRegressor - 然后用: -feature_importances_在ExtraTreesClassifier中显示为NoneType:TypeError:'NoneType'对象不可迭代
clf = ExtraTreesClassifier(n_estimators=10,max_features='auto',random_state=0) # stops after 10 estimation passes, right ?
clf.fit(x_train, y_train)
feature_importance=clf.feature_importances_ # does NOT work - returns NoneType for feature_importance
帖子这个我在绘制它们(视觉表现)很感兴趣 - 甚至是初步的,只是看的相对顺序重视和相应的指数
# Both of these do not work as the feature_importance is of NoneType
feature_importance = 100.0 * (feature_importance/feature_importance.max())
indices = numpy.argsort(feature_importance)[::-1]
我发现令人费解的是 - 如果我下面用GradientBoostingRegressor,我得到了feature_importance及其指数。我究竟做错了什么 ?
#Works with GradientBoostingRegressor
params = {'n_estimators': 100, 'max_depth': 3, 'learning_rate': 0.1, 'loss': 'lad'}
clf = GradientBoostingRegressor(**params).fit(x_train, y_train)
clf.fit(x_train, y_train)
feature_importance=clf.feature_importances_
其他信息:我有12个独立的增值经销商(x_train)和一个标签VAR(y_train))与多个值(比如4,5,7)和式(x_train)是和类型(feature_importance)是
致谢:某些元素从该交http://www.tonicebrian.com/2012/11/05/training-gradient-boosting-trees-with-python/
工作得到compute_importances数组 - 谢谢你和+1。你能否提一下如何选择n_estimators?关于scikit-learn文档,关于这方面的信息很少 - 我可以随机化这个,并且*看*哪一个很适合(通过适合度)? – ekta
确定“合适”时,您可能希望监视验证集上的预测误差,而不是训练集上的误差以避免过度拟合。例如,你可以尝试不断增加的迭代次数,训练错误应该持续下降 - 但是当验证错误开始增长时你会停下来。 –