All problems
Forecast Error Autocorrelation
Problem
Compute the lag-one autocorrelation of a list of forecast errors, using the biased estimator with division by the number of errors. The numerator sums (e[t] - mean) * (e[t+1] - mean) over consecutive pairs and the denominator is the total centered sum of squares.
Return 0.0 when there are fewer than three errors or when all errors are identical.
Hint
Autocorrelated residuals signal that a model has left structure on the table.
Test cases
case 1
in: [[1,-1,1,-1]]
expected: -0.75
case 2
in: [[2,4,6,8]]
expected: 0.25
case 3
in: [[1,2,3]]
expected: 0
case 4
in: [[1,2]]
expected: 0
case 5
in: [[3,3,3,3]]
expected: 0
Starter codePython
def forecast_error_autocorrelation(errors):
# Your code here
pass5 test cases · run your code against them in the editor