#180Loss — pick the better modelEasy

Loss — pick the better model

Background

A loss is the ruler that scores how wrong a model is: lower is better. So comparing two models on the same labels is just comparing their losses. Here we use mean squared error,

LMSE=1ni=1n(yiy^i)2.L_{\text{MSE}} = \frac{1}{n}\sum_{i=1}^{n}(y_i - \hat{y}_i)^2.

Problem statement

Implement better_model(y, preds_a, preds_b) returning which model's predictions have the lower MSE against y.

Input

  • y — array-like of true targets.
  • preds_a — array-like, model A's predictions (same length as y).
  • preds_b — array-like, model B's predictions.

Output

Returns an int: 0 if model A has the lower (or equal) MSE, 1 if model B is strictly lower.

Examples

Example 1

Input:  y = [1, 0, 1], preds_a = [0.9, 0.1, 0.8], preds_b = [0.2, 0.9, 0.1]
Output: 0

Explanation: A's MSE 0.02\approx 0.02 vs B's 0.75\approx 0.75 — A is far better.

Example 2 — B wins

Input:  y = [0, 0], preds_a = [1, 1], preds_b = [0.1, 0.1]
Output: 1

Explanation: B is much closer to the zeros.

Constraints

  • Compute each model's MSE and compare.
  • On a tie, return 0 (prefer A).
  • Return a Python int (0/1).

Notes

  • "Training = lower loss" is the whole game; this is the comparison the optimiser makes implicitly at every step.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Example — model A clearly better
  • Reference model B clearly better
  • Sample tie prefers A