【问题标题】:R - fortify forecast object transformation generating wrong datesR - 加强预测对象转换生成错误日期
【发布时间】:2018-01-10 21:38:17
【问题描述】:

我正在尝试通过将预测对象转换为强化对象来绘制预测对象,正如this 堆栈溢出主题中所建议的那样。

这里是dataset 的链接,您将在下面找到生成两个对象(emea 和 df1)的代码,这两个对象的日期应该相同,其中一个对象是基于另一个对象的转换。

# Load required libraries
library(forecast)
library(lubridate)
library(tidyverse)
library(scales)
library(ggfortify)

# Load dataset
emea <- read.csv(file="C:/Users/nsoria/Downloads/AMS Globales/EMEA_Depuy_Finanzas.csv", header=TRUE, sep=';', dec=",")

# Create time series object
ts_fin <- ts(emea$Value, frequency = 26, start = c(2014,11))

# Pull out the seasonal, trend, and irregular components from the time series 
model <- stl(ts_fin, s.window = "periodic")

# Predict the next 3 bi weeks of tickets
pred <- forecast(model, h = 5)

# Round values to better accuracy
pred$mean <- round(pred$mean)

# Convert pred from list to data frame object
df1 <- fortify(pred) %>% as_tibble()

# Convert ts decimal time to Date class
df1$Date <- as.Date(date_decimal(df1$Index), "%Y-%m-%d")

# Remove Index column and rename other columns
# Select only data pts after 2017
df1 <- df1 %>% 
  select(-Index) %>% 
  filter(Date >= as.Date("2017-01-01")) %>% 
  rename("Low95" = "Lo 95",
         "Low80" = "Lo 80",
         "High95" = "Hi 95",
         "High80" = "Hi 80",
         "Forecast" = "Point Forecast")

这是first 对象 (emea) 和 second 对象 (df1) 的屏幕截图。

我的第一个假设是,当我遇到错误时,这与时区有关:

Warning message:
In as.POSIXlt.POSIXct(x, tz = tz) : unknown timezone '%Y-%m-%d'

任何帮助将不胜感激。

【问题讨论】:

    标签: r dataset data-science


    【解决方案1】:

    添加对我有用的东西,在另一篇文章中建议。

    ts_fin <- ts(emea$Value, deltat = 1/24, start = c(2014, 21))
    

    这有助于我获得准确的时间序列。

    【讨论】:

      猜你喜欢
      • 2015-08-08
      • 2018-02-19
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      相关资源
      最近更新 更多