简体   繁体   English

在 R 中拆分小时时间序列

[英]Splitting hourly time series in R

I'm trying to split a time series dataset into train and test set with R.我正在尝试使用 R 将时间序列数据集拆分为训练集和测试集。

The dataset structure is the following:数据集结构如下:

Date (format = %Y-%m-%d)     | Hour (24 H format) |       Value

         2018-09-23                    15                 12345

I have transformed this dataset in a times series format using this code:我已使用以下代码将此数据集转换为时间序列格式:


tt <- ts(df$Value,start=c(2018,09,00:00),frequency=24*365)

After this I tried to split the series in a training and test set using this code:在此之后,我尝试使用以下代码将系列拆分为训练和测试集中:

y_train <- window(tt, c(2018,09), c(2020,05)

y_test <- window(tt, c(2020,06))

But the test set contains only two observation (instead of 1488 values).但是测试集只包含两个观察值(而不是 1488 个值)。

How can I solve this problem?我怎么解决这个问题?

Example, for nrow(df) = 200例如,对于 nrow(df) = 200

tt <- ts(df$Value, frequency = 24, start = 1)        

y_train <- ts(tt[1:140], frequency=24) #70%
y_test <- ts(tt[141:200], frequency=24) #30%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM