You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Permutation Importance展示全部特征名称的技术求助

解决Permutation Importance输出全部特征权重的问题

eli5的show_weights方法默认仅展示权重排名靠前的20个特征,要输出所有特征,只需在调用时添加top=None参数:

import eli5
from eli5.sklearn import PermutationImportance

perm = PermutationImportance(rfc, random_state=1).fit(X_test, Y_test)
# 设置top=None以显示全部特征
eli5.show_weights(perm, feature_names=X_train.columns.tolist(), top=None)

如果需要将结果导出为文本格式(而非Jupyter的交互式输出),可以使用format_as_text配合explain_weights:

# 获取全量特征权重的文本结果
full_weights = eli5.explain_weights(perm, feature_names=X_train.columns.tolist(), top=None)
print(eli5.format_as_text(full_weights))

关键说明

  • top参数的默认值为20,专门用于控制展示的特征数量,设为None会强制包含数据集的所有特征。
  • 若特征数量庞大,输出结果会比较冗长,但这是获取全量特征权重的直接方案。

内容的提问来源于stack exchange,提问作者Saif_adib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 11:15:53