Mean Squared Error (MSE)
Mean Squared Error (MSE)
Compute the Mean Squared Error between predictions and targets.
Mathematical Definition
Mean Squared Error:
MSE=N1i=0∑N−1(ypred[i]−ytrue[i])2where N is the number of samples.
Function Arguments
y_pred: array-like, shape (N,)- predicted valuesy_true: array-like, shape (N,)- target values
Examples
Input: y_pred = [2, 3], y_true = [1, 1]
Output: MSE = 2.5
Input: y_pred = [0, 0, 0], y_true = [0, 0, 0]
Output: MSE = 0.0
Hint 1
Compute element-wise squared differences, then take the mean.
Hint 2
Use np.mean() on the squared differences.
Requirements
- Convert inputs to NumPy arrays
- Ensure shapes match (return
Noneif mismatch) - Return a single float
- NumPy only, no sklearn
Constraints
- 1 ≤ N ≤ 10,000
- NumPy only
- Time limit: 200ms
Try Similar Problems
Log in to take notes on this problem
Accepts: array
Accepts: array
Mean Squared Error (MSE)
Mean Squared Error (MSE)
Compute the Mean Squared Error between predictions and targets.
Mathematical Definition
Mean Squared Error:
MSE=N1i=0∑N−1(ypred[i]−ytrue[i])2where N is the number of samples.
Function Arguments
y_pred: array-like, shape (N,)- predicted valuesy_true: array-like, shape (N,)- target values
Examples
Input: y_pred = [2, 3], y_true = [1, 1]
Output: MSE = 2.5
Input: y_pred = [0, 0, 0], y_true = [0, 0, 0]
Output: MSE = 0.0
Hint 1
Compute element-wise squared differences, then take the mean.
Hint 2
Use np.mean() on the squared differences.
Requirements
- Convert inputs to NumPy arrays
- Ensure shapes match (return
Noneif mismatch) - Return a single float
- NumPy only, no sklearn
Constraints
- 1 ≤ N ≤ 10,000
- NumPy only
- Time limit: 200ms
Try Similar Problems
Log in to take notes on this problem
Accepts: array
Accepts: array