加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
.Rhistory 11.51 KB
一键复制 编辑 原始数据 按行查看 历史
xiashiwendao 提交于 2019-09-17 23:07 . add daily data to csv
q()
data(ml)
install.packages("TSA")
install.packages("MASS","tseries","uroot")
install.packages("MASS","tseries","uroot")
install.packages("MASS")
install.packages("tseries")
install.packages("uroot")
install.packages("uroot")
library(TSA)
library("uroot")
library(uroot)
library(cc)
library("TSA")
library(TSA)
library(MASS)
library("MASS")
library("tseries")
library("train")
library("train.ts")
install.packages("Tableau")
installed.packages()
install.packages("forecast")
install.packages()
install.packages()
install.packages("forecast")
install.packages()
installed.packages()
Amtrak.data <- read.csv("Amtrak data.csv")
nValid <- 36
library(forecast)
library(zoo)
Amtrak.data <- read.csv("Amtrak_data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
nValid <- 36
nTrain <- length(ridership.ts) - nValid
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + nValid))
train.lm <- tslm(train.ts ~ trend)
# Figure 6.2
plot(train.ts, xlab = "Time", ylab = "Ridership", ylim = c(1300, 2300), bty = "l")
lines(train.lm$fitted, lwd = 2)
# Table 6.1
summary(train.lm)
install.packages("~/MySpace/research/Machine-Learn/TimeSerias/aa/forecast_7.1.tar.gz", repos = NULL, type = "source", lib="C:/Users/wenyang.zhang/Documents/R/R-3.6.0/library")
library(forecast)
library(zoo)
Amtrak.data <- read.csv("Amtrak_data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
nValid <- 36
nTrain <- length(ridership.ts) - nValid
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + nValid))
train.lm <- tslm(train.ts ~ trend)
# Figure 6.2
plot(train.ts, xlab = "Time", ylab = "Ridership", ylim = c(1300, 2300), bty = "l")
lines(train.lm$fitted, lwd = 2)
# Table 6.1
summary(train.lm)
Amtrak.data <- read.csv("Amtrak_data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
Amtrak.data <- read.csv(".\\Amtrak_data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
Amtrak.data <- read.csv("C:\Users\wenyang.zhang\Documents\MySpace\research\Machine-Learn\TimeSerias\aa\R-code-for-forecast-7.1-second-edition\R-code-for-forecast-7.1\Amtrak_data.csv")
Amtrak.data <- read.csv("C:\\Users\\wenyang.zhang\\Documents\\MySpace\\research\\Machine-Learn\\TimeSerias\\aa\\R-code-for-forecast-7.1-second-edition\\R-code-for-forecast-7.1\\Amtrak_data.csv")
library(forecast)
library(zoo)
Amtrak.data <- read.csv("C:\\Users\\wenyang.zhang\\Documents\\MySpace\\research\\Machine-Learn\\TimeSerias\\aa\\R-code-for-forecast-7.1-second-edition\\R-code-for-forecast-7.1\\Amtrak_data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
nValid <- 36
nTrain <- length(ridership.ts) - nValid
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + nValid))
train.lm <- tslm(train.ts ~ trend)
# Figure 6.2
plot(train.ts, xlab = "Time", ylab = "Ridership", ylim = c(1300, 2300), bty = "l")
lines(train.lm$fitted, lwd = 2)
# Table 6.1
summary(train.lm)
help(tslm)
help(trend)
library(forecast)
library(zoo)
Amtrak.data <- read.csv("Amtrak data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
nValid <- 36
nTrain <- length(ridership.ts) - nValid
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + nValid))
train.lm.expo.trend <- tslm(train.ts ~ trend, lambda = 0)
train.lm.expo.trend.pred <- forecast(train.lm.expo.trend, h = nValid, level = 0)
train.lm.linear.trend <- tslm(train.ts ~ trend, lambda = 1)
train.lm.linear.trend.pred <- forecast(train.lm.linear.trend, h = nValid, level = 0)
# Figures 6-3/6-5
plot(train.lm.expo.trend.pred, ylim = c(1300, 2600), ylab = "Ridership", xlab = "Time", bty = "l", xaxt = "n", xlim = c(1991,2006.25), main = "", flty = 2)
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(train.lm.expo.trend.pred$fitted, lwd = 2, col = "blue") # Added in 6-5
lines(train.lm.linear.trend.pred$fitted, lwd = 2, col = "black", lty = 3)
lines(train.lm.linear.trend.pred$mean, lwd = 2, col = "black", lty = 3)
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
text(2005.25, 2500, "Future")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5, 2450, 2006, 2450, code = 3, length = 0.1, lwd = 1, angle = 30)
BoxCox(train.ts, 0)
help(train)
Amtrak.data <- read.csv("Amtrak data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
nValid <- 36
nTrain <- length(ridership.ts) - nValid
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + nValid))
# Table 6.3
train.lm.season <- tslm(train.ts ~ season)
summary(train.lm.season)
cls
clear
clean
dsfd
train.lm.season.pred <- forecast(train.lm.season, h = nValid, level = 0)
# Figure 6-7
par(mfrow = c(2,1))
plot(train.lm.season.pred, ylim = c(1300, 2625), ylab = "Ridership", xlab = "Time", bty = "l", xaxt = "n", xlim = c(1991,2006.25), main = "", flty = 2)
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(train.lm.season.pred$fitted, lwd = 2, col = "blue")
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2600, "Training")
text(2002.75, 2600, "Validation")
text(2005.25, 2600, "Future")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5, 2450, 2006, 2450, code = 3, length = 0.1, lwd = 1, angle = 30)
plot(train.lm.season.pred$residuals, ylim = c(-400, 550), ylab = "Residuals", xlab = "Time", bty = "l", xaxt = "n", xlim = c(1991,2006.25), main = "")
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(train.ts - train.lm.season.pred$fitted)
lines(valid.ts - train.lm.season.pred$mean)
lines(c(2004.25 - 3, 2004.25 - 3), c(-500, 3500))
lines(c(2004.25, 2004.25), c(-500, 3500))
text(1996.25, 525, "Training")
text(2002.75, 525, "Validation")
text(2005.25, 525, "Future")
arrows(2004 - 3, 425, 1991.25, 425, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 425, 2004, 425, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5, 425, 2006, 425, code = 3, length = 0.1, lwd = 1, angle = 30)
# Table 6.5
train.lm.trig <- tslm(train.ts ~ trend + I(sin(2*pi*trend/12)) + I(cos(2*pi*trend/12)))
train.lm.trig.pred <- forecast(train.lm.trig, h = nValid, level = 0)
plot(train.lm.trig.pred, ylim = c(1300, 2600), ylab = "Ridership", xlab = "Time", bty = "l", xaxt = "n", xlim = c(1991,2006.25), main = "", flty = 2)
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(train.lm.trig.pred$fitted, lwd = 2, col = "blue")
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
text(2005.25, 2500, "Future")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5, 2450, 2006, 2450, code = 3, length = 0.1, lwd = 1, angle = 30)
summary(train.lm.trig)
summary(train.lm.trig)
library(forecast)
library(zoo)
Amtrak.data <- read.csv("Amtrak data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
nValid <- 36
nTrain <- length(ridership.ts) - nValid
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + nValid))
train.lm.trend.season <- tslm(train.ts ~ trend + I(trend^2) + season)
train.lm.trend.season.pred <- forecast(train.lm.trend.season, h = nValid, level = 0)
# Table 6-4
summary(train.lm.trend.season)
# Figure 6-8
par(mfrow = c(2,1))
plot(train.lm.trend.season.pred, ylim = c(1300, 2625), ylab = "Ridership", xlab = "Time", bty = "l", xaxt = "n", xlim = c(1991,2006.25), main = "", flty = 2)
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(train.lm.trend.season.pred$fitted, lwd = 2, col = "blue")
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2600, "Training")
text(2002.75, 2600, "Validation")
text(2005.25, 2600, "Future")
help(text)
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5, 2450, 2006, 2450, code = 3, length = 0.1, lwd = 1, angle = 30)
plot(train.lm.trend.season.pred$residuals, ylim = c(-400, 550), ylab = "Residuals", xlab = "Time", bty = "l", xaxt = "n", xlim = c(1991,2006.25), main = "")
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(train.ts - train.lm.trend.season.pred$fitted)
lines(valid.ts - train.lm.trend.season.pred$mean)
help(line)
lines(c(2004.25 - 3, 2004.25 - 3), c(-500, 3500))
lines(c(2004.25, 2004.25), c(-500, 3500))
text(1996.25, 525, "Training")
text(2002.75, 525, "Validation")
text(2005.25, 525, "Future")
arrows(2004 - 3, 425, 1991.25, 425, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 425, 2004, 425, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5, 425, 2006, 425, code = 3, length = 0.1, lwd = 1, angle = 30)
dev.off()
help(dev.off)
train <- read.csv("dataset\\train.csv")
train <- read.csv(".\\dataset\\train.csv")
train <- read.csv("C:\\Users\\wenyang.zhang\\Documents\\MySpace\\practice\\github\\R_Explorer\\dataset\\train.csv")
test<-read.csv(("C:\\Users\\wenyang.zhang\\Documents\\MySpace\\practice\\github\\R_Explorer\\dataset\\test.csv")
mode(train)
test<-read.csv("C:\\Users\\wenyang.zhang\\Documents\\MySpace\\practice\\github\\R_Explorer\\dataset\\test.csv")
mode(train)
train
str(train)
str(train)
library(dplyr)
install.packages("dplyr")
help(dplyr)
help("dplyr")
install.packages("dplyr")
library(randomForest)
library(sqldf)
#library(CrossR)
library(caret)
library(TSA)
library(Metrics)
banner_trend = read.csv("dataset\\banner_carr_month.csv")
# get the sequence Data
ts.raw = banner_trend[["QLI"]]
# get the TS Data
ts.ts = ts(ts.raw, start = c(2016,9),frequency = 12)
banner_trend = read.csv("dataset\\banner_carr_month.csv")
setwd("~/MySpace/practice/github/predictionPlatform")
banner_trend = read.csv("dataset\\banner_carr_month.csv")
# get the sequence Data
ts.raw = banner_trend[["QLI"]]
# get the TS Data
ts.ts = ts(ts.raw, start = c(2016,9),frequency = 12)
plot(ts.ts)
start(ts.ts)
end(ts.ts)
frequency(ts.ts)
ts.ts
fit = stl(ts.ts, s.window = "period")
fit
library(forecast)
forecast(fit, 1)
ts.ma=arima(ts.ts, order=c(2,0,1), seasonal = list(order=c(1,0,0), period=12))
#plot(ts.ts)
#plot(ts.ts, n1=c(2016,9), n.ahead=36, type='o')
#plot(ts.ma)
pred_val =predict(ts.ma, 6)
pred_val
ts.ma=arima(ts.ts, order=c(1,0,1), seasonal = list(order=c(1,0,0), period=12))
#plot(ts.ts)
#plot(ts.ts, n1=c(2016,9), n.ahead=36, type='o')
#plot(ts.ma)
pred_val =predict(ts.ma, 6)
pred_val
pred_val$pred
pred_val$pred
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化