Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-356

Deseasonalize by Period Means

Problem

Remove an additive seasonal pattern by subtracting from every observation the mean of the seasonal position it belongs to. Observation t belongs to position t mod m.

Return an empty list when m is not positive or m exceeds the series length.

Hint

Subtracting a constant per season leaves the trend and the irregular part intact.

Test cases

case 1
in: [[1,3,2,4],2]
expected: [-0.5,-0.5,0.5,0.5]
case 2
in: [[5,7,9],1]
expected: [-2,0,2]
case 3
in: [[3,3,3,3],2]
expected: [0,0,0,0]
case 4
in: [[1,2],5]
expected: []
Starter codePython
def deseasonalize_by_period_means(series, m):
    # Your code here
    pass

4 test cases · run your code against them in the editor