缺失时间序列数据的估算预测几乎是平稳的(扁平线)
Imputed predictions for missing time-series data nearly stationary (flat line)
我有一段时间内的球员数据,这些数据缺少几年的球员人数。我正在尝试填充 in/predict 不同时间间隔内丢失的玩家计数数据。
此处提供数据:https://1drv.ms/u/s!AvEZ_QPY7OZuhJAlKJN89rH185SUhA
我正在按照下面使用 KalmanRun 估算缺失值的说明进行操作。我尝试了 3 种不同的方法来转换数据 - 使用 xts 对象,以及 2 种方法将其转换为时间序列数据
https://stats.stackexchange.com/questions/104565/how-to-use-auto-arima-to-impute-missing-values
require(forecast)
library(xts)
library(anytime)
library(DescTools)
df_temp = read.csv("r_share.csv")
df_temp[['DateTime']] <- as.Date(strptime(df_temp[['DateTime']], format='%Y-%m-%d %H:%M:%S'))
3 种数据转换方法; xts 似乎通过返回可解释的非零数据来发挥最佳作用。
#Convert df_temp to TimeSeries object
df_temp = xts(df_temp$Players, df_temp$DateTime)
#df_temp = as.ts(log(df_temp$Players), start = start(df_temp$DateTime), end = end(df_temp$DateTime), frequency = 365)
#df_temp = ts(df_temp$Players, start = c(2013, 02, 02), end = c(2016, 01, 31), frequency = 365)
拟合和绘图:
fit <- auto.arima(df_temp, seasonal = TRUE)
id.na <- which(is.na(df_temp))
kr <- KalmanRun(index(df_temp), fit$model, update = FALSE)
#?KalmanRun$tol
for (i in id.na)
df_temp[i] <- fit$model$Z %*% kr$states[i,]
plot(df_temp)
预期输出是模拟实际数据中的可变性的数据,并且每个区间都不同,而实际输出相对稳定且不变(两个区间具有几乎相同的预测)。
需要搭配型号arima()
?.
也许你可以试试另一个由 Facebook 开发的名为 Prophet 的模型。
在这里你可以找到 guide and github page.
如果我知道你想要这样的东西:
# Import library
library(prophet)
# Read data
df = read.csv("C:/Users/Downloads/r_share.csv",sep = ";")
# Transform to date
df["DateTime"] = as.Date(df$DateTime,format = "%d/%m/%Y")
# Change names for the model
colnames(df) = c("ds","y")
# call model
m = prophet(df)
# make "future" just one day greater than past
future = make_future_dataframe(m,periods = 1)
# predict the points
forecast = predict(m,future)
# plot results
plot(m,forecast)
我有一段时间内的球员数据,这些数据缺少几年的球员人数。我正在尝试填充 in/predict 不同时间间隔内丢失的玩家计数数据。
此处提供数据:https://1drv.ms/u/s!AvEZ_QPY7OZuhJAlKJN89rH185SUhA
我正在按照下面使用 KalmanRun 估算缺失值的说明进行操作。我尝试了 3 种不同的方法来转换数据 - 使用 xts 对象,以及 2 种方法将其转换为时间序列数据
https://stats.stackexchange.com/questions/104565/how-to-use-auto-arima-to-impute-missing-values
require(forecast)
library(xts)
library(anytime)
library(DescTools)
df_temp = read.csv("r_share.csv")
df_temp[['DateTime']] <- as.Date(strptime(df_temp[['DateTime']], format='%Y-%m-%d %H:%M:%S'))
3 种数据转换方法; xts 似乎通过返回可解释的非零数据来发挥最佳作用。
#Convert df_temp to TimeSeries object
df_temp = xts(df_temp$Players, df_temp$DateTime)
#df_temp = as.ts(log(df_temp$Players), start = start(df_temp$DateTime), end = end(df_temp$DateTime), frequency = 365)
#df_temp = ts(df_temp$Players, start = c(2013, 02, 02), end = c(2016, 01, 31), frequency = 365)
拟合和绘图:
fit <- auto.arima(df_temp, seasonal = TRUE)
id.na <- which(is.na(df_temp))
kr <- KalmanRun(index(df_temp), fit$model, update = FALSE)
#?KalmanRun$tol
for (i in id.na)
df_temp[i] <- fit$model$Z %*% kr$states[i,]
plot(df_temp)
预期输出是模拟实际数据中的可变性的数据,并且每个区间都不同,而实际输出相对稳定且不变(两个区间具有几乎相同的预测)。
需要搭配型号arima()
?.
也许你可以试试另一个由 Facebook 开发的名为 Prophet 的模型。
在这里你可以找到 guide and github page.
如果我知道你想要这样的东西:
# Import library
library(prophet)
# Read data
df = read.csv("C:/Users/Downloads/r_share.csv",sep = ";")
# Transform to date
df["DateTime"] = as.Date(df$DateTime,format = "%d/%m/%Y")
# Change names for the model
colnames(df) = c("ds","y")
# call model
m = prophet(df)
# make "future" just one day greater than past
future = make_future_dataframe(m,periods = 1)
# predict the points
forecast = predict(m,future)
# plot results
plot(m,forecast)