首页 > 解决方案 > 在时间序列数据集上应用 GAM

问题描述

我正在尝试在时间序列数据上创建一个 gam 模型。在mydata中,我只有两列:Var1date(从 2013 年 1 月到 2018 年 12 月)。这是我正在使用的代码:

training.samples <- mydata$Var1 %>% createDataPartition(p = 0.8, list = FALSE)
    train.data  <- mydata[training.samples, ]
    test.data <- mydata[-training.samples, ]

    library(mgcv)
    # Build the model
    model <- gam(Var1 ~ s(date, bs="cr"), data = train.data, fit= TRUE)



Error in names(dat) <- object$term : 
  'names' attribute [1] must be the same length as the vector [0]

我的问题是:这段代码有问题还是在 gam 函数中使用日期变量有什么根本区别?任何帮助将不胜感激。

标签: rtime-series

解决方案


推荐阅读