DataLane

33. Huber loss

hardProNot started~14 minPythonImplement huber_loss()

Asked in screens shaped like: NVIDIA, Jane Street

← Prev33 / 33Next →

Mean Huber loss of labels y and predictions yhat with delta = 1. For each residual r = yhat - y: 0.5 r^2 if |r| <= 1, else |r| - 0.5. Round to 4 decimals.

Examples

  • Example 1

    Input: { "y": [0, 0, 0], "yhat": [0.5, 2, 0] }
    Output: 0.5417

Constraints

  • 1 <= n <= 10**5, where n is the length of the input
  • Input is non-empty

Python editor

Loading Python engine…

Ctrl/Cmd + Enter submits

Run your code to see stdout.

Pro problem

Hard problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close