Friday, November 14, 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

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11916 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS