我有一组与二进制类标签关联的特征向量,每个特征向量都有大约40,000个特征。我训练使用随机森林分类RandomForestClassifier
从sklearn
大约需要10分钟。但是,我想看看哪些是最重要的功能。
我尝试简单地打印出来,clf.feature_importances_
但是每个功能大约需要1秒,因此总共需要大约40,000秒(大约12个小时)。这比最初训练分类器所需的时间长得多!
有没有更有效的方法来找出哪些功能最重要?
这是我的意思的示例:
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(n_estimators=50)
clf = clf.fit(X, Y)
for i in xrange(len(clf.feature_importances_)):
print clf.feature_importances_[i]
您需要做的就是将结果存储clf.feature_importances_
在数组中,然后使用它来打印结果。喜欢:
from sklearn.ensemble import RandomForestClassifier
clf = RandomForestClassifier(n_estimators=50)
clf = clf.fit(X, Y)
featureImportance = clf.feature_importances_
for i in xrange(len(featureImportance)):
print featureImportance[i]
您现在处理它的方式是每一次重新计算数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句