TSstudio时间序列包使用

TSstudio包提供了一组时间序列数据的描述性和预测性分析工具。这包括用于预处理时间序列数据的实用功能、基于plotly包引擎的交互式可视化功能,以及用于训练和评估预测的forecast、bsts等包中的时间序列预测模型的一组工具,下面小编对该包的使用进行介绍。

  • ts_info对象属性函数
install.packages("TSstudio")
library(TSstudio)
> NGC
     Qtr1   Qtr2   Qtr3   Qtr4
2000 2050.6 1513.1 1475.0 2587.5
2001 2246.6 1444.4 1494.1 2120.2
2002 2258.4 1591.4 1542.2 2378.9
> ts_info(NGC)
 The NGC series is a ts object with 1 variable and 80 observations
 Frequency: 4 
 Start time: 2000 1 
 End time: 2019 4
ts_info给出了这个ts对象的一些基本属性,包括长度、频率和起止时间。周期/频率是规则的时间序列对象很重要的属性,周期是规则且重复的时间单元,它将序列划分成连续等长的子集。频率定义了周期中的单元个数或者单元长度。在NGC中,周期是1年,观测单元是季度,所以频率就是4
  • ts_lags可视化
ts_lags(USgas, lags = c(12,24,36,48))

在这里插入图片描述

  • ts_plot可视化函数
ts_plot(tvs_ts, title = "US Monthly total vehicle sales",
        Ytitle = "Thousands of Vehicle",slider = TRUE)

在这里插入图片描述

  • ts_cor函数
UK_ts <- ts(UKdaily$ND, 
            start = c(year(start_date), yday(start_date)),
            frequency = 365)
ts_cor(UK_ts, lag.max = 365 * 4)#分析该系列与过去四年的滞后之间的关系

在这里插入图片描述

  • ts_ma函数
two_sided_ma <- ts_ma(ts.obj = USVSales,#ts类型
                      n = c(2,5),#设定5号和11号的平均线
                      n_left = 6, n_right = 5, #设置12号平均线
                      plot = TRUE, multiple = TRUE,
                      margin = 0.04)
two_sided_ma

在这里插入图片描述

  • ts_quantile函数
ts_quantile(UKgrid, period = "monthly", n = 2)

在这里插入图片描述

  • ccf_plot可视化函数
ccf_plot(x = USVSales, y = USUnRate, lags = 0:12)

在这里插入图片描述

  • ts_split函数
#创建训练和测试集
USgas_partitions <- ts_split(USgas, sample.out = 12)
train <- USgas_partitions$train
test <- USgas_partitions$test
  • test_forecast模型预测函数
md <- auto.arima(train)
checkresiduals(md)
fc <- forecast (md, h = 12)
accuracy(fc,test)
test_forecast(actual = USgas,
              forecast.obj = fc,
              test = test)
naive_model <- naive(train, h = 12)
test_forecast(actual = USgas,
              forecast.obj = naive_model,
              test = test)
accuracy(naive_model,test)
snaive_model <- snaive(train, h = 12)
test_forecast(actual = USgas,
              forecast.obj = snaive_model,
              test = test)
accuracy(snaive_model, test)

在这里插入图片描述

  • plot_forecast模型预测可视化函数
md_final <- auto.arima(USgas)
fc_final <- forecast (md_final, h = 12)
plot_forecast(fc_final,
              title = "The US Natural Gas Consumption Forecast",
              Xtitle = "Year",Ytitle = "Billion Cubic Feet")
#Confidence interval
fc_final2 <- forecast(md_final, h = 60, level = c(80,90))
plot_forecast(fc_final2,
              title = "The US Natural Gas Consumption Forecast",
              Xtitle = "Year",Ytitle = "Billion Cubic Feet")
  • train_model模型训练
library(TSstudio)
USgas_forecast <- train_model(ts.obj = USgas,
                                 periods = 6, models = "abehntw",
                                 error = "MAPE",
                                 window_size = 12,
                                 h = 60, plot = FALSE)
  • ts_grid网格函数
deep_grid <-  ts_grid(train,
 			model = "HoltWinters",periods = 6,
                      window_space = 6,
                      window_test = 12,
                      hyper_params = list(alpha = seq(0.1,0.2,0.1),
                                          beta = seq(0,0.2,0.1),
                                          gamma = seq(0.2,0.3,0.1)),
                      parallel = TRUE, n.cores = 8)
plot_grid(deep_grid, type = "3D", top = 250)

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

winupup

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值