【问题标题】:how to predict next month sales using this data如何使用此数据预测下个月的销售额
【发布时间】:2018-10-25 08:27:49
【问题描述】:

这是csv文件数据(我在下面使用的daily sales predict.csv)

TOTAL     = c(198230142.89,129497034.78,186477295.56,118126147.20,
              140245618.01,110070803.09,70209156.29,131272373.74,144268706.02,
              21047760.22)
Monthname = c(1,2,3,4,5,6,7,8,9,10)

这是我目前尝试过的一段代码

library(forecast)
#trying to predict next month sales(november)     

shinyServer(function(input, output, session) {

  mydat<- read.csv("daily sales predict.csv")
  predictmodelling=data_frame(

    Saledate=mydat$monthname,
    total=mydat$TOTAL
  )

  tData <- ts(predictmodelling$total,
              start=c(2018,1),
              frequency=12)

  Mod1 <- auto.arima(tData)
  summary(Mod1)
  print(Mod1)
  # 2 period forecast
  plot(forecast(Mod1, h=60))

})

【问题讨论】:

    标签: r regression forecasting arima


    【解决方案1】:

    这是该问题的解决方案,您可以使用 (p, d, q) 的其他值以获得更好的准确性。

    x <- c(198230142.89,129497034.78,186477295.56,118126147.20,140245618.01,110070803.09,70209156.29,131272373.74,144268706.02,21047760.22)
    df = data.frame(x)
    
    ts_data = ts(df$x, start = c(2018,1), end = c(2018,10), frequency = 12)
    
    plot(ts_data)
    
    #this gives value for p
    
    acf(ts_data)
    
    #this gives value for q
    
    pacf(ts_data)
    # so we have p = 1, d = 1, q = 0
    
    # differentiating the series one time only so d = 1
    
    fit = arima(log(ts_data), c(1,1,0))
    
    #here I am predicting for next 2 months
    
    predicted_val = predict(fit, n.ahead = 1*2)
    
    actual_val = 2.718^predicted_val$pred
    
    print(actual_val)
    
    49577035,33805119
    

    【讨论】:

    • 感谢您的帮助,但我收到一个错误 df$x
    • @RohitJha 出现语法错误。如果您觉得有帮助,请重试并标记为已接受。谢谢!!
    • @RohitJha。它在我的编辑器中运行良好。清除当前环境中存储的所有变量和数据框后,您能否在新的编辑器中运行此代码。另外,逐行运行代码。哪一行代码产生了错误,错误是什么?
    • 我收到错误这个监听127.0.0.1:6337 警告:
    • @RohitJha 请再试一次。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多