DataLane

21. R-squared

hardProNot started~12 minPythonImplement r2_score()

Asked in screens shaped like: Databricks, Google

Return 1 - SS_res / SS_tot for y_true vs y_pred, rounded to 4 decimals. SS_tot uses the mean of y_true.

Examples

  • Example 1

    Input: { "y_true": [1, 2, 3], "y_pred": [1, 2, 5] }
    Output: -1

Constraints

  • Arrays are the same length and y_true is not constant

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