您的位置:首页 > 其它

愉快的学习就从翻译开始吧_Multi-step Time Series Forecasting_5_Persistence Model_Make Forecasts

2018-06-18 12:53 330 查看

Make Forecasts/进行预测

The next step is to make persistence forecasts.下一步是进行持续预测We can implement the persistence forecast easily in a function named persistence() that takes the last observation and the number of forecast steps to persist. This function returns an array containing the forecast.我们可以用一个叫persistence()的函数来容易的实现持续预测,他接受最后一个观测值和预测步数来持续(预测)。

123# make a persistence forecastdef persistence(last_ob, n_seq): return [last_ob for i in range(n_seq)]

We can then call this function for each time step in the test dataset from December in year 2 to September in year 3.我们可以为从第二年12月到第三年9月的测试数据集中的每一个时间步调用这个函数Below is a function make_forecasts() that does this and takes the train, test, and configuration for the dataset as arguments and returns a list of forecasts.下面是一个函数 make_forecasts(),它来执行此操作,并且它接受train,test,和 configuration for the dataset 作为参数,并且返回一个预测列表

12345678910# evaluate the persistence modeldef make_forecasts(train, test, n_lag, n_seq): forecasts = list() for i in range(len(test)): X, y = test[i, 0:n_lag], test[i, n_lag:] # make forecast forecast = persistence(X[-1], n_seq) # store the forecast forecasts.append(forecast) return forecasts

We can call this function as follows:我们可以像下面这样调用这个函数:

1forecasts = make_forecasts(train, test, 1, 3)
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐