All problems
Additive Seasonal Component
Problem
Estimate an additive seasonal component by averaging deviations from the overall mean per season position. For each position j = 0, ..., period-1 compute the mean of series[j::period] minus the overall mean, then center the component so its entries sum to zero.
Return an empty list if period is not positive or exceeds the series length.
Hint
After centering, the seasonal deviations add up to exactly zero.
Test cases
case 1
in: [[2,4,6,2,4,6],3]
expected: [-2,0,2]
case 2
in: [[1,3,5,2,4,6],3]
expected: [-2,0,2]
case 3
in: [[10,20,30,40],2]
expected: [-5,5]
case 4
in: [[1,2,3],5]
expected: []
Starter codePython
def additive_seasonal_component(series, period):
# Your code here
pass4 test cases · run your code against them in the editor