Open david-b-6 opened 5 years ago
@david-b-6, thank you for the issue. In the code above I don't see how you print the metrics from keras-metrics
package, there is only evaluation through sklearn
.
I've extended unit test to perform cross-validation with sklearn metrics: #46
It seems I understand your confusion now, let me explain.
keras-metrics
are implemented as regular layers of the model, so they are part of the model's execution graph. So whenever you call fit
of the model, all components of that graph are executed, including metrics.
Assuming previous statement: result of keras-metrics
make sense to compare with sklearn result on evaluation
of the model only, that's it.
Don't get confused with values printed during the model fitting, it's just part of the model's graph execution.
Hi all,
Wondering if you might be able to shed some light on what's going on here. Is this a bug? Thanks.
I'm using: tensorflow gpu 1.13.1 keras 2.2.4 (very latest pip installed form github repo) keras-metrics 1.1.0 numpy 1.16.4 scikit-learn 0.21.2
Here's the situation...
I'm training a ResNet on a multiclass problem (seven classes total). I'm trying to track the precision, recall and F1 for each class at each epoch. If I compare the validation set output from the last epoch with the values in that scikit learn calculates in its classification report after calling predict, they are vastly different.
For example, after 3 epochs the precision, recall and F1 of each class in the validation set is:
val_precision: 0.5000 val_precision_1: 0.3333 val_precision_2: 0.6000 val_precision_3: 0.3333 val_precision_4: 0.5641 val_precision_5: 0.8972 val_precision_6: 0.3500
val_recall: 0.0312 val_recall_1: 0.0196 val_recall_2: 0.0275 val_recall_3: 0.0909 val_recall_4: 0.1982 val_recall_5: 0.8075 val_recall_6: 0.5000
val_f1_score: 0.0588 val_f1_score_1: 0.0370 val_f1_score_2: 0.0526 val_f1_score_3: 0.1429 val_f1_score_4: 0.2933 val_f1_score_5: 0.8500 val_f1_score_6: 0.4118
But the scikit-learns confusion matrix and classification report shows:
Confusion matrix [[ 0 0 28 0 4 0 0] [ 0 0 44 0 7 0 0] [ 0 0 102 0 7 0 0] [ 0 0 11 0 0 0 0] [ 0 0 99 0 12 0 0] [ 0 0 657 0 13 0 0] [ 0 0 14 0 0 0 0]]
Classification Report precision recall f1-score support
weighted avg 0.04 0.11 0.04 998
Here's my code: