赞
踩
# keras训练的model
# .predict() 输出预测的值
pre = model.predict(X_test, batch_size=batch_size)
pre, y_test
'''
array([[0.18804531, 0.3357192 , 0.47623548],
[0.30215347, 0.36785322, 0.32999334],
[0.18804531, 0.3357192 , 0.47623548],
[0.18804531, 0.3357192 , 0.47623548],
[0.18804531, 0.3357192 , 0.47623548],
[0.30215347, 0.36785322, 0.32999334],
[0.30215347, 0.36785322, 0.32999334],
[0.18804531, 0.3357192 , 0.47623548],
[0.30215347, 0.36785322, 0.32999334]])
array([[1., 0., 0.],
[1., 0., 0.],
[0., 1., 0.],
[1., 0., 0.],
[0., 1., 0.],
[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.],
[1., 0., 0.],
[0., 1., 0.]])
'''
# 进行转化
for idx1 in range(len(pre)):
max_val = max(pre[idx1])
for idx2 in range(len(pre[idx1])):
if max_val == pre[idx1][idx2]:
pre[idx1][idx2] = 1
else:
pre[idx1][idx2] = 0
from sklearn.metrics import f1_score, recall_score, precision_score
_val_f1 = f1_score(y_true=y_test, y_pred=pre, average='weighted')
_val_recall = recall_score(y_true=y_test, y_pred=pre, average='weighted')
_val_precision = precision_score(y_true=y_test, y_pred=pre, average='weighted')
print(" — val_f1: %f — val_precision: %f — val_recall: %f" % (_val_f1, _val_precision, _val_recall))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。