0

有没有办法从下面的代码片段中提取实际的特征重要性系数/分数(而不是顶级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)
4

1 回答 1

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_

于 2020-06-25T00:20:39.590 回答