All problems
Trend Removal
Problem
Remove a known linear trend from a series: x[t] - (intercept + slope * t) for t = 0, ..., n-1.
Return the detrended series. Neural forecasters often model the detrended residual and add the trend back.
Hint
Subtracting the fitted line makes the series stationary in the mean.
Test cases
case 1
in: [[1,2,3],1,0]
expected: [1,1,1]
case 2
in: [[10,20,30],10,10]
expected: [0,0,0]
case 3
in: [[5,5],0,5]
expected: [0,0]
case 4
in: [[],1,1]
expected: []
Starter codePython
def trend_removal(series, slope, intercept):
# Your code here
pass4 test cases · run your code against them in the editor