Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-234

Horizon Linear Weights

Problem

Build normalized linearly decaying horizon weights. The raw weight for horizon h is horizon - h + 1 for h = 1, ..., horizon, divided by the total so the weights sum to 1.

The nearest horizon receives the largest weight. Return an empty list for horizon <= 0.

Hint

Near horizons are usually easier to forecast, so they get more training weight.

Test cases

case 1
in: [3]
expected: [0.5,0.3333333333333333,0.16666666666666666]
case 2
in: [1]
expected: [1]
case 3
in: [4]
expected: [0.4,0.3,0.2,0.1]
case 4
in: [0]
expected: []
Starter codePython
def horizon_linear_weights(horizon):
    # Your code here
    pass

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