【问题标题】:Forecast Multiple seasonality Function Is not working预测多重季节性功能不起作用
【发布时间】:2023-04-10 23:39:01
【问题描述】:

my new result

我有每日销售数据,我在许多 Post 中使用 Rob Hyndman Sir 建议的 Tbat 函数。我的结果没有显示增长趋势

我正在使用以下代码

mydata<-read.csv ("D:/data.csv",header=TRUE);
y <- msts(mydata$sales, seasonal.periods=c(7,365.25))
fit <- tbats(y)
fc <- forecast(fit)
plot(fc)

【问题讨论】:

  • 请添加MWE,包括一些数据。
  • 我添加了我的数据的样子
  • 请在问题中包含dput(mydata) 及其输出...
  • 请查看 dput(data)
  • 请告诉我哪里错了

标签: r statistics data-analysis forecasting forecastr


【解决方案1】:

由于我无法使用您的数据,这里有一个示例,它使用您的方法来 a) 模拟一些具有(某种)季节性的数据,以及 b) 预测下一个时期。

A) 模拟数据

用三个分量模拟数据,一个正弦函数、一个余弦函数和一个随机分量。

# 1. simulate some data:
set.seed(123) # set seed for reproducability
n <- 1000

# simulate the random components
sin.comp <- sin((1:n)/10)*10
cos.comp <- cos((1:n)/5)*5
rand.comp <- rnorm(n)

df <- data.frame(time = seq(from = as.Date("2000-01-01"), by = "day", 
                            length.out = n),
                 value = sin.comp + cos.comp + rand.comp)

# plot the data
plot(x = df$time, y = df$value, main = "Seasonal Series", type = "l")
lines(x = df$time, y = sin.comp, col = "red")
lines(x = df$time, y = cos.comp, col = "blue")
lines(x = df$time, y = rand.comp, col = "green")
legend("bottomleft", 
       c("Series", "Sin", "Cos", "Rand"), 
       lty = c(1, 1), 
       col = c("black", "red", "blue", "green"), cex = 0.7)

B) 预测系列

y <- msts(df$value, seasonal.periods = c(7, 36)) # cut down to 36
fit <- tbats(y) #takes some time to calculate..
fc <- forecast(fit)

plot(fc)

附加说明

如果这种方法对您不起作用,则意味着您的数据可能以某种方式不适合预测...

要检查您的数据,您可以使用str(mydata)(在我的情况下为str(df))、summary(mydata)head/tail(mydata) 来检查类型。

最后一点,您的dput 显然有点太长了...要么发布dput(head(mydata, 100)),它提供前 100 个条目,要么将 csv 上传到托管商并发布链接。

这是否为您指明了正确的方向?

【讨论】:

  • 大卫请告诉我您的电子邮件 ID,我将邮寄给您...请紧急...我的数据没有问题...分解后我可以看到数据的季节性模式跨度>
  • 你能先解释一下你的问题到底是什么吗?你说你没有看到趋势。如果您的数据没有趋势怎么办?
  • 好的,我在问题开始时附上了我的结果图表。销售额正在增长,但在预测时它下降了..这不应该发生
  • 你能把plot(fit)的图包括进来,而不是plot(fc),而是一个额外的plot(fit)
  • 是的,我在您点击预测结果图时添加了
猜你喜欢
  • 1970-01-01
  • 2020-04-05
  • 2016-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-21
  • 2016-07-26
相关资源
最近更新 更多