-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpredict.R
36 lines (32 loc) · 917 Bytes
/
predict.R
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
library(forecast)
library('plyr')
source('preprocess-data.R')
datePattern = '%Y%m%d'
dataInWeekdays = data[data$time >= strptime('20141103', datePattern)
& data$time < strptime('20141108', datePattern),]
ids = levels(data$id)
ids = ids[ids != '0180']
frequency = 60 * 24
predictionByStationId = list()
for(id in ids){
print(id)
#time series
xData = dataInWeekdays[dataInWeekdays$id == id,]
ind_size = length(xData$id)
five_day_ind = 1:ind_size
xData.ts = ts(xData$ratio, start=1, frequency=frequency)
fit = stl(xData.ts, 'periodic')
#prediction
pred = as.numeric(forecast(fit, h=frequency)$mean)
header = xData[1,]
predictionByStationId[[as.character(id)]] = list(
id=header$id,
name=header$name,
district=header$district,
address=header$address,
lat=header$lat,
lon=header$lon,
ratios=pred
)
}
save(predictionByStationId, file='predictionByStationId.rda')