Tensorflow.js tf.metrics.binaryCrossentropy() Function
Last Updated :
18 May, 2021
Tensorflow.js is an open-source library developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .metrics.binaryCrossentropy() function is binary crossentropy metric function which uses binary tensors and returns tf.Tensor object.
Syntax:
tf.metrics.binaryCrossentropy (yTrue, yPred)
Parameters:
- yTrue: It is the stated binary tensor input of truth, and it can be of type tf.Tensor.
- yPred: It is the stated binary tensor input of prediction, and it can be of type tf.Tensor.
Return Value: It returns the tf.Tensor object.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const y = tf.tensor2d([[4], [5], [6], [7]]);
const z = tf.tensor2d([[1], [2], [0], [1.8]]);
const binry_crsntropy =
tf.metrics.binaryCrossentropy(y, z);
binry_crsntropy.print();
|
Output:
Tensor
[-27.6301231, -36.8401985, 55.2615433, -55.2603455]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
tf.metrics.binaryCrossentropy(
tf.tensor2d([[-13], [-2.787]]),
([[-0.6], [-12]])).print();
|
Output:
Tensor
[-119.7330246, -25.6688404]
Reference: https://js.tensorflow.org/api/latest/#metrics.binaryCrossentropy
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...