Skip to content
DeepForgeby svx
All problems
HardTime Seriests-090

Seasonal Strength Measure

Problem

Measure seasonal strength from a centered-moving-average decomposition. Detrend the series with a centered moving average of length period, average the detrended values per season position and center them, then form residuals. Return max(0, 1 - Var(residual) / Var(detrended)), using population variances.

Return 0.0 if period is not positive, the series is shorter than 2*period, or the detrended variance is zero.

Hint

A strength near 1 means the seasonal component explains almost all of the variation.

Test cases

case 1
in: [[1,5,1,5,1,5,1,5],2]
expected: 1
case 2
in: [[1,2,1,2,1,2],2]
expected: 1
case 3
in: [[1,2,3,4,5,6],2]
expected: 0
case 4
in: [[10,10,10,10,10,10],3]
expected: 0
case 5
in: [[2,4,6,8],2]
expected: 0
Starter codePython
def seasonal_strength(series, period):
    # Your code here
    pass

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