提取特征重要性系数/分数

时间:2020-06-24 23:14:47

标签: python scikit-learn feature-selection sklearn-pandas rfe

是否有任何方法可以从以下代码段(与排名靠前的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)

1 个答案:

答案 0 :(得分:1)

如果您的目标是提取适合最终精简数据集的估计量的特征重要性,则可以使用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_取决于使用的估计量。