Tensorflow.js tf.metrics.meanSquaredError() 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 Tensorflow tf.metrics.meanSquaredError() function is a Loss or metric function used to Computes the mean squared error between y_true and y_pred. the y_true is a truth tensor and y_pred is the Prediction Tensor.
Syntax:
tf.metrics.meanSquaredError(tensor1, tensor2);
Parameters: This function accepts two parameters which are illustrated below:
- tensor1: It is the truth tensor (y_true).
- tensor2: It is the prediction tensor (y_pred).
Return Value: It returns the mean square error tensor between truth tensor and prediction tensor.
Example 1:
Javascript
// Importing the tensorflow.Js library // import * as tf from "@tensorflow/tfjs" // Creating the tensor let truth = tf.tensor1d([6, 4]); let prediction = tf.tensor1d([-3, -4]); // Calculating mean squared Error // between truth and prediction tensor const mse = tf.metrics.meanSquaredError(truth, prediction); // Printing mean square error mse.print(); |
Output:
Tensor 72.5
Example 2:
Javascript
// Importing the tensorflow.Js library // import * as tf from "@tensorflow/tfjs" // Calculating mean squared Error between // truth and prediction tensor let mse = tf.metrics.meanSquaredError( tf.tensor1d([0, 1, 2, 3]), tf.tensor1d([-8,-9, -10, -11]) ); // Printing mean square error mse.print(); |
Output:
Tensor 126
Reference: https://js.tensorflow.org/api/latest/#metrics.meanSquaredError
Please Login to comment...