TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Mean Squared Error (MSE)

Loss Functions
Easy

Compute the mean squared error between predicted and target values:

MSE⁡=1N∑i=1N(y^i−yi)2\operatorname{MSE}=\frac{1}{N}\sum_{i=1}^{N}(\hat{y}_i-y_i)^2MSE=N1​i=1∑N​(y^​i​−yi​)2

Here, NNN is the number of values, y^i\hat{y}_iy^​i​ is prediction iii, and yiy_iyi​ is its target. Return the result as a Python float.

Loading visualization...

Examples

Input: y_pred = [1.1, 2.1, 2.9, 4.2, 4.8], y_true = [1, 2, 3, 4, 5]

Output: 0.022

Explanation: The five squared errors sum to 0.11, which gives a mean of 0.022.

Input: y_pred = [1, 2, 3, 4], y_true = [1, 2, 3, 4]

Output: 0

Input: y_pred = [10.5, 19.5, 30.2], y_true = [10, 20, 30]

Output: 0.18

Hint 1

Convert both inputs with np.asarray(..., dtype=float).

Hint 2

Use np.mean((predictions - targets) ** 2) for the reduction.

Requirements

  • Compute the elementwise prediction errors
  • Square every error before averaging
  • Return a Python float

Constraints

  • y_pred and y_true are nonempty lists of equal length
  • Values may be integers or floating-point numbers
  • Use NumPy only
Try Similar Problems
Huber LossCross Entropy LossR2 ScoreHinge LossLogistic Regression Training

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Mean Squared Error (MSE)

Loss Functions
Easy

Compute the mean squared error between predicted and target values:

MSE⁡=1N∑i=1N(y^i−yi)2\operatorname{MSE}=\frac{1}{N}\sum_{i=1}^{N}(\hat{y}_i-y_i)^2MSE=N1​i=1∑N​(y^​i​−yi​)2

Here, NNN is the number of values, y^i\hat{y}_iy^​i​ is prediction iii, and yiy_iyi​ is its target. Return the result as a Python float.

Loading visualization...

Examples

Input: y_pred = [1.1, 2.1, 2.9, 4.2, 4.8], y_true = [1, 2, 3, 4, 5]

Output: 0.022

Explanation: The five squared errors sum to 0.11, which gives a mean of 0.022.

Input: y_pred = [1, 2, 3, 4], y_true = [1, 2, 3, 4]

Output: 0

Input: y_pred = [10.5, 19.5, 30.2], y_true = [10, 20, 30]

Output: 0.18

Hint 1

Convert both inputs with np.asarray(..., dtype=float).

Hint 2

Use np.mean((predictions - targets) ** 2) for the reduction.

Requirements

  • Compute the elementwise prediction errors
  • Square every error before averaging
  • Return a Python float

Constraints

  • y_pred and y_true are nonempty lists of equal length
  • Values may be integers or floating-point numbers
  • Use NumPy only
Try Similar Problems
Huber LossCross Entropy LossR2 ScoreHinge LossLogistic Regression Training

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.