R で Forecast パッケージを使用していますが、自分の毎日の時系列を ts オブジェクトに読み込んで、これを予測アルゴリズムで使用するのが難しいことがわかりました。代わりに Zoo を使用して毎日の timeseries オブジェクトを作成しましたが、これを R Forecast パッケージの予測アルゴリズムに直接渡すことはできません。
正しい方向への助けをいただければ幸いです。私はこれに非常に行き詰まりを感じています。
ありがとう
こんにちは、サンプルコードです。単純な四半期ごとのデータセットでは予測が機能しますが、毎日のデータセットでは機能しません。どうもありがとう
require("forecast")
require("fpp")
# Example from Forecasting Principles and Practice
# http://otexts.com/fpp/2/5/
#beer2 <- window(ausbeer,start=1992,end=2006-.1)
#start with a really small dataset (only 6 data points)
beer2 <- window(ausbeer,start=2006,end=2006-.1)
print(beer2)
beerfit1 <- meanf(beer2,h=11)
beerfit2 <- rwf(beer2,h=11)
beerfit3 <- snaive(beer2,h=11)
plot(beerfit1, plot.conf=FALSE, main="Forecasts for quarterly beer production")
lines(beerfit2$mean,col=2)
lines(beerfit3$mean,col=3)
lines(ausbeer)
legend("topright", lty=1, col=c(4,2,3), legend=c("Mean method","Naive method","Seasonal naive method"))
beer3 <- window(ausbeer, start=2006)
accuracy(beerfit1, beer3)
accuracy(beerfit2, beer3)
accuracy(beerfit3, beer3)
#now make a really small daily dataset (Each day for two weeks)
forecast_datesequence = seq(from=as.Date("2013-05-06"), to=as.Date("2013-05-19"), by=1)
vals <- c(100,150,300,150,100,45,25,100,150,300,150,100,45,25)
dailyzoo_ts <- zoo(vals, forecast_datesequence)
print(daily_ts)
dailyfit1 <- meanf(coredata(dailyzoo_ts),h=7)
dailyfit2 <- rwf(coredata(dailyzoo_ts),h=7)
dailyfit3 <- snaive(coredata(dailyzoo_ts),h=7)
plot(dailyfit1, plot.conf=FALSE, main="Daily Data Over 2 Week Period")
lines(dailyfit2$mean,col=2)
lines(dailyfit3$mean,col=3)
lines(dailyzoo_ts)
legend("topright", lty=1, col=c(4,2,3), legend=c("Mean method","Naive method","Seasonal naive method"))
これは、まだ機能しない R コードの更新されたビットです。
#now make a really small daily dataset (Each day for two weeks)
forecast_datesequence = seq(from=as.Date("2013-05-06"), to=as.Date("2013-05-19"), by=1)
vals <- c(100,150,300,150,100,45,25,100,150,300,150,100,45,25)
dailyzoo_ts <- zoo(vals, forecast_datesequence)
print(daily_ts)
z <- zoo(coredata(dailyzoo_ts), 1:14/7)
print(z)
plot(forecast(z))
#stl(z)
dailyfit1 <- meanf(z,h=7)
dailyfit2 <- rwf(z,h=7)
dailyfit3 <- snaive(z,h=7)
plot(dailyfit1, plot.conf=FALSE, main="Daily Data Over 2 Week Period")
lines(dailyfit2$mean,col=2)
lines(dailyfit3$mean,col=3)
lines(z)
legend("topright", lty=1, col=c(4,2,3), legend=c("Mean method","Naive method","Seasonal naive method"))
どうもありがとう