sklearn を使用して、木の森の機能の重要性をプロットします。データフレームの名前は「ハート」です。ソートされた機能のリストを抽出するコードは次のとおりです。
importances = extc.feature_importances_
indices = np.argsort(importances)[::-1]
print("Feature ranking:")
for f in range(heart_train.shape[1]):
print("%d. feature %d (%f)" % (f + 1, indices[f], importances[indices[f]]))
次に、この方法でリストをプロットします。
f, ax = plt.subplots(figsize=(11, 9))
plt.title("Feature ranking", fontsize = 20)
plt.bar(range(heart_train.shape[1]), importances[indices],
color="b",
align="center")
plt.xticks(range(heart_train.shape[1]), indices)
plt.xlim([-1, heart_train.shape[1]])
plt.ylabel("importance", fontsize = 18)
plt.xlabel("index of the feature", fontsize = 18)
そして、私は次のようなプロットを取得します:
私の質問は、プロットをより理解しやすくするために、機能の NUMBER を機能の名前に置き換えるにはどうすればよいですか? フィーチャの名前 (データ フレームの各列の名前) を含む文字列を変換しようとしましたが、目標を達成できません。
ありがとう