Tensorflow.js tf.metrics.meanAbsoluteError() Function
Last Updated :
25 May, 2021
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.metrics.meanAbsoluteError() is used to calculate mean absolute error. The mean absolute error is defined as the mean of absolute difference of two tensors. Where, the mean is applied over feature dimensions. It takes two tensors as a parameter.
mean(abs(Prediction - True))
Syntax:
tf.metrics.meanAbsoluteError(Tensor1, Tensor2);
Parameters:
- Tensor1: It is the truth tensor.
- Tensor2: It is the Prediction tensor.
Return Value: It returns the tensor of the mean absolute errors.
Example 1: In this example, we are giving two 1d tensors as a parameter, and the metrics.meanAbsoluteError function will calculate the mean absolute error and return a tensor.
Javascript
import * as tf from "@tensorflow/tfjs"
const True = tf.tensor([1,2,3]);
const Prediction = tf.tensor([3,2,1]);
const error = tf.metrics.meanAbsoluteError(True, Prediction);
error.print();
|
Output:
Tensor
1.3333333730697632
Example 2: In this example, we are giving two 2d tensors as a parameter, and the metrics.meanAbsoluteError function will calculate the mean absolute error and return a tensor.
Javascript
import * as tf from "@tensorflow/tfjs"
const True = tf.tensor([[1,2,3],[2,4,1]]);
const Prediction = tf.tensor([[3,2,1],[5,2,1]]);
const error = tf.metrics.meanAbsoluteError(True, Prediction);
error.print();
|
Output:
Tensor
[1.3333334, 1.6666667]
Reference:https://js.tensorflow.org/api/latest/#metrics.meanAbsoluteError
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...