質問が把握できていないかもしれませんが、やりたいことは以下のようなことでしょうか。参考まで。
Python
1import numpy as np
2from sklearn.datasets import load_iris
3from sklearn.model_selection import train_test_split
4from sklearn.metrics import accuracy_score
5from sklearn.ensemble import RandomForestClassifier
6
7import pandas as pd
8
9# アイリスデータ
10df = pd.read_csv('http://home.a00.itscom.net/hatada/ml/data/iris.csv', encoding='shift_jis')
11X = df.iloc[:, 0:4].values
12y = pd.Categorical(df.iloc[:,4]).codes
13
14X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
15
16clf_rf = RandomForestClassifier()
17clf_rf.fit(X_train, y_train)
18y_pred = clf_rf.predict(X_test)
19
20accu = accuracy_score(y_test, y_pred)
21print('accuracy = {:>.4f}'.format(accu))
22
23# Feature Importance
24fti = clf_rf.feature_importances_
25
26feature_names = df.columns[0:4]
27
28print('Feature Importances:')
29for i, feat in enumerate(feature_names):
30 print('\t{0:20s} : {1:>.6f}'.format(feat, fti[i]))
31"""
32accuracy = 0.9333
33Feature Importances:
34 がく片 : 0.089579
35 がく片幅 : 0.026769
36 花びら : 0.435210
37 花びら幅 : 0.448442
38"""