Beat the Lazy Guess

Machine Learning in CodeMedium+10 XP+10

Beat the Lazy Guess

Before trusting any model, compare it with the laziest one possible: always predict the average of the training answers, whatever the row.

Write lazy_baseline(train_answers, test_answers).

  • Work out the mean of train_answers.
  • Predict that same number for every value in test_answers.
  • Score those predictions against test_answers.

Return a dict with:

  • "rmse": the root mean squared error, rounded to 2 decimal places.
  • "r2": the R² score, rounded to 3 decimal places.

Use plain Python floats. test_answers always holds at least two different values.

Examples

train_answers = [10, 20, 30]
test_answers = [15, 25]
returns {'rmse': 5.0, 'r2': 0.0}
train_answers = [12, 14, 16, 18]
test_answers = [10.0, 12.0, 14.0, 16.0]
returns {'rmse': 3.0, 'r2': -0.8}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run