Finding Precision And Recall For Mnist Dataset Using Tensorflow
I'm using this tutorial to learn how to train a model on the MNIST dataset here: https://www.tensorflow.org/tutorials/quickstart/beginner Currently, the model only trains on the ac
Solution 1:
suppose you predicted using code:
predicted_result=model.predict(x_test)
the output layer has prob for digit 0 to 9, i.e 10. so from the predicted result need to identify the class.
import numpy as npclass_preds= np.argmax(predicted_result, axis=-1)
now, y_test and class_preds are in classes, so can run precision_score.
from sklearn.metrics import precision_score
precision_score(y_test, class_preds,average='macro')
or
from sklearn.metrics import recall_score
recall_score(y_test, class_preds,average='macro')
even can feed this custom function to metrics:
from sklearn.metrics import precision_score
def custom_prec_score(y_true, y_pred):
y_true=y_true.numpy()
y_pred=y_pred.numpy()
y_pred=np.argmax(y_pred, axis=-1)
return precision_score(y_true, y_pred,average='macro')
model.compile(optimizer='adam',
loss=loss_fn,run_eagerly=True,
metrics=["accuracy",custom_prec_score])
model.fit(x_train, y_train, epochs=5)
Post a Comment for "Finding Precision And Recall For Mnist Dataset Using Tensorflow"