首页 > 解决方案 > 提取特征重要性系数/分数

问题描述

有没有办法从下面的代码片段中提取实际的特征重要性系数/分数(而不是顶级num_feats特征)?

from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
rfe_selector = RFE(estimator=LogisticRegression(), n_features_to_select=num_feats, step=10, verbose=5)
rfe_selector.fit(X_norm, y)

标签: pythonscikit-learnfeature-selectionsklearn-pandasrfe

解决方案


如果您的目标是提取适合最终简化数据集的估计器的特征重要性,则可以使用estimator_属性访问此估计器并提取其系数或特征重要性分数:

from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression

rfe_selector = RFE(estimator=LogisticRegression(), n_features_to_select=num_feats, step=10, verbose=5)
rfe_selector.fit(X_norm, y)

coefs = rfe_selector.estimator_.coef_[0]

当然,如果您必须调用coef_或,这取决于使用的估算器feature_importances_


推荐阅读