CSVの行ごとに判定結果を知りたい
学習用データ(dataA.csv)でモデルを作成した後に、別のデータ(dataB.csv)をモデルにインプットして精度を計算するところまではできたのですが、どのデータが正解と認識され、どのデータを誤って分類したのか知る方法が分かりません。
Azure Machine Learningでは行ごとに予測クラスを確認する事ができた為、pythonでもできるのではと思い調べたのですが分かりませんでした。ご存知の方、教えていただけると幸いです。よろしくお願いします。
###python3でのコード(ライブラリのインポートは省略します)
#データ読み込み df = pd.read_csv('dataA.csv') df1 = pd.read_csv('dataB.csv') train_x = df.drop(['Class'], axis=1) train_y = df['Class'] (train_x, test_x ,train_y, test_y) = train_test_split(train_x, train_y, test_size = 0.3, random_state = 42) # モデル構築ランダムフォレスト random_forest = RandomForestClassifier(bootstrap=True, max_depth=10, n_estimators=10, random_state=42) random_forest.fit(train_x, train_y) # 予測値算出 y_pred = random_forest.predict(test_x) trainaccuracy_random_forest = random_forest.score(train_x, train_y) accuracy_random_forest = accuracy_score(test_y, y_pred) #評価用データ test_x1 = df1.drop(['Class'], axis=1) test_y1 = df1['Class'] y_pred1 = random_forest.predict(test_x1) random_forest = random_forest.score(test_x1, test_y1) #confusion matrix mat = confusion_matrix(test_y1, y_pred1) sns.heatmap(mat, square=True, annot=True, cbar=False, fmt='d', cmap='RdPu') plt.xlabel('predicted class') plt.ylabel('true value')
Confusin Matrixでの分類の可視化では、データごとの予測クラスを知る事ができない為、データごとの予測モデルを表示する方法を知りたいです。
回答1件
あなたの回答
tips
プレビュー