如何将X轴上的样本转换为褶皱?

2024-04-19 23:26:25 发布

您现在位置:Python中文网/ 问答频道 /正文

对于一个项目,我对一个时间序列做了10倍的交叉验证。为了使我的结果可视化,我创建了这样一个图:

How the plot looks right now

为了更好地理解我的情节,我宁愿有褶皱(1-10)在我的x轴,而不是样品。你知道吗

由于我使用时间序列数据,我的10倍交叉验证有以下结构:

  • 第0列-测试1
  • 第1列-测试2
  • 第1、2列-测试3
  • 列车1、2、3-4日
  • 。。。你知道吗
  • 第1、2、3、4、5、6、7、8、9列-试验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个折叠。你知道吗


Tags: testindexnp时间train序列交叉pl