sklearn のディシジョン ツリーの機能の重要性と、df の機能の対応する名前を一致させる辞書を作成しました。ここで以下のコード:
importances = clf.feature_importances_
feature_names = ['age','BP','chol','maxh',
'oldpeak','slope','vessels',
'sex_0.0','sex_1.0',
'pain_1.0','pain_2.0','pain_3.0','pain_4.0',
'bs_0.0','bs_1.0',
'ecg_0.0','ecg_1.0','ecg_2.0',
'ang_0.0','ang_1.0',
'thal_3.0','thal_6.0','thal_7.0']
CLF_sorted = dict(zip(feature_names, importances))
出力で私はこれを得ました:
{'BP': 0.053673644739136502,
'age': 0.014904980747733202,
'ang_0.0': 0.0,
'ang_1.0': 0.0,
'bs_0.0': 0.0,
'bs_1.0': 0.0,
'chol': 0.11125922817930389, ...}
私の期待通りに。2 つの質問があります。
feature_names
x 軸が を表し、y 軸が対応する棒グラフを作成するにはどうすればよいimportances
ですか?可能であれば、棒グラフを降順に並べ替えるにはどうすればよいですか?