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
let truth = tf.tensor1d([6, 4]);
let prediction = tf.tensor1d([-3, -4]);
const mse = tf.metrics.meanSquaredError(truth, prediction);
mse.print();
|
Output:
Tensor
72.5
Example 2:
Javascript
let mse = tf.metrics.meanSquaredError(
tf.tensor1d([0, 1, 2, 3]),
tf.tensor1d([-8,-9, -10, -11])
);
mse.print();
|
Output:
Tensor
126
Reference: https://js.tensorflow.org/api/latest/#metrics.meanSquaredError
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 :
22 Jul, 2021
Like Article
Save Article