All problems
Residual Standard Error
Problem
Fit simple linear regression y = a + b*x by least squares and return the residual standard error sqrt(SSE/(n-2)). Return 0.0 when n < 3, the lengths differ, or x has zero variance.
Hint
Compute the slope from Sxy/Sxx, then the sum of squared residuals.
Test cases
case 1
in: [[1,2,3],[2,4,6]]
expected: 0
case 2
in: [[1,2,3,4],[2,3,4,7]]
expected: 0.7745966692414836
case 3
in: [[1,2,3],[1,2,2]]
expected: 0.408248290463863
case 4
in: [[1,2],[3,5]]
expected: 0
case 5
in: [[5,5,5],[1,2,3]]
expected: 0
Starter codePython
def residual_standard_error(x, y):
# Your code here
pass5 test cases · run your code against them in the editor