Tensorflow.js tf.confusionMatrix() Function Last Updated : 24 Jun, 2021 Comments Improve Suggest changes Like Article Like Report Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .confusionMatrix() function is used to calculate the confusion matrix from the stated true labels coupled with predicted labels. Syntax: tf.confusionMatrix(labels, predictions, numClasses) Parameters: labels: It is the stated target labels that are supposed to be a zero based integers in favor of the classes. It has shape [numExamples]. Where, numExamples is the measure of incorporated instances. It can be of type tf.Tensor1D, TypedArray, or an array.predictions: It is the stated predicted classes that are supposed to be a zero based integers in favor of the classes. It should have shape equivalent to the stated labels. It can be of type tf.Tensor1D, TypedArray, or an array.numClasses: It is the number of total classes of type integer. Moreover, its measure should be greater than the greatest element in the stated labels as well as predictions. It is of type number. Return Value: It returns tf.Tensor2D object. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining predictions, labels and // numClasses const lab = tf.tensor1d([3, 4, 1, 0, 1], 'int32'); const pred = tf.tensor1d([1, 3, 0, 4, 1], 'int32'); const num_Cls = 2; // Calling tf.confusionMatrix() method const output = tf.math.confusionMatrix(lab, pred, num_Cls); // Printing output output.print(); Output: Tensor [[0, 0], [1, 1]] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling tf.confusionMatrix() method const res = tf.math.confusionMatrix( tf.tensor1d([3.3, 4.5, null, 'a', 'b']), tf.tensor1d([-2, 5.3, -0.1, 4.3, 12.5]), 4 ); // Printing output res.print(); Output: Tensor [[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] Reference: https://js.tensorflow.org/api/latest/#confusionMatrix Comment More infoAdvertise with us Next Article Tensorflow.js tf.confusionMatrix() Function N nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.concat() 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.concat() function is used to concatenate the list of specified Tensors along the given axis. Syntax: tf.concat (tensors, axis)P 2 min read Tensorflow.js tf.cos() Function Tensorflow.js is an open-source library which is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .cos() function is used to find the cosine value of the stated tensor input and is done element wise. Syntax 2 min read Tensorflow.js tf.acosh() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .acosh() function is used to find the inverse hyperbolic cos of the stated tensor element input. Syntax: Â tf 2 min read Tensorflow.js tf.dot() 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.dot() function is used to compute the dot product of two given matrices or vectors, t1 and t2. Syntax:Â tf.dot(t1, t2); Paramet 1 min read Tensorflow.js tf.fill() Function Tensorflow.js is an open-source library for creating machine learning models in Javascript that allows users to run the models directly in the browser. The tf.fill() is a function defined in the class tf.Tensor. It is used to create a tensor that is filled with a scalar value. Syntax: tf.fill( shape 2 min read Like