Open In App

Tensorflow.js tf.metrics.recall() Function

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:



Return Value: It returns a tensor (tf.tensor).

Example 1:




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:




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


Article Tags :