Skip to content

Instantly share code, notes, and snippets.

@vitillo
Created April 3, 2014 20:21
Show Gist options
  • Save vitillo/9962151 to your computer and use it in GitHub Desktop.
Save vitillo/9962151 to your computer and use it in GitHub Desktop.
Time series forecast
library(forecast)
library(ggplot2)
library(dplyr)
predictions = as.factor(read.csv('results.csv')$Prediction)
levels(predictions) <- c("ok", "drop")
submissions <- read.csv('submissions.csv')$Submissions
submissions <- msts(submissions, seasonal.periods=c(24, 7*24), ts.frequency=24)
df <- data.frame(submissions) %.%
mutate(time = 1:n()/24,
prediction = predictions)
ggplot(aes(x = time, y = submissions), data=df) + geom_point() + xlab('Days') + ylab('Submissions') + theme_bw()
ggplot(aes(x = time, y = submissions), data=df) + geom_line() + xlab('Days') + ylab('Submissions') + theme_bw()
ggplot(aes(x = time, y = submissions), data=df) + geom_point(aes(color = prediction)) + xlab('Days') + ylab('Submissions') + theme_bw()
classic_decomp <- decompose(ts(submissions, deltat=1/24))
bt <- tbats(submissions, use.parallel=T, num.cores=8)
submissions.clean <- window(submissions, start=20, end=40)
submissions.clean.test <- window(submissions, start=40.01, end=45)
bt.clean <- tbats(submissions.clean, use.parallel=T, num.cores=8)
df <- data.frame(submissions=submissions.clean.test) %.%
mutate(prediction = (forecast(bt.clean, h=5*24)$mean),
time = 1:n()/24)
ggplot(aes(time), data=df) + geom_line(aes(y = submissions, colour = 'Submissions')) +
geom_line(aes(y = prediction, color = 'Predictions')) +
scale_colour_manual(values=c("red", "black"))
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Prediction
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Submissions
20154
21442
22822
24403
24936
25862
26287
24310
21777
18061
16192
13067
13098
11694
11583
11274
12153
12379
13045
16423
17712
18326
19077
19383
20762
21729
22297
24658
25679
27481
26739
23545
23059
20746
16547
14520
13978
12209
12050
11529
12237
12423
15345
16113
18344
17797
20544
21614
21736
23452
24501
24667
25293
26636
25985
23326
20641
18541
16246
14395
12914
12395
12092
10716
11341
11751
12336
13104
15097
16038
17317
18340
17822
17272
18878
20480
20432
20021
19319
17032
14829
13296
12129
11188
9366
9728
9124
9001
8343
8700
8797
10166
12786
14665
14069
14555
15522
16241
16372
17883
18483
19007
17165
16255
13114
12697
9846
8801
8366
7900
8803
8384
9038
10022
11950
13596
14015
13369
13207
13463
13791
14484
15482
16889
17762
18503
16795
16249
13753
11476
9819
8529
8422
8478
8050
7934
9032
9269
9578
11984
13257
12792
11939
12936
13269
13748
14943
14432
16352
15966
15204
13828
11837
10881
9013
7721
7715
7250
7036
7491
7668
8256
9128
10564
10788
11511
11893
11476
11706
13157
14219
14676
15253
14387
13741
13334
11453
10324
8274
8084
7042
7006
7134
7134
7239
7406
8638
9614
10005
10612
11428
10421
11796
12128
12010
13321
13636
14082
13456
12039
11272
9481
8176
7043
6414
7408
6473
6766
6673
6799
7682
9084
9268
9823
9590
10526
10837
11582
11624
12239
12595
13047
12308
11375
10726
9299
8245
7201
6705
6387
6557
6832
6509
6886
7555
8188
9060
10593
11215
11328
11787
12687
13614
15318
15856
15998
15893
15353
13739
12312
10881
9812
8954
8147
8195
8187
7690
8484
8547
9975
11357
12703
14231
15484
16301
16442
18206
17942
19723
19701
19262
17516
15678
14368
12292
10727
10361
10474
9839
9773
10419
10991
12077
13347
14922
15081
15001
15775
17053
18741
19505
20810
23240
23228
22071
19775
18475
16577
14743
12927
12021
11779
11184
11326
11336
11966
12449
15072
16977
16589
16495
18609
18416
20766
20552
21607
23607
24331
23761
23182
19945
18169
14480
13684
11665
12616
11884
11101
12705
12455
13909
15372
17026
17768
19124
18669
19273
22281
23308
23464
23681
25966
24279
22751
20333
17900
15429
13656
12940
12689
11904
10914
12111
13061
13839
16041
16852
18080
18166
19233
19679
21512
23850
24212
24128
25952
24995
21909
20626
18288
16165
13788
12283
12768
12039
11564
11864
12032
12813
15127
16829
18660
18500
18280
19185
21667
21791
24246
26350
24286
24606
24112
20279
18526
16669
14880
13501
12072
11789
11429
11704
11486
12541
13774
16509
17457
18771
18986
20181
20656
21072
22734
24428
23792
22768
21704
20053
16476
15429
14355
12264
11897
11495
11226
11965
10895
12187
14359
15879
17183
18986
21521
20814
21408
23276
24047
24807
25000
24216
22656
20189
18749
14460
14531
13090
12540
13076
12076
12770
13677
15665
16851
19408
19018
19058
19919
19847
22485
24252
25482
28013
28055
28316
24320
22650
20535
16432
14197
13258
13774
14659
12804
13080
14351
15622
18354
19235
22174
18986
21685
21888
23333
24575
26045
25959
27722
26664
25759
22696
18629
15971
14534
14320
12333
14485
13391
13408
15333
16267
17065
18906
20349
21136
20571
21506
23889
24777
24529
26749
27799
27656
26168
23062
19501
16551
15162
13952
12881
13709
13337
14200
15122
14718
17181
18878
20045
19639
21968
21342
22309
23594
24543
26466
26468
26848
26055
22818
19559
17598
14170
14245
13009
12861
13701
13423
13652
14435
16331
19518
20278
19064
21475
22725
22524
24799
25565
27472
26666
25951
23763
22363
18984
17597
15852
13836
13532
13422
12245
12297
12666
14001
15272
15957
16945
18318
19937
20974
22368
22904
23667
23745
25246
25637
22142
19489
17524
15994
14382
13767
11820
11367
12604
12336
11945
11903
14602
16681
18740
19731
21636
21602
21754
22921
23548
25907
27010
25334
25028
20988
18041
15536
14315
13409
14266
13702
13659
13511
14382
15472
18452
19056
19269
20283
20716
21777
23589
25348
27182
28807
30104
28178
26569
22622
19705
17417
15609
13915
13103
14336
14269
14460
15017
15581
20476
20594
21241
20898
21378
22808
24372
25646
26939
27487
28317
27809
27198
22837
19101
16465
15150
14044
14719
14779
14343
14439
14668
15902
18869
20559
21159
20646
20849
21598
24127
24686
27809
26996
28228
26810
26169
23633
19928
17229
14120
13430
13833
13270
14608
14246
14892
15679
18249
20279
20092
19790
21416
20444
21866
25260
25220
27045
27818
27096
25055
22355
19897
18108
15024
13902
13314
13297
13711
13711
14203
14803
18156
18893
20887
20212
20907
22558
23205
25938
25982
27353
26209
25135
24118
21416
18733
16002
14844
13730
13330
12214
13251
12649
13903
13793
15606
16972
18666
18814
19247
19526
21067
23623
23487
26023
24138
25033
22971
20072
18562
15952
14454
13448
12698
12353
13035
12640
11491
13363
16100
17358
18026
20939
21241
22027
21460
22666
24320
25868
26091
24393
24018
20798
18846
16736
14334
12951
14127
12856
12869
13401
14915
16743
18130
20961
19885
19686
20305
20638
23137
27837
27625
27896
29450
29720
24959
23592
19526
17230
15448
14308
15648
15161
13515
14369
15028
15385
18623
21493
21784
21028
22407
22218
23028
25380
27656
27237
30231
26799
25364
23030
19887
17900
15262
13671
14419
14142
13502
14191
15612
16267
18048
20980
21526
20464
22219
22921
23503
25470
26157
28926
28724
27533
24770
23220
19945
17421
14381
14105
13647
14832
13722
14119
14253
15218
18015
19107
20914
20917
21982
22318
23024
24140
27142
26489
28646
29352
25184
22637
18794
17728
15035
12830
14163
13533
13855
14435
14289
15708
17206
18709
22221
20165
22125
22544
23497
24880
25102
26821
26174
25983
23380
20732
19887
16580
14718
13625
13016
12695
11705
13064
13166
13885
15432
17480
17591
18804
20590
20775
20613
21916
22390
25387
24574
24133
23032
19886
17486
15509
13544
12453
11540
11956
11743
11842
12098
13887
15413
17840
17388
19349
21077
21838
21623
22955
24406
24904
25933
24741
24595
21252
18029
16203
13399
12889
13615
15243
13422
14137
14832
15956
17924
20207
19954
19631
21070
21327
23490
24120
25794
27495
27230
28367
25596
22828
19607
17944
14313
14295
13805
14547
13235
14583
15684
16082
19204
20491
20922
21899
21153
21324
25140
25364
25783
27836
28272
27943
25483
23716
20238
17244
14705
14557
13449
13607
14002
13817
15334
17112
18534
19602
19104
20476
22433
22290
33110
24113
26783
28321
27281
28870
27453
24421
20469
17312
15211
14392
13524
13068
13226
12746
14868
15589
18743
20719
19675
19834
22268
21916
23503
23645
25142
27558
28573
28158
25371
24839
19662
16427
15274
14713
12999
13686
14323
14213
12928
14587
18353
19574
19694
20496
22334
22131
23661
23934
25551
25253
26769
25394
23711
21628
18865
16401
14715
12270
12384
12664
12195
12670
13401
15018
15504
17273
18745
18045
20197
20663
20893
23046
23161
24778
23871
23729
22191
19640
17294
15823
13903
12753
11371
11729
11247
12108
12026
16947
22515
26560
27228
31115
32609
32918
33918
36475
37764
38324
33983
26275
24111
20081
9383
7799
7089
6576
6465
6395
6283
6698
7053
8171
8701
10409
9938
9605
10274
10579
11000
12415
13507
13089
14052
14031
13495
11795
10646
8446
7703
6956
6820
6935
6392
7803
7362
8549
9499
9837
10145
9719
10847
11141
12484
12427
13337
13448
14003
13720
12920
11697
10010
8201
7056
6419
6762
6575
6583
6946
7305
7909
9292
10351
10623
10889
10382
10895
11573
12280
13677
13082
14165
13652
11987
11346
10040
8885
7740
6567
7098
6745
6996
7258
7126
6926
8726
9829
9636
10583
10904
10884
11271
12250
12859
13312
13644
13558
12546
11479
9568
8888
7296
7187
6801
6789
5928
6682
6824
7572
8594
9210
9772
9923
10801
12118
10986
12433
12024
13297
12321
13068
15921
10729
9347
8391
7572
6655
5931
5875
5650
5494
6327
6728
7871
8635
8903
9809
9244
10392
11192
10908
11169
11541
12724
11548
11172
9705
9191
7931
6908
6675
5942
6035
5672
5376
5696
6911
7047
9058
8758
9883
10781
11292
10983
11782
12043
13691
12960
13854
12305
10645
9803
8005
6536
6592
6209
6314
8053
6667
7511
12448
19176
20138
19580
19852
22397
21442
24679
24880
26118
27963
28393
26803
25971
23058
20628
17754
15201
13378
13933
14750
12056
14919
15374
16005
19600
20570
19985
21626
21027
22891
22533
26299
27555
28979
28887
29265
25581
23471
18530
16198
14307
14360
13731
13404
13399
13364
14971
15798
18380
20138
20393
20931
22513
22103
23878
25314
26886
29128
27359
27724
25770
23494
19410
16254
15085
13761
13631
13072
12838
14230
14526
16950
18033
19145
20174
19650
21968
22293
22054
24280
25036
26338
27740
27523
25994
22200
19550
16604
15104
13014
13742
12823
13198
14539
14810
15778
18296
20909
20437
19334
21239
21154
22205
23184
24456
26672
26460
26630
23424
22101
18197
16730
13358
13391
11907
12749
12429
12202
13310
14150
14932
17954
17227
17292
18835
21058
21405
22008
22862
22748
22922
23838
21700
20264
18048
14994
13389
13734
11958
11578
11895
12420
12915
13049
15863
17546
18686
19457
8156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment