私は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)
と私はこのようなプロットを得る:
に私の質問は:プロットをより理解しやすくするために、フィーチャの番号をフィーチャの名前に置き換えるにはどうすればよいですか? 機能の名前(データフレームの各列の名前)を含む文字列を変換しようとしましたが、目標に到達できません。
おかげ
ありがとう!今私は右の列と正しい重要性を一致させる必要があります。 – ElenaPhys
右の列と正しい重要度を一致させる方法を見つけましたか? – Amy21