画像の分類器のモデルを作成し、評価を実行すると、エラーが発生します。
原因がどうも良く分かりません。
ご指導頂ければ助かります。
#optimizers ="Adadelta" optimizers ="adam" results = {} model.compile(loss='categorical_crossentropy', optimizer=optimizers, metrics=['accuracy']) #x_train, y_train, batch_size=batch_size, epochs=epochs,verbose=1, validation_data=(x_test, y_test) results= model.fit(x_train, y_train, validation_split=0.2, epochs=50,batch_size=128,verbose=0, validation_data=(x_test, y_test) ) model_json_str = model.to_json() open('dokugyo_mlp_weights.json', 'w').write(model_json_str) model.save_weights('dokugyo_mlp_weights.h5');
print(x_train.shape) print(y_train.shape) print(x_test.shape) print(y_test.shape) print(x_train) print(y_train) print(x_test) print(y_test) (101, 50, 50, 3) (101, 2) (26, 50, 50, 3) (26, 2) [[[[0.4 0.27450982 0.18431373] [0.87058824 0.84705883 0.9019608 ] [0.34901962 0.25882354 0.20392157] ... [0.7882353 0.615
# 評価の実行 from sklearn import metrics from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score predict_classes = model.predict_classes(x_test) score = model.evaluate(x_test,y_test) print('正確度(accuracy):', score[1]) print(' ') # 混同行列(Confusion Matrix) print(' ') from sklearn.metrics import confusion_matrix print(confusion_matrix(y_test, predict_classes)) # 詳しいレポート print(' ') print("classification report") print(metrics.classification_report(y_test, predict_classes)) 26/26 [==============================] - 0s 1ms/step 正確度(accuracy): 0.692307710647583
以下、エラーメッセージです。
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-21-7d8df345f99e> in <module> 12 print(' ') 13 from sklearn.metrics import confusion_matrix ---> 14 print(confusion_matrix(y_test, predict_classes)) 15 16 # 詳しいレポート ~\Anaconda3\lib\site-packages\sklearn\metrics\classification.py in confusion_matrix(y_true, y_pred, labels, sample_weight) 251 252 """ --> 253 y_type, y_true, y_pred = _check_targets(y_true, y_pred) 254 if y_type not in ("binary", "multiclass"): 255 raise ValueError("%s is not supported" % y_type) ~\Anaconda3\lib\site-packages\sklearn\metrics\classification.py in _check_targets(y_true, y_pred) 79 if len(y_type) > 1: 80 raise ValueError("Classification metrics can't handle a mix of {0} " ---> 81 "and {1} targets".format(type_true, type_pred)) 82 83 # We can't have more than one value on y_type => The set is no more needed ValueError: Classification metrics can't handle a mix of multilabel-indicator and binary targets
あなたの回答
tips
プレビュー