Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.metrics.recall() function is used to compute the recall of the predictions with respect to the labels. ‘Recall’ is one of the metrics in machine learning. You can read more about it here.
Syntax:
tf.metrics.recall (yTrue, yPred)
Parameters:
- yTrue (tensor): It contains the truth values either 0 or 1.
- yPred (tensor): It contains the predicted values only 0 or 1.
Return Value: It returns a tensor (tf.tensor).
Example 1:
Javascript
const tf = require( "@tensorflow/tfjs" ) // Creating 2-D tensor of true values const yTrue = tf.tensor2d([ [0, 0, 1, 1], [0, 1, 0, 0], [0, 0, 0, 1] ]); // Creating 2-D tensor of predicted values const yPred = tf.tensor2d([ [1, 0, 0, 1], [0, 1, 0, 0], [1, 0, 1, 1] ]); // Getting the result from the recall function const recallResult = tf.metrics.recall(yTrue, yPred); recallResult.print(); |
Output:
Tensor 0.75
Example 2:
Javascript
const tf = require( "@tensorflow/tfjs" ) // Creating 2-D tensor of true values const trueValues = tf.tensor2d([ [0, 0, 0], [1, 0, 0], [0, 1, 0] ]); // Creating 2-D tensor of predicted values const predValues = tf.tensor2d([ [0, 1, 0], [0, 0, 1], [0, 1, 1] ]); // Getting the result from the recall function const recallResult = tf.metrics.recall(trueValues, predValues); recallResult.print(); |
Output:
Tensor 0.5
Reference: https://js.tensorflow.org/api/latest/#metrics.recall