All problems
Adjusted R-Squared from Predictions
Problem
Compute the adjusted R^2: 1 - (1 - R^2) * (n - 1) / (n - p - 1), where p = n_features is the number of predictors and R^2 = 1 - SS_res/SS_tot (using 1.0 when SS_tot is 0 and SS_res is also 0, else 0.0).
If n - p - 1 <= 0 or the input is empty, return 0.0.
Hint
Penalize R^2 by the ratio of residual degrees of freedom to total degrees of freedom.
Test cases
case 1
in: [[1,2,3],[1,2,3],1]
expected: 1
case 2
in: [[1,2,3],[2,2,2],1]
expected: -1
case 3
in: [[1,2,3],[2,2,2],0]
expected: 0
case 4
in: [[1,2,3,4],[1,2,3,5],1]
expected: 0.7000000000000001
Starter codePython
def adjusted_r2(y_true, y_pred, n_features):
# Your code here
pass4 test cases · run your code against them in the editor