使用SVR进行时间序列预测

我有一个时间序列数据,我想使用xt来预测xt + 1。我使用了sklearn的支持向量回归,但我不明白为什么我的预测会出现这种偏移。这里是我的代码和结果(见图片)。

bts_sup = timeseries_to_supervised(bts,1)bts_sup = bts_sup.iloc[1:,:]   # 删除该行因为x0没有前序值train, test = split_data(bts_sup)# 缩放数据scaler_in = MinMaxScaler()  # 用于输入scaler_out = MinMaxScaler()  # 用于输出X_train = scaler_in.fit_transform(train[:,0].reshape(-1,1))y_train = scaler_out.fit_transform(train[:,1].reshape(-1,1))X_test = scaler_in.transform(test[:,0].reshape(-1,1))y_test = scaler_out.transform(test[:,1].reshape(-1,1))param_grid = {"C": np.linspace(10**(-2),10**3,100),             'gamma': np.linspace(0.0001,1,20)}mod = SVR(epsilon = 0.1,kernel='rbf')model = GridSearchCV(estimator = mod, param_grid = param_grid,                                   scoring = "neg_mean_squared_error",verbose = 0)best_model = model.fit(X_train, y_train.ravel())#预测predicted_tr = model.predict(X_train)predicted_te = model.predict(X_test)# 逆变换因为预测是在缩放的输入上进行的predicted_tr = scaler_out.inverse_transform(predicted_tr.reshape(-1,1))predicted_te = scaler_out.inverse_transform(predicted_te.reshape(-1,1))#绘图forcast = np.concatenate((predicted_tr,predicted_te))real = np.concatenate((train[:,1],test[:,1]))plt.plot(real, color = 'blue', label = '实际Erlangs')plt.plot(forcast,"--", linewidth=2,color = 'red', label = '预测Erlangs')plt.title('Erlangs预测--'+data_set.columns[choice])plt.xlabel('时间')plt.ylabel('Erlangs')plt.legend()plt.show()#错误print("MSE: ", mse(real,forcast), " R2: ", r2_score(real,forcast))print(best_model.best_params_)

训练数据

[[ 9.26 11.01] [11.01 22.72] [22.72 20.75] [20.75 11.54] [11.54 11.85] [11.85 18.17] [18.17 16.05] [16.05 17.98] [17.98 14.85] [14.85 12.62] [12.62 16.95] [16.95 16.81] [16.81 16.23] [16.23 21.81] [21.81 22.47] [22.47 20.37] [20.37 16.68] [16.68 17.07] [17.07 20.48] [20.48 21.99] [21.99 25.54] [25.54 21.1 ] [21.1 16.91] [16.91 24.23] [24.23 27.37] [27.37 30.55] [30.55 28.47] [28.47 26.74] [26.74 40.37] [40.37 36.55] [36.55 39.65] [39.65 45.58] [45.58 48.91] [48.91 37.82] [37.82 39.7 ] [39.7 36.09] [36.09 25.33] [25.33 23.64] [23.64 18.33] [18.33 21.59] [21.59 22.4 ] [22.4 15.89] [15.89 18.94] [18.94 21.78] [21.78 19.38] [19.38 17.81] [17.81 21.33] [21.33 22.61] [22.61 27.11] [27.11 26.48] [26.48 19.87] [19.87 18.57] [18.57 14.03] [14.03 18.82] [18.82 22.46] [22.46 22.33] [22.33 21.58] [21.58 22.66] [22.66 19.51] [19.51 21.54] [21.54 20.58] [20.58 20.48]]

测试数据

[[20.48 25.78] [25.78 21.89] [21.89 19.61] [19.61 22.95] [22.95 21.67] [21.67 26.03] [26.03 21.96] [21.96 21.81] [21.81 21.91] [21.91 21.82] [21.82 19.6 ] [19.6 24.61] [24.61 30.97] [30.97 18.29] [18.29 19.84] [19.84 20.81] [20.81 29.17] [29.17 24.01] [24.01 21.3 ] [21.3 25.08] [25.08 27.18] [27.18 26.59] [26.59 25.99] [25.99 28.74] [28.74 25.32] [25.32 27.56] [27.56 28.69]]

结果图


回答:

根据我的观察,模型预测的值接近于之前的时间段,这些数据已作为输入数据。当x_t较低时,可以观察到小的方差,模型预测x_t+1略高,反之当x_t较高时,预测值略低。

这似乎是模型在仅有一个滞后特征的情况下做出的最佳猜测。

改进的方法可以是添加额外的特征,如5到10个滞后值,让模型学习贯穿其中的模式。

对于更复杂的模型,如果SVM不奏效,可以尝试使用RNN进行预测。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注