import pandas as pd
import numpy as np
import seaborn as sns
from scipy import stats
import matplotlib as mpl
import matplotlib .pyplot as plt
from fbprophet import Prophet
We will be looking at Transactions at advertised locations for the last 2 years, by Day & Week. This data will be used to forecast out weekly Transactions to compare last year to.
data = pd .read_csv ('Sales_by_day.csv' , parse_dates = ['ds' ])
txns = pd .DataFrame (data [['ds' ,'# Txns' ]])
txns ['y' ] = np .log10 (txns ['# Txns' ])
del txns ['# Txns' ]
txns
data = pd .read_csv ('Sales_by_day.csv' , parse_dates = ['ds' ])
sales = pd .DataFrame (data [['ds' ,'Sales $' ]])
sales ['y' ] = np .log10 (sales ['Sales $' ])
del sales ['Sales $' ]
sales
ds
y
0
2015-02-01
4.721918
1
2015-02-02
4.709092
2
2015-02-03
4.673058
3
2015-02-04
4.684917
4
2015-02-05
4.679173
5
2015-02-06
4.755204
6
2015-02-07
4.795623
7
2015-02-08
4.703704
8
2015-02-09
4.667985
9
2015-02-10
4.689362
10
2015-02-11
4.741286
11
2015-02-12
4.801952
12
2015-02-14
4.885039
13
2015-02-15
4.727509
14
2015-02-16
4.664567
15
2015-02-17
4.575142
16
2015-02-18
4.675934
17
2015-02-19
4.705932
18
2015-02-20
4.746580
19
2015-02-21
4.782967
20
2015-02-22
4.680843
21
2015-02-23
4.652672
22
2015-02-24
4.674503
23
2015-02-25
4.713793
24
2015-02-26
4.660078
25
2015-02-27
4.807440
26
2015-02-28
4.831543
27
2015-03-01
4.713742
28
2015-03-02
4.695368
29
2015-03-03
4.692600
...
...
...
695
2017-01-27
4.742937
696
2017-01-28
4.754975
697
2017-01-29
4.647305
698
2017-01-30
4.581665
699
2017-01-31
4.651123
700
2017-02-01
4.753476
701
2017-02-02
4.735224
702
2017-02-03
4.785180
703
2017-02-04
4.825517
704
2017-02-05
4.686538
705
2017-02-06
4.654658
706
2017-02-07
4.729343
ds
y
0
2015-02-01
6.568501
1
2015-02-02
6.519151
2
2015-02-03
6.352087
3
2015-02-04
6.407623
4
2015-02-05
6.376327
5
2015-02-06
6.469397
6
2015-02-07
6.605302
7
2015-02-08
6.477032
8
2015-02-09
6.347584
9
2015-02-10
6.378210
10
2015-02-11
6.511220
11
2015-02-12
6.560980
12
2015-02-14
6.750798
13
2015-02-15
6.565547
14
2015-02-16
6.469702
15
2015-02-17
6.241425
16
2015-02-18
6.361745
17
2015-02-19
6.426021
18
2015-02-20
6.479443
19
2015-02-21
6.595187
20
2015-02-22
6.457410
21
2015-02-23
6.306829
22
2015-02-24
6.349313
23
2015-02-25
6.431925
24
2015-02-26
6.399252
25
2015-02-27
6.562656
26
2015-02-28
6.667724
27
2015-03-01
6.529803
28
2015-03-02
6.372163
29
2015-03-03
6.389169
...
...
...
695
2017-01-27
6.447965
696
2017-01-28
6.556622
697
2017-01-29
6.405705
698
2017-01-30
6.196282
699
2017-01-31
6.315664
700
2017-02-01
6.568835
701
2017-02-02
6.512520
702
2017-02-03
6.578559
703
2017-02-04
6.701477
704
2017-02-05
6.510305
705
2017-02-06
6.384240
706
2017-02-07
6.501414
707
2017-02-08
6.317689
708
2017-02-09
6.320989
709
2017-02-10
6.443153
710
2017-02-11
6.547922
711
2017-02-12
6.437922
712
2017-02-13
6.472022
713
2017-02-14
6.534376
714
2017-02-15
6.403736
715
2017-02-16
6.382633
716
2017-02-17
6.527329
717
2017-02-18
6.576850
718
2017-02-19
6.470435
719
2017-02-20
6.405650
720
2017-02-21
6.286527
721
2017-02-22
6.500512
722
2017-02-23
6.476577
723
2017-02-24
6.548398
724
2017-02-25
6.612316
725 rows × 2 columns
#forecasting tool used to fit model & plot data
m = Prophet ()
m .fit (txns )
<fbprophet.forecaster.Prophet at 0x7f7009d14748>
#create future dataframe with number of periods to be forecasted
future = m .make_future_dataframe (periods = 336 )
future
ds
0
2015-02-01
1
2015-02-02
2
2015-02-03
3
2015-02-04
4
2015-02-05
5
2015-02-06
6
2015-02-07
7
2015-02-08
8
2015-02-09
9
2015-02-10
10
2015-02-11
11
2015-02-12
12
2015-02-14
13
2015-02-15
14
2015-02-16
15
2015-02-17
16
2015-02-18
17
2015-02-19
18
2015-02-20
19
2015-02-21
20
2015-02-22
21
2015-02-23
22
2015-02-24
23
2015-02-25
24
2015-02-26
25
2015-02-27
26
2015-02-28
27
2015-03-01
28
2015-03-02
29
2015-03-03
...
...
1031
2017-12-29
1032
2017-12-30
1033
2017-12-31
1034
2018-01-01
1035
2018-01-02
1036
2018-01-03
1037
2018-01-04
1038
2018-01-05
1039
2018-01-06
1040
2018-01-07
1041
2018-01-08
1042
2018-01-09
1043
2018-01-10
1044
2018-01-11
1045
2018-01-12
1046
2018-01-13
1047
2018-01-14
1048
2018-01-15
1049
2018-01-16
1050
2018-01-17
1051
2018-01-18
1052
2018-01-19
1053
2018-01-20
1054
2018-01-21
1055
2018-01-22
1056
2018-01-23
1057
2018-01-24
1058
2018-01-25
1059
2018-01-26
1060
2018-01-27
1061 rows × 1 columns
No additional information considered here i.e., Events or Holidays
forecast = m .predict (future )
forecast [['ds' , 'yhat' , 'yhat_lower' , 'yhat_upper' ]].tail ()
ds
yhat
yhat_lower
yhat_upper
1056
2018-01-23
4.622200
4.560516
4.680854
1057
2018-01-24
4.660621
4.596642
4.721010
1058
2018-01-25
4.662980
4.599900
4.724595
1059
2018-01-26
4.723546
4.664982
4.786545
1060
2018-01-27
4.729829
4.665482
4.793615
% matplotlib inline
m .plot (forecast );
m .plot_components (forecast );
ds
t
trend
seasonal_lower
seasonal_upper
trend_lower
trend_upper
yhat_lower
yhat_upper
weekly
weekly_lower
weekly_upper
yearly
yearly_lower
yearly_upper
seasonal
yhat
0
2015-02-01
0.000000
4.750702
-0.060431
-0.060431
4.750702
4.750702
4.629934
4.746744
-0.037397
-0.037397
-0.037397
-0.023033
-0.023033
-0.023033
-0.060431
4.690271
1
2015-02-02
0.001325
4.750573
-0.079103
-0.079103
4.750573
4.750573
4.614538
4.737126
-0.058506
-0.058506
-0.058506
-0.020598
-0.020598
-0.020598
-0.079103
4.671470
2
2015-02-03
0.002649
4.750445
-0.049399
-0.049399
4.750445
4.750445
4.639142
4.758367
-0.030829
-0.030829
-0.030829
-0.018570
-0.018570
-0.018570
-0.049399
4.701046
3
2015-02-04
0.003974
4.750316
-0.013089
-0.013089
4.750316
4.750316
4.679305
4.796501
0.003878
0.003878
0.003878
-0.016966
-0.016966
-0.016966
-0.013089
4.737227
4
2015-02-05
0.005298
4.750187
-0.013413
-0.013413
4.750187
4.750187
4.678724
4.798790
0.002379
0.002379
0.002379
-0.015792
-0.015792
-0.015792
-0.013413
4.736774
5
2015-02-06
0.006623
4.750058
0.043990
0.043990
4.750058
4.750058
4.734311
4.852198
0.059035
0.059035
0.059035
-0.015045
-0.015045
-0.015045
0.043990
4.794048
6
2015-02-07
0.007947
4.749930
0.046731
0.046731
4.749930
4.749930
4.738959
4.854388
0.061440
0.061440
0.061440
-0.014709
-0.014709
-0.014709
0.046731
4.796661
7
2015-02-08
0.009272
4.749801
-0.052159
-0.052159
4.749801
4.749801
4.637375
4.759022
-0.037397
-0.037397
-0.037397
-0.014762
-0.014762
-0.014762
-0.052159
4.697642
8
2015-02-09
0.010596
4.749672
-0.073678
-0.073678
4.749672
4.749672
4.619588
4.733545
-0.058506
-0.058506
-0.058506
-0.015173
-0.015173
-0.015173
-0.073678
4.675994
9
2015-02-10
0.011921
4.749544
-0.046732
-0.046732
4.749544
4.749544
4.649343
4.766111
-0.030829
-0.030829
-0.030829
-0.015903
-0.015903
-0.015903
-0.046732
4.702812
10
2015-02-11
0.013245
4.749415
-0.013031
-0.013031
4.749415
4.749415
4.678914
4.800226
0.003878
0.003878
0.003878
-0.016909
-0.016909
-0.016909
-0.013031
4.736384
11
2015-02-12
0.014570
4.749286
-0.015762
-0.015762
4.749286
4.749286
4.677391
4.795541
0.002379
0.002379
0.002379
-0.018142
-0.018142
-0.018142
-0.015762
4.733524
12
2015-02-14
0.017219
4.749029
0.040359
0.040359
4.749029
4.749029
4.730550
4.852044
0.061440
0.061440
0.061440
-0.021080
-0.021080
-0.021080
0.040359
4.789388
13
2015-02-15
0.018543
4.748900
-0.060076
-0.060076
4.748900
4.748900
4.631445
4.747374
-0.037397
-0.037397
-0.037397
-0.022679
-0.022679
-0.022679
-0.060076
4.688824
14
2015-02-16
0.019868
4.748771
-0.082797
-0.082797
4.748771
4.748771
4.609208
4.724351
-0.058506
-0.058506
-0.058506
-0.024292
-0.024292
-0.024292
-0.082797
4.665974
15
2015-02-17
0.021192
4.748643
-0.056697
-0.056697
4.748643
4.748643
4.637425
4.753577
-0.030829
-0.030829
-0.030829
-0.025868
-0.025868
-0.025868
-0.056697
4.691946
16
2015-02-18
0.022517
4.748514
-0.023482
-0.023482
4.748514
4.748514
4.667891
4.785552
0.003878
0.003878
0.003878
-0.027360
-0.027360
-0.027360
-0.023482
4.725032
17
2015-02-19
0.023841
4.748385
-0.026343
-0.026343
4.748385
4.748385
4.663674
4.783288
0.002379
0.002379
0.002379
-0.028723
-0.028723
-0.028723
-0.026343
4.722042
18
2015-02-20
0.025166
4.748256
0.029117
0.029117
4.748256
4.748256
4.718172
4.833382
0.059035
0.059035
0.059035
-0.029918
-0.029918
-0.029918
0.029117
4.777373
19
2015-02-21
0.026490
4.748128
0.030528
0.030528
4.748128
4.748128
4.716428
4.836553
0.061440
0.061440
0.061440
-0.030911
-0.030911
-0.030911
0.030528
4.778656
20
2015-02-22
0.027815
4.747999
-0.069074
-0.069074
4.747999
4.747999
4.622780
4.741123
-0.037397
-0.037397
-0.037397
-0.031677
-0.031677
-0.031677
-0.069074
4.678925
21
2015-02-23
0.029139
4.747870
-0.090698
-0.090698
4.747870
4.747870
4.599048
4.717505
-0.058506
-0.058506
-0.058506
-0.032193
-0.032193
-0.032193
-0.090698
4.657172
22
2015-02-24
0.030464
4.747742
-0.063274
-0.063274
4.747742
4.747742
4.624169
4.741186
-0.030829
-0.030829
-0.030829
-0.032446
-0.032446
-0.032446
-0.063274
4.684467
23
2015-02-25
0.031788
4.747613
-0.028551
-0.028551
4.747613
4.747613
4.660959
4.778433
0.003878
0.003878
0.003878
-0.032428
-0.032428
-0.032428
-0.028551
4.719062
24
2015-02-26
0.033113
4.747484
-0.029761
-0.029761
4.747484
4.747484
4.658521
4.776376
0.002379
0.002379
0.002379
-0.032141
-0.032141
-0.032141
-0.029761
4.717723
25
2015-02-27
0.034437
4.747355
0.027447
0.027447
4.747355
4.747355
4.717733
4.832807
0.059035
0.059035
0.059035
-0.031588
-0.031588
-0.031588
0.027447
4.774802
26
2015-02-28
0.035762
4.747227
0.030657
0.030657
4.747227
4.747227
4.718431
4.831581
0.061440
0.061440
0.061440
-0.030783
-0.030783
-0.030783
0.030657
4.777883
27
2015-03-01
0.037086
4.747098
-0.067140
-0.067140
4.747098
4.747098
4.620859
4.731811
-0.037397
-0.037397
-0.037397
-0.029743
-0.029743
-0.029743
-0.067140
4.679958
28
2015-03-02
0.038411
4.746969
-0.086995
-0.086995
4.746969
4.746969
4.604208
4.717865
-0.058506
-0.058506
-0.058506
-0.028489
-0.028489
-0.028489
-0.086995
4.659975
29
2015-03-03
0.039735
4.746841
-0.057877
-0.057877
4.746841
4.746841
4.632128
4.747440
-0.030829
-0.030829
-0.030829
-0.027049
-0.027049
-0.027049
-0.057877
4.688963
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
1031
2017-12-29
1.406623
4.708875
0.108752
0.108752
4.692505
4.724074
4.757283
4.872094
0.059035
0.059035
0.059035
0.049717
0.049717
0.049717
0.108752
4.817627
1032
2017-12-30
1.407947
4.708824
0.101238
0.101238
4.692361
4.724086
4.749039
4.871049
0.061440
0.061440
0.061440
0.039798
0.039798
0.039798
0.101238
4.810062
1033
2017-12-31
1.409272
4.708774
-0.007642
-0.007642
4.692231
4.724099
4.643275
4.755815
-0.037397
-0.037397
-0.037397
0.029755
0.029755
0.029755
-0.007642
4.701132
1034
2018-01-01
1.410596
4.708723
-0.038804
-0.038804
4.692108
4.724111
4.612485
4.731552
-0.058506
-0.058506
-0.058506
0.019701
0.019701
0.019701
-0.038804
4.669919
1035
2018-01-02
1.411921
4.708672
-0.021079
-0.021079
4.691985
4.724164
4.630295
4.748048
-0.030829
-0.030829
-0.030829
0.009750
0.009750
0.009750
-0.021079
4.687594
1036
2018-01-03
1.413245
4.708622
0.003890
0.003890
4.691862
4.724231
4.650104
4.770984
0.003878
0.003878
0.003878
0.000013
0.000013
0.000013
0.003890
4.712512
1037
2018-01-04
1.414570
4.708571
-0.007021
-0.007021
4.691733
4.724298
4.640287
4.762276
0.002379
0.002379
0.002379
-0.009401
-0.009401
-0.009401
-0.007021
4.701550
1038
2018-01-05
1.415894
4.708521
0.040647
0.040647
4.691594
4.724316
4.685780
4.809235
0.059035
0.059035
0.059035
-0.018388
-0.018388
-0.018388
0.040647
4.749167
1039
2018-01-06
1.417219
4.708470
0.034587
0.034587
4.691456
4.724363
4.680212
4.807902
0.061440
0.061440
0.061440
-0.026853
-0.026853
-0.026853
0.034587
4.743057
1040
2018-01-07
1.418543
4.708419
-0.072104
-0.072104
4.691300
4.724504
4.570585
4.694350
-0.037397
-0.037397
-0.037397
-0.034707
-0.034707
-0.034707
-0.072104
4.636315
1041
2018-01-08
1.419868
4.708369
-0.100379
-0.100379
4.691060
4.724599
4.548674
4.668777
-0.058506
-0.058506
-0.058506
-0.041874
-0.041874
-0.041874
-0.100379
4.607990
1042
2018-01-09
1.421192
4.708318
-0.079116
-0.079116
4.690914
4.724616
4.568201
4.686485
-0.030829
-0.030829
-0.030829
-0.048288
-0.048288
-0.048288
-0.079116
4.629202
1043
2018-01-10
1.422517
4.708267
-0.050019
-0.050019
4.690769
4.724632
4.593933
4.718391
0.003878
0.003878
0.003878
-0.053897
-0.053897
-0.053897
-0.050019
4.658248
1044
2018-01-11
1.423841
4.708217
-0.056282
-0.056282
4.690624
4.724639
4.589652
4.714692
0.002379
0.002379
0.002379
-0.058661
-0.058661
-0.058661
-0.056282
4.651935
1045
2018-01-12
1.425166
4.708166
-0.003523
-0.003523
4.690480
4.724698
4.644535
4.763789
0.059035
0.059035
0.059035
-0.062558
-0.062558
-0.062558
-0.003523
4.704643
1046
2018-01-13
1.426490
4.708115
-0.004135
-0.004135
4.690335
4.724751
4.648964
4.764602
0.061440
0.061440
0.061440
-0.065575
-0.065575
-0.065575
-0.004135
4.703980
1047
2018-01-14
1.427815
4.708065
-0.105114
-0.105114
4.690191
4.724744
4.541776
4.662461
-0.037397
-0.037397
-0.037397
-0.067717
-0.067717
-0.067717
-0.105114
4.602950
1048
2018-01-15
1.429139
4.708014
-0.127508
-0.127508
4.690049
4.724757
4.521715
4.641925
-0.058506
-0.058506
-0.058506
-0.069003
-0.069003
-0.069003
-0.127508
4.580506
1049
2018-01-16
1.430464
4.707963
-0.100292
-0.100292
4.689906
4.724819
4.543367
4.669104
-0.030829
-0.030829
-0.030829
-0.069463
-0.069463
-0.069463
-0.100292
4.607671
1050
2018-01-17
1.431788
4.707913
-0.065266
-0.065266
4.689776
4.724880
4.580314
4.701597
0.003878
0.003878
0.003878
-0.069144
-0.069144
-0.069144
-0.065266
4.642647
1051
2018-01-18
1.433113
4.707862
-0.065719
-0.065719
4.689654
4.724942
4.584266
4.704747
0.002379
0.002379
0.002379
-0.068099
-0.068099
-0.068099
-0.065719
4.642143
1052
2018-01-19
1.434437
4.707811
-0.007361
-0.007361
4.689527
4.724997
4.638522
4.761000
0.059035
0.059035
0.059035
-0.066396
-0.066396
-0.066396
-0.007361
4.700451
1053
2018-01-20
1.435762
4.707761
-0.002668
-0.002668
4.689399
4.725050
4.644288
4.768587
0.061440
0.061440
0.061440
-0.064108
-0.064108
-0.064108
-0.002668
4.705093
1054
2018-01-21
1.437086
4.707710
-0.098715
-0.098715
4.689273
4.725102
4.544435
4.663375
-0.037397
-0.037397
-0.037397
-0.061318
-0.061318
-0.061318
-0.098715
4.608995
1055
2018-01-22
1.438411
4.707659
-0.116617
-0.116617
4.689109
4.725159
4.529550
4.651315
-0.058506
-0.058506
-0.058506
-0.058112
-0.058112
-0.058112
-0.116617
4.591042
1056
2018-01-23
1.439735
4.707609
-0.085409
-0.085409
4.688953
4.725204
4.560516
4.680854
-0.030829
-0.030829
-0.030829
-0.054580
-0.054580
-0.054580
-0.085409
4.622200
1057
2018-01-24
1.441060
4.707558
-0.046937
-0.046937
4.688895
4.725207
4.596642
4.721010
0.003878
0.003878
0.003878
-0.050815
-0.050815
-0.050815
-0.046937
4.660621
1058
2018-01-25
1.442384
4.707507
-0.044528
-0.044528
4.688741
4.725172
4.599900
4.724595
0.002379
0.002379
0.002379
-0.046907
-0.046907
-0.046907
-0.044528
4.662980
1059
2018-01-26
1.443709
4.707457
0.016089
0.016089
4.688587
4.725120
4.664982
4.786545
0.059035
0.059035
0.059035
-0.042946
-0.042946
-0.042946
0.016089
4.723546
1060
2018-01-27
1.445033
4.707406
0.022423
0.022423
4.688468
4.725110
4.665482
4.793615
0.061440
0.061440
0.061440
-0.039017
-0.039017
-0.039017
0.022423
4.729829
1061 rows × 17 columns
#Get R-squared to measure model variation
stats .corrcoef (x = txns ['y' ], y = forecast .loc [:724 ,'yhat' ])
array([[ 1. , 0.75356776],
[ 0.75356776, 1. ]])
Additional information to Model
Scratcher Event & Holidays to consider
events_15 = pd .read_csv ('2015_events.csv' , parse_dates = ['ds' ])
events_16 = pd .read_csv ('2016_events.csv' , parse_dates = ['ds' ])
events_17 = pd .read_csv ('2017_events.csv' , parse_dates = ['ds' ])
events_future = pd .read_csv ('2017_events_future.csv' , parse_dates = ['ds' ])
events_future2 = pd .read_csv ('2017_events_future2.csv' , parse_dates = ['ds' ])
past_events = events_15 .append (events_16 )
all_past_events = past_events .append (events_17 )
all_events = all_past_events .append (events_future )
all_events2 = all_past_events .append (events_future2 )
all_events2
ds
holiday
lower_window
upper_window
0
2015-03-11
scratch
0
7
1
2015-04-05
holiday
-2
2
2
2015-06-17
scratch
0
7
3
2015-07-04
holiday
-2
2
4
2015-07-15
scratch
0
7
5
2015-08-12
scratch
0
7
6
2015-10-14
scratch
0
7
7
2015-11-11
scratch
0
7
8
2015-11-26
holiday
-2
2
9
2015-12-02
scratch
0
7
10
2015-12-16
scratch
0
7
11
2015-12-25
holiday
-2
2
12
2016-01-01
holiday
-2
2
0
2016-01-27
scratch
0
7
1
2016-03-16
scratch
0
7
2
2016-03-27
holiday
-2
2
3
2016-04-01
scratch
0
7
4
2016-06-17
scratch
0
7
5
2016-07-04
holiday
-2
2
6
2016-07-15
scratch
0
7
7
2016-08-12
scratch
0
7
8
2016-10-14
scratch
0
7
9
2016-11-09
scratch
0
7
10
2016-11-24
holiday
-2
2
11
2016-12-02
scratch
0
7
12
2016-12-14
scratch
0
7
13
2016-12-25
holiday
-2
2
14
2017-01-01
holiday
-2
2
0
2017-02-01
scratch
0
7
1
2017-03-15
scratch
0
7
2
2017-04-16
holiday
-2
2
0
2017-06-28
scratch
0
7
1
2017-07-04
holiday
-2
2
2
2017-08-09
scratch
0
7
3
2017-10-11
scratch
0
7
4
2017-11-10
scratch
0
7
5
2017-11-23
holiday
-2
2
6
2017-11-29
scratch
0
7
7
2017-12-15
scratch
0
7
8
2017-12-25
holiday
-2
2
#read in dates with Scratcher Event & Holidays listed
dates = pd .read_csv ('changepoint_holiday.csv' ,parse_dates = ['Scratcher Holiday' ,'Ad Changepoint' ,'Year Changepoint' ,'Holidays' ])
#set up different event/holiday dataframes, their 'impact' windows and combine sets
scratch_hol = pd .DataFrame ({
'holiday' :'holiday' ,
'ds' : pd .to_datetime (dates ['Scratcher Holiday' ].dropna ()),
'lower_window' :0 ,
'upper_window' :7 ,
})
reg_hol = pd .DataFrame ({
'holiday' :'holiday' ,
'ds' : pd .to_datetime (dates ['Holidays' ].dropna ()),
'lower_window' :- 2 ,
'upper_window' :2 ,
})
new_dates = pd .DataFrame ({
'ds' :pd .to_datetime ('2017-11-23' ),
'holiday' :'holiday' ,
'lower_window' :- 2 ,
'upper_window' :2 ,},
index = [21 ])
reg_hol = reg_hol .append (new_dates )
holidays = scratch_hol .append (reg_hol )
holidays .sort ( ascending = False )
/home/nbuser/anaconda3_410/lib/python3.5/site-packages/ipykernel/__main__.py:25: FutureWarning: sort(....) is deprecated, use sort_index(.....)
ds
holiday
lower_window
upper_window
21
2017-11-23
holiday
-2
2
20
2017-04-16
holiday
-2
2
20
2017-06-30
holiday
0
7
19
2017-02-01
holiday
0
7
18
2017-03-15
holiday
0
7
17
2015-03-11
holiday
0
7
16
2016-01-27
holiday
0
7
15
2015-06-17
holiday
0
7
14
2015-07-15
holiday
0
7
13
2015-08-12
holiday
0
7
12
2015-10-14
holiday
0
7
12
2017-12-25
holiday
-2
2
11
2015-11-11
holiday
0
7
11
2017-07-04
holiday
-2
2
10
2015-12-02
holiday
0
7
10
2016-07-04
holiday
-2
2
9
2015-12-16
holiday
0
7
9
2015-07-04
holiday
-2
2
8
2016-03-16
holiday
0
7
8
2017-04-16
holiday
-2
2
7
2016-03-27
holiday
-2
2
7
2016-04-01
holiday
0
7
6
2015-04-05
holiday
-2
2
6
2016-06-17
holiday
0
7
5
2017-01-01
holiday
-2
2
5
2016-07-15
holiday
0
7
4
2016-08-12
holiday
0
7
4
2016-01-01
holiday
-2
2
3
2016-10-14
holiday
0
7
3
2016-12-25
holiday
-2
2
2
2015-12-25
holiday
-2
2
2
2016-11-09
holiday
0
7
1
2016-11-24
holiday
-2
2
1
2016-12-02
holiday
0
7
0
2015-11-26
holiday
-2
2
0
2016-12-14
holiday
0
7
#columns = {'ds', 'holiday', 'lower_window', 'upper_window'}
#rows = '2017-08-11', '2017-10-19', '2017-11-10', '2017-12-01','2017-12-15'
future_events = pd .read_csv ('future_events.csv' , parse_dates = ['ds' ])
future_events
#new_holidays = holidays.append(future_events)
#new_holidays
ds
holiday
lower_window
upper_window
0
2017-08-17
scratch
-7
0
1
2017-10-13
scratch
0
2
2
2017-10-15
scratch
0
2
3
2017-11-10
scratch
0
2
4
2017-11-12
scratch
0
2
5
2017-12-01
scratch
0
2
6
2017-12-03
scratch
0
2
7
2017-12-15
scratch
0
2
8
2017-12-17
scratch
0
2
future_events = pd .read_csv ('future_events.csv' , parse_dates = ['ds' ])
future_events
new_holidays = holidays .append (future_events )
new_holidays
ds
holiday
lower_window
upper_window
0
2016-12-14
holiday
0
7
1
2016-12-02
holiday
0
7
2
2016-11-09
holiday
0
7
3
2016-10-14
holiday
0
7
4
2016-08-12
holiday
0
7
5
2016-07-15
holiday
0
7
6
2016-06-17
holiday
0
7
7
2016-04-01
holiday
0
7
8
2016-03-16
holiday
0
7
9
2015-12-16
holiday
0
7
10
2015-12-02
holiday
0
7
11
2015-11-11
holiday
0
7
12
2015-10-14
holiday
0
7
13
2015-08-12
holiday
0
7
14
2015-07-15
holiday
0
7
15
2015-06-17
holiday
0
7
16
2016-01-27
holiday
0
7
17
2015-03-11
holiday
0
7
18
2017-03-15
holiday
0
7
19
2017-02-01
holiday
0
7
20
2017-06-30
holiday
0
7
0
2015-11-26
holiday
-2
2
1
2016-11-24
holiday
-2
2
2
2015-12-25
holiday
-2
2
3
2016-12-25
holiday
-2
2
4
2016-01-01
holiday
-2
2
5
2017-01-01
holiday
-2
2
6
2015-04-05
holiday
-2
2
7
2016-03-27
holiday
-2
2
8
2017-04-16
holiday
-2
2
9
2015-07-04
holiday
-2
2
10
2016-07-04
holiday
-2
2
11
2017-07-04
holiday
-2
2
12
2017-12-25
holiday
-2
2
20
2017-04-16
holiday
-2
2
21
2017-11-23
holiday
-2
2
0
2017-08-11
holiday
0
7
1
2017-10-13
holiday
0
7
2
2017-11-10
holiday
0
7
3
2017-12-01
holiday
0
7
4
2017-12-15
holiday
0
7
Forecast fitted with Events
m1 = Prophet (holidays = all_events2 , holidays_prior_scale = .25 )
forecast3 = m1 .fit (txns ).predict (future )
m1 .plot (forecast3 );
m1 .plot_components (forecast3 );
forecast3 .to_csv ('daily_fcst_all_events2.csv' )
forecast1 .to_csv ('fcst_daily_txns.csv' )
txns .to_csv ('data_daily_txns.csv' )
#Get R-squared to measure model variation
stats .corrcoef (x = txns ['y' ], y = forecast1 .loc [:724 ,'yhat' ])
array([[ 1. , 0.79419461],
[ 0.79419461, 1. ]])
forecast .to_csv ('prophet_txns_fcst.csv' )
forecast1 .to_csv ('prophet_txns_fcst1.csv' )
#m1 = Prophet(holidays=holidays, holidays_prior_scale=.25)
forecast1_sales = m1 .fit (sales ).predict (future )
m1 .plot (forecast1_sales );
m1 .plot_components (forecast1_sales );
week_data = pd .read_csv ('week_data.csv' , parse_dates = ['ds' ])
week_data .describe ()
# Txns
Sales $
count
112.000000
1.120000e+02
mean
387623.285714
2.389304e+07
std
47703.433555
7.113570e+06
min
316991.000000
1.529568e+07
25%
363127.750000
2.034617e+07
50%
375542.500000
2.195671e+07
75%
398826.000000
2.475855e+07
max
596989.000000
5.983885e+07
week_bskt = week_data [['ds' ,'# Txns' ,'Sales $' ]]
week_bskt ['y' ] = week_bskt ['Sales $' ]/ week_bskt ['# Txns' ]
del week_bskt ['Sales $' ]
del week_bskt ['# Txns' ]
week_bskt
ds
y
0
2015-02-07
57.751817
1
2015-02-14
60.899264
2
2015-02-21
57.664583
3
2015-02-28
55.852891
4
2015-03-07
54.192692
5
2015-03-14
64.803281
6
2015-03-21
57.812787
7
2015-03-28
54.876293
8
2015-04-04
56.892848
9
2015-04-11
53.913780
10
2015-04-18
62.923289
11
2015-04-25
54.468337
12
2015-05-02
59.306199
13
2015-05-09
57.665705
14
2015-05-16
58.794291
15
2015-05-23
60.335862
16
2015-05-30
58.668581
17
2015-06-06
54.878416
18
2015-06-13
55.465641
19
2015-06-20
68.071180
20
2015-06-27
59.206520
21
2015-07-04
60.860709
22
2015-07-11
53.035462
23
2015-07-18
63.216453
24
2015-07-25
57.996328
25
2015-08-01
57.856493
26
2015-08-08
56.018111
27
2015-08-15
65.600499
28
2015-08-22
60.899654
29
2015-08-29
59.578032
...
...
...
82
2016-09-03
59.212810
83
2016-09-10
57.188839
84
2016-09-17
59.329563
85
2016-09-24
57.261933
86
2016-10-01
57.601069
87
2016-10-08
55.036670
88
2016-10-15
66.931062
89
2016-10-22
60.764614
90
2016-10-29
54.990041
91
2016-11-05
56.560280
92
2016-11-12
67.657786
93
2016-11-19
63.855139
94
2016-11-26
114.508584
95
2016-12-03
71.827240
96
2016-12-10
67.330459
97
2016-12-17
79.066763
98
2016-12-24
83.362573
99
2016-12-31
55.579885
100
2017-01-07
48.252730
101
2017-01-14
53.295858
102
2017-01-21
52.726923
103
2017-01-28
52.179462
104
2017-02-04
59.964624
105
2017-02-11
55.834854
106
2017-02-18
55.241496
107
2017-02-25
59.876513
108
2017-03-04
56.905613
109
2017-03-11
54.436461
110
2017-03-18
65.855111
111
2017-03-25
59.807701
112 rows × 2 columns
ds
y
0
2015-02-07
57.751817
1
2015-02-14
60.899264
2
2015-02-21
57.664583
3
2015-02-28
55.852891
4
2015-03-07
54.192692
5
2015-03-14
64.803281
6
2015-03-21
57.812787
7
2015-03-28
54.876293
8
2015-04-04
56.892848
9
2015-04-11
53.913780
10
2015-04-18
62.923289
11
2015-04-25
54.468337
12
2015-05-02
59.306199
13
2015-05-09
57.665705
14
2015-05-16
58.794291
15
2015-05-23
60.335862
16
2015-05-30
58.668581
17
2015-06-06
54.878416
18
2015-06-13
55.465641
19
2015-06-20
68.071180
20
2015-06-27
59.206520
21
2015-07-04
60.860709
22
2015-07-11
53.035462
23
2015-07-18
63.216453
24
2015-07-25
57.996328
25
2015-08-01
57.856493
26
2015-08-08
56.018111
27
2015-08-15
65.600499
28
2015-08-22
60.899654
29
2015-08-29
59.578032
...
...
...
82
2016-09-03
59.212810
83
2016-09-10
57.188839
84
2016-09-17
59.329563
85
2016-09-24
57.261933
86
2016-10-01
57.601069
87
2016-10-08
55.036670
88
2016-10-15
66.931062
89
2016-10-22
60.764614
90
2016-10-29
54.990041
91
2016-11-05
56.560280
92
2016-11-12
67.657786
93
2016-11-19
63.855139
94
2016-11-26
114.508584
95
2016-12-03
71.827240
96
2016-12-10
67.330459
97
2016-12-17
79.066763
98
2016-12-24
83.362573
99
2016-12-31
55.579885
100
2017-01-07
48.252730
101
2017-01-14
53.295858
102
2017-01-21
52.726923
103
2017-01-28
52.179462
104
2017-02-04
59.964624
105
2017-02-11
55.834854
106
2017-02-18
55.241496
107
2017-02-25
59.876513
108
2017-03-04
56.905613
109
2017-03-11
54.436461
110
2017-03-18
65.855111
111
2017-03-25
59.807701
112 rows × 2 columns
week_txns = week_data [['ds' ,'# Txns' ]]
week_txns ['y' ] = np .log10 (week_txns ['# Txns' ])
del week_txns ['# Txns' ]
week_txns
ds
y
0
2015-02-07
5.564134
1
2015-02-14
5.638412
2
2015-02-21
5.546383
3
2015-02-28
5.567790
4
2015-03-07
5.562261
5
2015-03-14
5.620316
6
2015-03-21
5.599127
7
2015-03-28
5.572017
8
2015-04-04
5.613450
9
2015-04-11
5.558992
10
2015-04-18
5.608362
11
2015-04-25
5.553200
12
2015-05-02
5.589702
13
2015-05-09
5.627017
14
2015-05-16
5.587549
15
2015-05-23
5.606119
16
2015-05-30
5.573017
17
2015-06-06
5.578356
18
2015-06-13
5.571408
19
2015-06-20
5.617928
20
2015-06-27
5.563689
21
2015-07-04
5.584313
22
2015-07-11
5.532271
23
2015-07-18
5.588061
24
2015-07-25
5.572168
25
2015-08-01
5.569219
26
2015-08-08
5.560179
27
2015-08-15
5.602297
28
2015-08-22
5.582600
29
2015-08-29
5.570953
...
...
...
82
2016-09-03
5.597165
83
2016-09-10
5.544601
84
2016-09-17
5.563593
85
2016-09-24
5.526773
86
2016-10-01
5.560285
87
2016-10-08
5.531421
88
2016-10-15
5.569895
89
2016-10-22
5.569209
90
2016-10-29
5.542246
91
2016-11-05
5.555896
92
2016-11-12
5.576098
93
2016-11-19
5.625310
94
2016-11-26
5.693046
95
2016-12-03
5.668736
96
2016-12-10
5.674914
97
2016-12-17
5.728724
98
2016-12-24
5.775966
99
2016-12-31
5.570002
100
2017-01-07
5.501047
101
2017-01-14
5.533947
102
2017-01-21
5.508561
103
2017-01-28
5.517200
104
2017-02-04
5.563805
105
2017-02-11
5.538898
106
2017-02-18
5.584438
107
2017-02-25
5.549615
108
2017-03-04
5.549207
109
2017-03-11
5.532900
110
2017-03-18
5.580826
111
2017-03-25
5.564596
112 rows × 2 columns
week_txns .to_csv ('week_txns.csv' )
m_week = Prophet (holidays = new_holidays , changepoints = ['2016-01-30' ,'2017-02-04' ],changepoint_prior_scale = .25 , holidays_prior_scale = .25 )
m_week .fit (week_txns )
future_week = m_week .make_future_dataframe (periods = 44 , freq = 'W-SAT' )
fcst_week = m_week .predict (future_week )
m_week .plot (fcst_week );
#m_week.plot_components(fcst_week);
fcst_week .to_csv ('fcst_week.csv' )
ds
t
trend
seasonal_lower
seasonal_upper
trend_lower
trend_upper
yhat_lower
yhat_upper
holiday
holiday_lower
holiday_upper
weekly
weekly_lower
weekly_upper
yearly
yearly_lower
yearly_upper
seasonal
yhat
0
2015-02-07
0.000000
5.550714
0.022272
0.022272
5.550714
5.550714
5.547346
5.602319
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.012477
-0.012477
-0.012477
0.022272
5.572986
1
2015-02-14
0.009009
5.550632
0.025131
0.025131
5.550632
5.550632
5.548403
5.602419
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.009617
-0.009617
-0.009617
0.025131
5.575763
2
2015-02-21
0.018018
5.550550
0.020610
0.020610
5.550550
5.550550
5.544827
5.596707
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.014138
-0.014138
-0.014138
0.020610
5.571160
3
2015-02-28
0.027027
5.550468
0.015380
0.015380
5.550468
5.550468
5.536733
5.593043
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.019369
-0.019369
-0.019369
0.015380
5.565848
4
2015-03-07
0.036036
5.550386
0.013072
0.013072
5.550386
5.550386
5.534867
5.591884
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.021677
-0.021677
-0.021677
0.013072
5.563457
5
2015-03-14
0.045045
5.550304
0.037759
0.037759
5.550304
5.550304
5.559119
5.615523
0.022564
0.022564
0.022564
0.034748
0.034748
0.034748
-0.019554
-0.019554
-0.019554
0.037759
5.588062
6
2015-03-21
0.054054
5.550221
0.021369
0.021369
5.550221
5.550221
5.545527
5.600468
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.013379
-0.013379
-0.013379
0.021369
5.571591
7
2015-03-28
0.063063
5.550139
0.028211
0.028211
5.550139
5.550139
5.552033
5.605434
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.006537
-0.006537
-0.006537
0.028211
5.578350
8
2015-04-04
0.072072
5.550057
0.059433
0.059433
5.550057
5.550057
5.583734
5.636675
0.028293
0.028293
0.028293
0.034748
0.034748
0.034748
-0.003609
-0.003609
-0.003609
0.059433
5.609490
9
2015-04-11
0.081081
5.549975
0.029656
0.029656
5.549975
5.549975
5.552579
5.606949
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.005093
-0.005093
-0.005093
0.029656
5.579631
10
2015-04-18
0.090090
5.549893
0.029618
0.029618
5.549893
5.549893
5.552197
5.606802
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.005131
-0.005131
-0.005131
0.029618
5.579511
11
2015-04-25
0.099099
5.549811
0.037481
0.037481
5.549811
5.549811
5.561058
5.616367
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.002732
0.002732
0.002732
0.037481
5.587292
12
2015-05-02
0.108108
5.549729
0.051648
0.051648
5.549729
5.549729
5.575196
5.627618
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.016899
0.016899
0.016899
0.051648
5.601376
13
2015-05-09
0.117117
5.549647
0.061801
0.061801
5.549647
5.549647
5.583488
5.637936
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.027053
0.027053
0.027053
0.061801
5.611448
14
2015-05-16
0.126126
5.549565
0.058984
0.058984
5.549565
5.549565
5.581563
5.635521
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.024236
0.024236
0.024236
0.058984
5.608549
15
2015-05-23
0.135135
5.549482
0.045775
0.045775
5.549482
5.549482
5.568837
5.622621
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.011027
0.011027
0.011027
0.045775
5.595258
16
2015-05-30
0.144144
5.549400
0.034229
0.034229
5.549400
5.549400
5.554700
5.611318
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.000519
-0.000519
-0.000519
0.034229
5.583630
17
2015-06-06
0.153153
5.549318
0.033000
0.033000
5.549318
5.549318
5.553562
5.610073
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.001748
-0.001748
-0.001748
0.033000
5.582318
18
2015-06-13
0.162162
5.549236
0.038213
0.038213
5.549236
5.549236
5.560328
5.615115
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.003464
0.003464
0.003464
0.038213
5.587449
19
2015-06-20
0.171171
5.549154
0.061317
0.061317
5.549154
5.549154
5.583404
5.636378
0.022564
0.022564
0.022564
0.034748
0.034748
0.034748
0.004004
0.004004
0.004004
0.061317
5.610471
20
2015-06-27
0.180180
5.549072
0.029693
0.029693
5.549072
5.549072
5.551153
5.606128
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.005056
-0.005056
-0.005056
0.029693
5.578764
21
2015-07-04
0.189189
5.548990
0.031744
0.031744
5.548990
5.548990
5.553790
5.607454
0.013767
0.013767
0.013767
0.034748
0.034748
0.034748
-0.016771
-0.016771
-0.016771
0.031744
5.580734
22
2015-07-11
0.198198
5.548908
0.014009
0.014009
5.548908
5.548908
5.533310
5.590121
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.020740
-0.020740
-0.020740
0.014009
5.562916
23
2015-07-18
0.207207
5.548825
0.042311
0.042311
5.548825
5.548825
5.563782
5.619592
0.022564
0.022564
0.022564
0.034748
0.034748
0.034748
-0.015002
-0.015002
-0.015002
0.042311
5.591136
24
2015-07-25
0.216216
5.548743
0.027551
0.027551
5.548743
5.548743
5.548741
5.603111
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.007198
-0.007198
-0.007198
0.027551
5.576294
25
2015-08-01
0.225225
5.548661
0.030252
0.030252
5.548661
5.548661
5.551049
5.605165
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.004497
-0.004497
-0.004497
0.030252
5.578913
26
2015-08-08
0.234234
5.548579
0.029247
0.029247
5.548579
5.548579
5.549797
5.606171
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.005502
-0.005502
-0.005502
0.029247
5.577826
27
2015-08-15
0.243243
5.548497
0.053315
0.053315
5.548497
5.548497
5.575350
5.629704
0.022564
0.022564
0.022564
0.034748
0.034748
0.034748
-0.003997
-0.003997
-0.003997
0.053315
5.601812
28
2015-08-22
0.252252
5.548415
0.035880
0.035880
5.548415
5.548415
5.557566
5.610936
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.001132
0.001132
0.001132
0.035880
5.584295
29
2015-08-29
0.261261
5.548333
0.037962
0.037962
5.548333
5.548333
5.558949
5.614455
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.003214
0.003214
0.003214
0.037962
5.586295
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
126
2017-07-08
1.135135
5.531225
0.014153
0.014153
5.531189
5.531225
5.517719
5.572352
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.020595
-0.020595
-0.020595
0.014153
5.545378
127
2017-07-15
1.144144
5.531021
0.016946
0.016946
5.530965
5.531021
5.520654
5.575053
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.017802
-0.017802
-0.017802
0.016946
5.547967
128
2017-07-22
1.153153
5.530817
0.025123
0.025123
5.530733
5.530830
5.527898
5.582792
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.009625
-0.009625
-0.009625
0.025123
5.555939
129
2017-07-29
1.162162
5.530613
0.029981
0.029981
5.530510
5.530650
5.533979
5.588919
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.004768
-0.004768
-0.004768
0.029981
5.560593
130
2017-08-05
1.171171
5.530408
0.029626
0.029626
5.530280
5.530466
5.532369
5.586185
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.005122
-0.005122
-0.005122
0.029626
5.560034
131
2017-08-12
1.180180
5.530204
0.055365
0.055365
5.530051
5.530290
5.558192
5.613456
0.025705
0.025705
0.025705
0.034748
0.034748
0.034748
-0.005089
-0.005089
-0.005089
0.055365
5.585569
132
2017-08-19
1.189189
5.530000
0.033945
0.033945
5.529821
5.530128
5.536884
5.591282
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.000804
-0.000804
-0.000804
0.033945
5.563945
133
2017-08-26
1.198198
5.529796
0.038098
0.038098
5.529588
5.529965
5.539165
5.595154
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.003350
0.003350
0.003350
0.038098
5.567895
134
2017-09-02
1.207207
5.529592
0.034461
0.034461
5.529348
5.529788
5.537397
5.591977
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.000287
-0.000287
-0.000287
0.034461
5.564053
135
2017-09-09
1.216216
5.529388
0.022198
0.022198
5.529072
5.529622
5.524708
5.579176
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.012550
-0.012550
-0.012550
0.022198
5.551586
136
2017-09-16
1.225225
5.529184
0.009439
0.009439
5.528827
5.529481
5.509105
5.564325
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.025309
-0.025309
-0.025309
0.009439
5.538624
137
2017-09-23
1.234234
5.528980
0.004531
0.004531
5.528579
5.529348
5.505361
5.560463
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.030218
-0.030218
-0.030218
0.004531
5.533511
138
2017-09-30
1.243243
5.528776
0.007305
0.007305
5.528346
5.529180
5.507304
5.562332
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.027444
-0.027444
-0.027444
0.007305
5.536081
139
2017-10-07
1.252252
5.528572
0.010963
0.010963
5.528111
5.529007
5.511260
5.567053
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.023785
-0.023785
-0.023785
0.010963
5.539535
140
2017-10-14
1.261261
5.528368
0.037072
0.037072
5.527878
5.528861
5.536179
5.590811
0.025705
0.025705
0.025705
0.034748
0.034748
0.034748
-0.023382
-0.023382
-0.023382
0.037072
5.565440
141
2017-10-21
1.270270
5.528164
0.011433
0.011433
5.527615
5.528707
5.511572
5.566162
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.023315
-0.023315
-0.023315
0.011433
5.539598
142
2017-10-28
1.279279
5.527960
0.015669
0.015669
5.527335
5.528554
5.516570
5.570857
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.019079
-0.019079
-0.019079
0.015669
5.543629
143
2017-11-04
1.288288
5.527756
0.023588
0.023588
5.527046
5.528426
5.525306
5.577934
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.011161
-0.011161
-0.011161
0.023588
5.551344
144
2017-11-11
1.297297
5.527552
0.057902
0.057902
5.526761
5.528291
5.558400
5.611796
0.025705
0.025705
0.025705
0.034748
0.034748
0.034748
-0.002552
-0.002552
-0.002552
0.057902
5.585454
145
2017-11-18
1.306306
5.527348
0.044324
0.044324
5.526522
5.528191
5.543959
5.598125
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.009576
0.009576
0.009576
0.044324
5.571672
146
2017-11-25
1.315315
5.527144
0.143716
0.143716
5.526262
5.528090
5.643038
5.699013
0.074386
0.074386
0.074386
0.034748
0.034748
0.034748
0.034582
0.034582
0.034582
0.143716
5.670860
147
2017-12-02
1.324324
5.526940
0.136539
0.136539
5.526010
5.527945
5.636818
5.691185
0.025705
0.025705
0.025705
0.034748
0.034748
0.034748
0.076086
0.076086
0.076086
0.136539
5.663479
148
2017-12-09
1.333333
5.526736
0.154170
0.154170
5.525773
5.527800
5.652723
5.708267
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.119422
0.119422
0.119422
0.154170
5.680906
149
2017-12-16
1.342342
5.526532
0.196849
0.196849
5.525507
5.527647
5.697632
5.750509
0.025705
0.025705
0.025705
0.034748
0.034748
0.034748
0.136396
0.136396
0.136396
0.196849
5.723381
150
2017-12-23
1.351351
5.526328
0.203197
0.203197
5.525218
5.527499
5.700713
5.756401
0.060733
0.060733
0.060733
0.034748
0.034748
0.034748
0.107715
0.107715
0.107715
0.203197
5.729525
151
2017-12-30
1.360360
5.526124
0.077227
0.077227
5.524898
5.527342
5.575491
5.630344
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
0.042479
0.042479
0.042479
0.077227
5.603351
152
2018-01-06
1.369369
5.525920
0.008948
0.008948
5.524630
5.527201
5.507735
5.562164
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.025800
-0.025800
-0.025800
0.008948
5.534868
153
2018-01-13
1.378378
5.525716
-0.029610
-0.029610
5.524361
5.527062
5.468948
5.522439
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.064358
-0.064358
-0.064358
-0.029610
5.496106
154
2018-01-20
1.387387
5.525512
-0.029530
-0.029530
5.524081
5.526952
5.469103
5.521989
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.064278
-0.064278
-0.064278
-0.029530
5.495982
155
2018-01-27
1.396396
5.525308
-0.006863
-0.006863
5.523752
5.526792
5.491214
5.546574
0.000000
0.000000
0.000000
0.034748
0.034748
0.034748
-0.041611
-0.041611
-0.041611
-0.006863
5.518445
156 rows × 20 columns
#Get R-squared to measure model variation
stats .corrcoef (x = week_txns ['y' ], y = fcst_week .loc [:111 ,'yhat' ])
week_sales = week_data [['ds' ,'Sales $' ]]
week_sales ['y' ] = np .log10 (week_sales ['Sales $' ])
del week_sales ['Sales $' ]
week_sales
m_bskt = Prophet (holidays = all_events )
m_bskt .fit (week_bskt )
fcst_week_bskt = m_bskt .predict (future_week )
m_bskt .plot (fcst_week_bskt );
fcst_week_bskt .to_csv ('fcst_week_bskt_all_events.csv' )
m_week .plot_components (fcst_week_sales );
#m_week.yearly_seasonality(fcst_week_sales)
m_week .plot_components (fcst_week_sales );
fcst_week
fcst_week .to_csv ('fcst_week_sales.csv' )
week_sales .to_csv ('data_week_sales.csv' )
#Get R-squared to measure model variation
stats .corrcoef (x = week_txns ['y' ], y = fcst_week .loc [:111 ,'yhat' ])
m_week .fit (week_bskt )
fcst_week_bskt = m_week .predict (future_week )
m_week .plot (fcst_week_bskt );
fcst_week_bskt .to_csv ('fcst_week_bskt.csv' )
mg1_data = pd .read_csv ('mg1_week_data.csv' , parse_dates = ['ds' ])
mg2_data = pd .read_csv ('mg2_week_data.csv' , parse_dates = ['ds' ])
mg3_data = pd .read_csv ('mg3_week_data.csv' , parse_dates = ['ds' ])
#mg1_data.info()
#mg2_data.describe()
mg3_data .describe ()
#mg1 = pd.DataFrame(mg1_data[['ds','Txns']])
#mg1['y'] = np.log10(mg1['Txns'])
#del mg1['Txns']
#mg1.drop(mg1.index[-1],inplace= True)
mg1
#mg2 = pd.DataFrame(mg2_data[['ds','Txns']])
#mg2['y'] = np.log10(mg2['Txns'])
#del mg2['Txns']
#mg2.drop(mg2.index[-1],inplace= True)
mg2
#mg3 = pd.DataFrame(mg3_data[['ds','Txns']])
#mg3['y'] = np.log10(mg3['Txns'])
#del mg3['Txns']
#mg3.drop(mg3.index[-1],inplace= True)
mg3
m_week .fit (mg1 )
fcst_mg1_txns = m_week .predict (future_week )
fcst_mg1_txns
m_week .plot (fcst_mg1_txns );
m_week .plot_components (fcst_mg1_txns );
m_week .fit (mg2 )
fcst_mg2_txns = m_week .predict (future_week )
fcst_mg2_txns
m_week .plot (fcst_mg2_txns );
m_week .plot_components (fcst_mg2_txns );
m_week .fit (mg3 )
fcst_mg3_txns = m_week .predict (future_week )
fcst_mg3_txns
m_week .plot (fcst_mg3_txns );
m_week .plot_components (fcst_mg3_txns );