随机森林特征重要性得分的解读

问题描述 投票:0回答:2

为什么我的特征重要性分数是 0.00-0.08。这是否表明这些功能与我的模型无关?

## Exclude columns nor required in cols_to_exclude
X_train, X_test, y_train, y_test = prepare_model_originaldata(df,class_col='Pathology',
                                                 cols_to_exclude=cols_to_exclude)
models_report, conf_matrix = run_rf(X_train,y_train,X_test,y_test, 'Original Data') # change model accordingly
final_report = final_report.append(models_report, ignore_index=True)
models_report

enter image description here

for name in conf_matrix.keys():
  import seaborn as sns
  print(f"Confusion Matrix for {name} :")
  sns.heatmap(conf_matrix[name],annot=True,cmap="Blues",fmt="g", xticklabels=['HC','IBM'], yticklabels=['HC','IBM'])
  plt.show()
  print('\n')

enter image description here

rf, y_pred_b, y_pred2_b = classify_rf(X_train, y_train,X_test,y_test)

精度:0.868421052631579 ROC 曲线下面积:0.9375 F 公制:0.9056603773584906

分类报告: 精确召回 f1 分数支持

       0       1.00      0.64      0.78        14
       1       0.83      1.00      0.91        24

accuracy                           0.87        38

宏观平均 0.91 0.82 0.84 38 加权平均 0.89 0.87 0.86 38

plot_feature_importance(rf.feature_importances_,X_train.columns,rf)

enter image description here

还没有尝试过

python random-forest sklearn-pandas
2个回答
0
投票

随机森林每列的特征重要性分数总和为 1。 所以

feature_importance(CD8+Tbet) + ... + feature_importance(CD8Temra) = 1

现在单个特征重要性得分的值非常低是因为数据中存在的列数较多(特征重要性图中大约有 70 列)。这些分数是相对的。在训练随机森林模型时,您可以删除那些不太重要的特征(可能只是噪音),这不会严重影响您的模型性能。


0
投票

假设你使用的是基于标签的

sklearn
,我们可以看看RandomForest Classifier关于特征重要性的文档,回归版本应该是相似的。

这个数组的值总和为 1,除非所有树都是仅由根节点组成的单节点树,在这种情况下它将是一个零数组。

由于你有很多特征(粗略计算约 70 个),如果每个特征都同等重要,那么它们的重要性约为 0.014。当然,有些特征比较重要,有些不那么重要,因此你有一系列的值,但它们加起来应该都是 1。

© www.soinside.com 2019 - 2024. All rights reserved.