对于一个项目,我对一个时间序列做了10倍的交叉验证。为了使我的结果可视化,我创建了这样一个图:
为了更好地理解我的情节,我宁愿有褶皱(1-10)在我的x轴,而不是样品。你知道吗
由于我使用时间序列数据,我的10倍交叉验证有以下结构:
我的眼睛应该是这样的:
情节应该是什么样的]2
这可能吗?如果可能,怎么可能?你知道吗
这是我的代码:
tscv = TimeSeriesSplit(n_splits=10)
print(tscv)
X = mergedf['AnzahlTweets']
y = mergedf['Kurs']
X=X.values.reshape(-1,1)
y=y.values.reshape(-1,1)
linreg=LinearRegression()
rmse=[]
prediction=np.zeros(y.shape)
for train_index, test_index in tscv.split(X):
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
linreg.fit(X_train,y_train)
y_pred=linreg.predict(X_test)
prediction[test_index]=y_pred
rmse.append(np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
print('RMSE: %.10f' % np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
pl.plot(y,label='Actual')
pl.plot(prediction, color='red',label='Predicted',)
pl.ylabel('Price')
pl.xlabel('Sample')
pl.legend()
pl.show()
提前谢谢!你知道吗
谢谢你提到一个现存的问题。这有助于解决我的一部分问题。另一部分是是否有可能将x轴上的“samples”改为“folds”,这样我的图就被分成10个折叠。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐