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. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js.
The tf.metrics.categoricalCrossentropy() function categorically finds the categorical crossentropy between a target and an output tensor.
Syntax:
tf.metrics.categoricalCrossentropy(yTrue, yPred)
Parameters: This function accepts the following two parameters:
- yTrue: It is the truth tensor, and it is of type tf.Tensor.
- yPred: It is the prediction tensor, and it is of type tf.Tensor.
Return Value: It returns the tf.Tensor object.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
let geek1 = tf.tensor2d([[2, 4], [1, 3]]);
let geek2 = tf.tensor2d([11, 22, 33, 44], [2, 2]);
let result = tf.metrics.categoricalCrossentropy(geek1, geek2);
result.print();
|
Output:
Tensor
[3.8190854, 2.526145]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
tf.metrics.categoricalCrossentropy(
tf.tensor1d([1, 2]),
tf.tensor2d([50], [1, 1]))
.print();
|
Output:
Tensor
[4e-7]
Reference: https://js.tensorflow.org/api/3.6.0/#metrics.categoricalCrossentropy
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Last Updated :
26 May, 2021
Like Article
Save Article