Saturday, December 13, 2025
HomeLanguagesJavascriptTensorflow.js tf.metrics.recall() Function

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:

  • 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7200 POSTS0 COMMENTS
Thapelo Manthata
6897 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS