Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-172

Expanding Window Mean Forecast

Problem

Compute expanding-window mean forecasts: for each time step t from initial to n-1, forecast the mean of values[0:t].

Return [] if initial < 1 or initial >= n.

Hint

Each forecast uses only the data available before the predicted time step.

Test cases

case 1
in: [[1,2,3,4,5],3]
expected: [2,2.5]
case 2
in: [[10,20],1]
expected: [10]
case 3
in: [[1,2],2]
expected: []
case 4
in: [[1,2],0]
expected: []
Starter codePython
def expanding_window_mean_forecast(values, initial):
    # Your code here
    pass

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