-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
193 lines (193 loc) · 5.39 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
ls
ls()
?stlf
library(data.table)
library(forecast)
library(plyr)
library(xgboost)
?stlf
source('D:/Rproject/tianchi_music/ts.R', echo=TRUE)
y1<-setDT(y)[y$action_type==1]
y1$count<-1
y1$gmt_create<-NULL
y1<-y1[,count:=sum(count),by=.(song_id,Ds)]
y1$user_id<-NULL
y1<-unique(y1)
y1<-y1[order(song_id,Ds)]
o_d<-1:61+as.Date("20150830","%Y%m%d")
ts_fit = function(x) {
a=vector(mode="integer",length = 183)
index=as.Date(as.character(x$Ds), "%Y%m%d")-as.Date("20150228","%Y%m%d")
print(index)
a[index]=x$count
b<-ts(a,frequency = 7)
#fit <- auto.arima(b)
#fit <- tslm(b~trend+season)
#p<-hw(b,h=61,seasonal = 'additive')
#p<-stlf(b,h=61)
# fit<-ets(b)
# p<-forecast(fit,h=61)
fit = arima(train, order = c(0, 1, 3), seasonal=list(order=c(0,1,3), period=7))
p<-predict(fit,61)
o<-p$mean
o[o<0]<-0
o<-round(o)
#fit <- tslm(Sales ~ trend + season + DayOfWeek + Open + Promo + StateHoliday + SchoolHoliday)
return(data.table(ds=o_d,pred=o))
}
out<-y1[,ts_fit(.SD),by=.(song_id)]
out1<-out
out1$ds<-format(out1$ds, "%Y%m%d")
out1<-out1[ds!="20150831"]
out1<-out1[x,on='song_id']
out1<-out1[,sum(pred),by=.(artist_id,ds)]
out1<-out1[,list(artist_id,V1,ds)]
out1<-out1[!is.na(ds)]
write.table(out1,file='./ts_arima1.csv',row.names = F,col.names = F,quote = F,sep = ',')
y1<-setDT(y)[y$action_type==1]
y1$count<-1
y1$gmt_create<-NULL
y1<-y1[,count:=sum(count),by=.(song_id,Ds)]
y1$user_id<-NULL
y1<-unique(y1)
y1<-y1[order(song_id,Ds)]
o_d<-1:61+as.Date("20150830","%Y%m%d")
ts_fit = function(x) {
a=vector(mode="integer",length = 183)
index=as.Date(as.character(x$Ds), "%Y%m%d")-as.Date("20150228","%Y%m%d")
print(index)
a[index]=x$count
b<-ts(a,frequency = 7)
#fit <- auto.arima(b)
#fit <- tslm(b~trend+season)
#p<-hw(b,h=61,seasonal = 'additive')
#p<-stlf(b,h=61)
# fit<-ets(b)
# p<-forecast(fit,h=61)
fit = arima(b, order = c(0, 1, 3), seasonal=list(order=c(0,1,3), period=7))
p<-predict(fit,61)
o<-p$mean
o[o<0]<-0
o<-round(o)
#fit <- tslm(Sales ~ trend + season + DayOfWeek + Open + Promo + StateHoliday + SchoolHoliday)
return(data.table(ds=o_d,pred=o))
}
out<-y1[,ts_fit(.SD),by=.(song_id)]
out1<-out
out1$ds<-format(out1$ds, "%Y%m%d")
out1<-out1[ds!="20150831"]
out1<-out1[x,on='song_id']
out1<-out1[,sum(pred),by=.(artist_id,ds)]
out1<-out1[,list(artist_id,V1,ds)]
out1<-out1[!is.na(ds)]
write.table(out1,file='./ts_arima1.csv',row.names = F,col.names = F,quote = F,sep = ',')
ts_fit = function(x) {
a=vector(mode="integer",length = 183)
index=as.Date(as.character(x$Ds), "%Y%m%d")-as.Date("20150228","%Y%m%d")
print(index)
a[index]=x$count
b<-ts(a,frequency = 7)
#fit <- auto.arima(b)
#fit <- tslm(b~trend+season)
#p<-hw(b,h=61,seasonal = 'additive')
#p<-stlf(b,h=61)
# fit<-ets(b)
# p<-forecast(fit,h=61)
fit = arima(b, order = c(0, 1, 3), seasonal=list(order=c(0,1,3), period=7))
p<-predict(fit,61)
print(p)
o<-p$mean
o[o<0]<-0
o<-round(o)
#fit <- tslm(Sales ~ trend + season + DayOfWeek + Open + Promo + StateHoliday + SchoolHoliday)
return(data.table(ds=o_d,pred=o))
}
out<-y1[,ts_fit(.SD),by=.(song_id)]
ts_fit = function(x) {
a=vector(mode="integer",length = 183)
index=as.Date(as.character(x$Ds), "%Y%m%d")-as.Date("20150228","%Y%m%d")
print(index)
a[index]=x$count
b<-ts(a,frequency = 7)
#fit <- auto.arima(b)
#fit <- tslm(b~trend+season)
#p<-hw(b,h=61,seasonal = 'additive')
#p<-stlf(b,h=61)
# fit<-ets(b)
# p<-forecast(fit,h=61)
fit = arima(b, order = c(0, 1, 3), seasonal=list(order=c(0,1,3), period=7))
p<-predict(fit,61)
o<-p$mean
o[o<0]<-0
o<-round(o)
print(o)
#fit <- tslm(Sales ~ trend + season + DayOfWeek + Open + Promo + StateHoliday + SchoolHoliday)
return(data.table(ds=o_d,pred=o))
}
out<-y1[,ts_fit(.SD),by=.(song_id)]
ts_fit = function(x) {
a=vector(mode="integer",length = 183)
index=as.Date(as.character(x$Ds), "%Y%m%d")-as.Date("20150228","%Y%m%d")
print(index)
a[index]=x$count
b<-ts(a,frequency = 7)
#fit <- auto.arima(b)
#fit <- tslm(b~trend+season)
#p<-hw(b,h=61,seasonal = 'additive')
#p<-stlf(b,h=61)
# fit<-ets(b)
# p<-forecast(fit,h=61)
fit = arima(b, order = c(0, 1, 3), seasonal=list(order=c(0,1,3), period=7))
p<-predict(fit,61)
o<-p$mean
print(o)
o[o<0]<-0
o<-round(o)
#fit <- tslm(Sales ~ trend + season + DayOfWeek + Open + Promo + StateHoliday + SchoolHoliday)
return(data.table(ds=o_d,pred=o))
}
out<-y1[,ts_fit(.SD),by=.(song_id)]
y1<-setDT(y)[y$action_type==1]
y1$count<-1
y1$gmt_create<-NULL
y1<-y1[,count:=sum(count),by=.(song_id,Ds)]
y1$user_id<-NULL
y1<-unique(y1)
y1<-y1[order(song_id,Ds)]
o_d<-1:61+as.Date("20150830","%Y%m%d")
ts_fit = function(x) {
a=vector(mode="integer",length = 183)
index=as.Date(as.character(x$Ds), "%Y%m%d")-as.Date("20150228","%Y%m%d")
print(index)
a[index]=x$count
b<-ts(a,frequency = 7)
#fit <- auto.arima(b)
#fit <- tslm(b~trend+season)
#p<-hw(b,h=61,seasonal = 'additive')
#p<-stlf(b,h=61)
# fit<-ets(b)
# p<-forecast(fit,h=61)
fit = arima(b, order = c(0, 1, 3), seasonal=list(order=c(0,1,3), period=7))
p<-predict(fit,61)
o<-p$pred
print(o)
o[o<0]<-0
o<-round(o)
#fit <- tslm(Sales ~ trend + season + DayOfWeek + Open + Promo + StateHoliday + SchoolHoliday)
return(data.table(ds=o_d,pred=o))
}
out<-y1[,ts_fit(.SD),by=.(song_id)]
out1<-out
out1$ds<-format(out1$ds, "%Y%m%d")
out1<-out1[ds!="20150831"]
out1<-out1[x,on='song_id']
out1<-out1[,sum(pred),by=.(artist_id,ds)]
out1<-out1[,list(artist_id,V1,ds)]
out1<-out1[!is.na(ds)]
write.table(out1,file='./ts_arima1.csv',row.names = F,col.names = F,quote = F,sep = ',')
??snaive
library(data.table)
library(forecast)
library(plyr)
library(xgboost)
??snaive