Challenge - 5 Problems
Regression Evaluation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this MSE calculation code?
Given the true values and predicted values below, what is the Mean Squared Error (MSE) computed by the code?
ML Python
import numpy as np true = np.array([3, -0.5, 2, 7]) pred = np.array([2.5, 0.0, 2, 8]) mse = np.mean((true - pred) ** 2) print(round(mse, 2))
Attempts:
2 left
💡 Hint
Calculate the squared differences, then average them.
✗ Incorrect
MSE is the average of squared differences between true and predicted values. Here, squared errors are [0.25, 0.25, 0, 1], average is 0.375 rounded to 0.38.
❓ Predict Output
intermediateWhat is the RMSE value printed by this code?
Calculate the Root Mean Squared Error (RMSE) from the true and predicted values below.
ML Python
import numpy as np true = np.array([1, 2, 3, 4]) pred = np.array([1.1, 1.9, 3.2, 3.8]) rmse = np.sqrt(np.mean((true - pred) ** 2)) print(round(rmse, 3))
Attempts:
2 left
💡 Hint
RMSE is the square root of MSE.
✗ Incorrect
Squared errors: [0.01, 0.01, 0.04, 0.04], mean = 0.025, sqrt(0.025) = 0.158.
❓ Model Choice
advancedWhich model has the highest R² score based on these predictions?
Given true values and predictions from two models, which model has the higher R² score?
ML Python
import numpy as np from sklearn.metrics import r2_score true = np.array([10, 20, 30, 40, 50]) pred_model1 = np.array([12, 18, 29, 41, 49]) pred_model2 = np.array([9, 21, 31, 39, 52]) r2_1 = r2_score(true, pred_model1) r2_2 = r2_score(true, pred_model2) print(round(r2_1, 3), round(r2_2, 3))
Attempts:
2 left
💡 Hint
Check which prediction set fits true values better overall.
✗ Incorrect
Model 2 predictions are closer overall to true values, resulting in a higher R² score.
❓ Metrics
advancedWhat is the R² score for a model that always predicts the mean?
If a regression model always predicts the mean of the true values, what is its R² score?
Attempts:
2 left
💡 Hint
R² compares model error to variance of true values.
✗ Incorrect
Predicting the mean results in residual sum of squares equal to total sum of squares, so R² = 0.
🔧 Debug
expertWhy does this R² calculation code raise an error?
Identify the error in this R² score calculation code and what error it raises.
ML Python
import numpy as np true = np.array([1, 2, 3]) pred = np.array([1, 2]) r2 = 1 - np.sum((true - pred) ** 2) / np.sum((true - np.mean(true)) ** 2) print(r2)
Attempts:
2 left
💡 Hint
Check if true and pred arrays have the same length.
✗ Incorrect
true and pred arrays have different lengths, so (true - pred) causes ValueError for shape mismatch.
