python - 提取特征重要性系数/分数
问题描述
有没有办法从下面的代码片段中提取实际的特征重要性系数/分数(而不是顶级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)
解决方案
如果您的目标是提取适合最终简化数据集的估计器的特征重要性,则可以使用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_
。
推荐阅读
- chronicle-queue - 在 Chronicle Queue 中跳过文档的最佳方法是什么?
- r - 如何根据先前的值+值R中的其他列填充列
- javascript - 如何将给定的对象数组转换为所需的对象?
- .net-core - 确保 SignalR 服务中心断点未从 Azure 函数中命中
- javascript - 如何在条件 JSON 模式中对属性进行排序
- json - json.Unmarshal json 字符串到对象是空结果
- ionic-framework - stenciljs 删除主题参数
- typescript - “解耦”类的多态性和类型安全
- java - 获取 CameraX 最终分辨率
- c# - 在 .net core 3.0 preview9 项目中使用 System.Windows.Forms 类