我有直到3650个时间步的数据,但我希望预测未来的数据,即3650个时间步之后的数据。我是机器学习的新手,显然搞不明白该怎么做。我该怎么做呢?作为参考,Colab笔记本
回答:
如何将表格(或横截面)回归算法调整用于预测问题的总体方法在这里描述。简而言之:你可以使用滞后观察的窗口来训练模型。为了生成预测,你有不同的选择,其中递归策略是最常用的,在这种策略中,你使用最后可用的窗口来预测第一个值,然后用第一个预测值更新最后一个窗口来预测下一个值,依此类推。
如果你有兴趣,我们正在开发一个工具箱,专门扩展scikit-learn以满足这些用例。因此,使用sktime,你可以简单地编写以下代码:
import numpy as npfrom sktime.datasets import load_airlinefrom sktime.forecasting.compose import RecursiveTabularRegressionForecasterfrom sklearn.ensemble import RandomForestRegressorfrom sktime.forecasting.model_selection import temporal_train_test_splitfrom sktime.performance_metrics.forecasting import mean_absolute_percentage_errory = load_airline() # 加载一维时间序列y_train, y_test = temporal_train_test_split(y) fh = np.arange(1, len(y_test) + 1) # 预测范围regressor = RandomForestRegressor(random_state=3) forecaster = RecursiveTabularRegressionForecaster(regressor, window_length=10)forecaster.fit(y_train)y_pred = forecaster.predict(fh)print(mean_absolute_percentage_error(y_test, y_pred, symmetric=True))>>> 0.1440354514063762