如何在训练期间的每个时期后计算多类分类问题的精度和召回率?

How to calculate precision, recall in multiclass classification problem after each epoch during training?

我正在使用 Tensorflow 1.15.0 和 keras 2.3。1.I正在尝试为我的训练数据计算每个时期的六个 class class化问题的精度和召回率和训练期间的验证数据。 我可以使用 classification_report 但它只有在训练完成后才有效。

from sklearn.metrics import classification_report
y_pred = final.predict(X_test)
y_indx = np.argmax(y_test_new, axis = 1)
pred_indx = np.argmax(y_pred, axis = 1)
print(classification_report(y_indx, pred_indx))

网络 ResNet154 的结果如下所示,我的数据集是平衡的。

             precision    recall  f1-score   support

       0       0.00      0.00      0.00    172482
       1       0.00      0.00      0.00    172482
       2       0.00      0.00      0.00    172482
       3       0.00      0.00      0.00    172482
       4       0.00      0.00      0.00    172482
       5       0.17      1.00      0.29    172482


accuracy                           0.17   1034892
macro avg       0.03      0.17      0.05   1034892
weighted avg       0.03      0.17      0.05   1034892

我只是想通过使用回调来检查我的训练数据的精度和召回率以及 f1 分数,以确保它是否过度拟合网络。

您需要定义一个特定的回调才能执行此操作。

您的问题的一种解决方案可在以下文章中找到:https://medium.com/@thongonary/how-to-compute-f1-score-for-each-epoch-in-keras-a1acd17715a2

上面的文章提到了如何在每个 epoch 结束时计算你想要的指标。

否则,您可以定义一个自定义回调,您可以在其中访问您的验证集;在 on_epoch_end() 中,你会得到 TPTNFNFP 的数量,你可以用它来计算你想要的所有指标。

此外,您可以查看此处编写的示例(适用于 TensorFlow 2.X 版本,>=2.1):