All problems
Seasonal Indices Simple Average
Problem
Estimate multiplicative seasonal indices by simple averaging. Compute the overall mean, then for each season position j = 0, ..., period-1 average the values whose indices are congruent to j modulo period, and divide that average by the overall mean.
Return the list of period indices. Return an empty list if period is not positive or exceeds the series length; if the overall mean is exactly 0.0 return a list of period zeros.
Hint
Python slicing with a step of period gives one season position at a time.
Test cases
case 1
in: [[2,4,6,2,4,6],3]
expected: [0.5,1,1.5]
case 2
in: [[1,3,5,2,4,6],3]
expected: [0.42857142857142855,1,1.5714285714285714]
case 3
in: [[1,2,3,4],2]
expected: [0.8,1.2]
case 4
in: [[1,2,3],5]
expected: []
Starter codePython
def seasonal_indices(series, period):
# Your code here
pass4 test cases · run your code against them in the editor