如何对面板数据使用插入符号/时间片?

我有关于股票回报和相应特征的面板数据。我想使用时间片进行交叉验证。

不幸的是,代码似乎只适用于真实的时间序列。

timeSlices <- createTimeSlices(1:length(unique(data$ID)),initialWindow = 48,horizon = 12,fixedwindow = T,skip = 11)

我的数据格式为:ID 1,2000-2020 年;身份证2; 2000-2020 年。

我想获得:

train_1: data from 2007 to 2010 // test_1 data from 2011
train_2: data from 2007 to 2011 // test_2 data from 2012

如何告诉 caret 使用面板数据格式?有办法吗?这里不能用timeslice吗?

kchuan 回答:如何对面板数据使用插入符号/时间片?

如果因变量(股票收益)的排序并不重要,那么您应该使用 createDataPartition 进行常规数据拆分,解释如下:https://topepo.github.io/caret/data-splitting.html

但是,请注意,股票收益确实与时间相关,并且在尝试预测收益时应该尽量避免交叉验证。您很可能希望保持数据的时间顺序。因此,(在资产定价文献中)经常使用的是滚动验证。 createTimeSlices 为您做这件事。然而,据我所知,这应该只适用于平衡的时间序列数据,而不适用于不平衡的面板数据。

本文链接:https://www.f2er.com/98222.html

大家都在问