Skip to content
DeepForgeby svx
All problems
HardTime Seriests-042

Theil U Statistic

Problem

Compute Theil's U statistic comparing a forecast against the naive no-change forecast: U = sqrt(mean((forecast - actual)^2)) / sqrt(mean over t >= 1 of (actual[t] - actual[t-1])^2). Use the 1/m denominator in the numerator and 1/(m-1) in the denominator.

Return 0.0 if there are fewer than two actual values or the denominator is 0. U < 1 means the forecast beats a random walk.

Hint

The denominator is the RMSE of the naive persistence forecast.

Test cases

case 1
in: [[10,12,14],[11,11,11]]
expected: 0.9574271077563381
case 2
in: [[1,2,3,4],[1,2,3,4]]
expected: 0
case 3
in: [[5,5,5],[6,4,5]]
expected: 0
case 4
in: [[2,4,6,8],[3,5,7,8]]
expected: 0.4330127018922193
Starter codePython
def theil_u(actual, forecast):
    # Your code here
    pass

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