Sagar Thacker commited on
Commit
22fca73
·
1 Parent(s): 6d3145a

adding files

Browse files
Files changed (7) hide show
  1. Pipfile +17 -0
  2. Pipfile.lock +0 -0
  3. app.py +122 -0
  4. data/data_daily.csv +366 -0
  5. model.py +31 -0
  6. models/damped_hw_model.pkl +3 -0
  7. models/hw_model.pkl +3 -0
Pipfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [[source]]
2
+ url = "https://pypi.org/simple"
3
+ verify_ssl = true
4
+ name = "pypi"
5
+
6
+ [packages]
7
+ statsmodels = "*"
8
+ pandas = "*"
9
+ numpy = "*"
10
+ matplotlib = "*"
11
+ gradio = "*"
12
+ zipp = "*"
13
+
14
+ [dev-packages]
15
+
16
+ [requires]
17
+ python_version = "3.9"
Pipfile.lock ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+
6
+ from statsmodels.tsa.holtwinters import ExponentialSmoothing
7
+ from model import PredictionModel
8
+
9
+ data_path = './data/data_daily.csv'
10
+ damped_model_path = './models/damped_hw_model.pkl'
11
+ model_path = './models/hw_model.pkl'
12
+
13
+ months = {1: [31, "2022-01-31"], 2: [59, "2022-02-28"], 3: [90, "2022-03-31"], 4: [120, "2022-04-30"], 5: [151, "2022-05-31"], 6: [181, "2022-06-30"], 7: [212, "2022-07-31"], 8: [243, "2022-08-31"], 9: [273, "2022-09-30"], 10: [304, "2022-010-31"], 11: [334, "2022-11-30"], 12: [365, "2022-12-31"]}
14
+
15
+ damped_model = PredictionModel(damped_model_path, data_path)
16
+ model = PredictionModel(model_path, data_path)
17
+
18
+ def plot_daily_chart(result, month):
19
+ fig, axes = plt.subplots(2,2, figsize=(15,15))
20
+
21
+ axes[0][0].plot(result.ds, result.y, label='Train')
22
+ axes[0][0].plot(result.ds, result.yhat, label='yhat')
23
+ axes[0][0].plot(result.ds, result.upper_bound, label='Upper Bound')
24
+ axes[0][0].plot(result.ds, result.lower_bound, label='Lower Bound')
25
+ axes[0][0].set_xticklabels(result.ds.dt.date, rotation=45)
26
+ axes[0][0].legend(loc='best')
27
+ axes[0][0].set_title("Daily Forecast")
28
+ axes[0][0].set_xlabel("Date")
29
+ axes[0][0].set_ylabel("Receipt Count")
30
+ axes[0][0].grid(True)
31
+
32
+ monthly_result = result.drop('ds', axis=1).groupby(['year', 'month']).sum().reset_index()
33
+ monthly_result['monthly'] = monthly_result['year'].astype(str) + '-' + monthly_result['month'].astype(str)
34
+ monthly_result['y'].iloc[-int(month):] = np.nan
35
+ monthly_result['yhat'].iloc[:12] = np.nan
36
+ monthly_result['upper_bound'].iloc[:12] = np.nan
37
+ monthly_result['lower_bound'].iloc[:12] = np.nan
38
+
39
+ axes[1][0].plot(monthly_result.monthly, monthly_result.y, label='Train')
40
+ axes[1][0].plot(monthly_result.monthly, monthly_result.yhat, label='yhat')
41
+ axes[1][0].plot(monthly_result.monthly, monthly_result.upper_bound, label='Upper Bound')
42
+ axes[1][0].plot(monthly_result.monthly, monthly_result.lower_bound, label='Lower Bound')
43
+ axes[1][0].set_xticklabels(monthly_result.monthly, rotation=45)
44
+ axes[1][0].legend(loc='best')
45
+ axes[1][0].set_title("Monthly Forecast")
46
+ axes[1][0].set_xlabel("Date")
47
+ axes[1][0].set_ylabel("Receipt Count")
48
+ axes[1][0].grid(True)
49
+
50
+ axes[0][1].plot(result.ds, result.y, label='Train')
51
+ axes[0][1].plot(result.ds, result.damped_yhat, label='yhat')
52
+ axes[0][1].plot(result.ds, result.damped_upper_bound, label='Upper Bound')
53
+ axes[0][1].plot(result.ds, result.damped_lower_bound, label='Lower Bound')
54
+ axes[0][1].set_xticklabels(result.ds.dt.date, rotation=45)
55
+ axes[0][1].legend(loc='best')
56
+ axes[0][1].set_title("Damped Model - Daily Forecast")
57
+ axes[0][1].set_xlabel("Date")
58
+ axes[0][1].set_ylabel("Receipt Count")
59
+ axes[0][1].grid(True)
60
+
61
+ monthly_result['damped_yhat'].iloc[:12] = np.nan
62
+ monthly_result['damped_upper_bound'].iloc[:12] = np.nan
63
+ monthly_result['damped_lower_bound'].iloc[:12] = np.nan
64
+
65
+ axes[1][1].plot(monthly_result.monthly, monthly_result.y, label='Train')
66
+ axes[1][1].plot(monthly_result.monthly, monthly_result.damped_yhat, label='yhat')
67
+ axes[1][1].plot(monthly_result.monthly, monthly_result.damped_upper_bound, label='Upper Bound')
68
+ axes[1][1].plot(monthly_result.monthly, monthly_result.damped_lower_bound, label='Lower Bound')
69
+ axes[1][1].set_xticklabels(monthly_result.monthly, rotation=45)
70
+ axes[1][1].legend(loc='best')
71
+ axes[1][1].set_title("Damped Model - Monthly Forecast")
72
+ axes[1][1].set_xlabel("Date")
73
+ axes[1][1].set_ylabel("Receipt Count")
74
+ axes[1][1].grid(True)
75
+
76
+ fig.tight_layout()
77
+
78
+ return fig
79
+
80
+
81
+ def cal_result(alpha, month):
82
+ alpha = float(alpha)
83
+ period = months[int(month)][0]
84
+ train_data_len = model.df.shape[0]
85
+ yhat, intervals = model.predict(period, alpha)
86
+ damped_yhat, damped_intervals = damped_model.predict(period, alpha)
87
+
88
+ START = "2021-01-01"
89
+ END = months[int(month)][1]
90
+
91
+ result = pd.DataFrame({
92
+ 'ds': pd.date_range(START, END, freq='D'),
93
+ 'y': list(model.df.receipt_count.values) + [np.nan] * period,
94
+ 'yhat': [np.nan] * train_data_len + list(yhat),
95
+ 'upper_bound': [np.nan] * train_data_len + list(intervals[1]),
96
+ 'lower_bound': [np.nan] * train_data_len + list(intervals[0]),
97
+ 'damped_yhat': [np.nan] * train_data_len + list(damped_yhat),
98
+ 'damped_upper_bound': [np.nan] * train_data_len + list(damped_intervals[1]),
99
+ 'damped_lower_bound': [np.nan] * train_data_len + list(damped_intervals[0])
100
+ })
101
+
102
+ result['year'] = result.ds.dt.year
103
+ result['month'] = result.ds.dt.month
104
+
105
+ daily_chart = plot_daily_chart(result, month)
106
+
107
+ return daily_chart
108
+
109
+
110
+ with gr.Blocks() as demo:
111
+ with gr.Row():
112
+ alpha = gr.Dropdown(choices=["0.1", "0.05", "0.01"], label="Significance level", info="The significance level for the confidence intervals.", value="0.05", name="alpha")
113
+ month = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"], label="Forecast period", info="The number of months to forecast.", value="12", name="period")
114
+
115
+ submit = gr.Button(text="Submit", label="Submit", type="submit")
116
+
117
+ daily = gr.Plot()
118
+
119
+ submit.click(fn=cal_result, inputs=[alpha, month], outputs=daily)
120
+
121
+
122
+ demo.launch()
data/data_daily.csv ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Date,Receipt_Count
2
+ 2021-01-01,7564766
3
+ 2021-01-02,7455524
4
+ 2021-01-03,7095414
5
+ 2021-01-04,7666163
6
+ 2021-01-05,7771289
7
+ 2021-01-06,7473320
8
+ 2021-01-07,7832624
9
+ 2021-01-08,7765028
10
+ 2021-01-09,7385245
11
+ 2021-01-10,7392087
12
+ 2021-01-11,7738899
13
+ 2021-01-12,7840830
14
+ 2021-01-13,8122546
15
+ 2021-01-14,7694195
16
+ 2021-01-15,7200595
17
+ 2021-01-16,7744470
18
+ 2021-01-17,7610648
19
+ 2021-01-18,7880913
20
+ 2021-01-19,7250032
21
+ 2021-01-20,7666397
22
+ 2021-01-21,7742477
23
+ 2021-01-22,7807438
24
+ 2021-01-23,7603625
25
+ 2021-01-24,7572947
26
+ 2021-01-25,7598153
27
+ 2021-01-26,7194687
28
+ 2021-01-27,7787109
29
+ 2021-01-28,7631075
30
+ 2021-01-29,7750536
31
+ 2021-01-30,8059526
32
+ 2021-01-31,7838129
33
+ 2021-02-01,7714465
34
+ 2021-02-02,7766408
35
+ 2021-02-03,7832259
36
+ 2021-02-04,7506461
37
+ 2021-02-05,7816477
38
+ 2021-02-06,7360372
39
+ 2021-02-07,8039414
40
+ 2021-02-08,7858632
41
+ 2021-02-09,7810951
42
+ 2021-02-10,7579882
43
+ 2021-02-11,8127696
44
+ 2021-02-12,7748085
45
+ 2021-02-13,8117805
46
+ 2021-02-14,7780006
47
+ 2021-02-15,7916028
48
+ 2021-02-16,7736671
49
+ 2021-02-17,8082781
50
+ 2021-02-18,7824063
51
+ 2021-02-19,7761256
52
+ 2021-02-20,7821879
53
+ 2021-02-21,7760399
54
+ 2021-02-22,8330147
55
+ 2021-02-23,8053953
56
+ 2021-02-24,7816117
57
+ 2021-02-25,8156649
58
+ 2021-02-26,7857443
59
+ 2021-02-27,7881212
60
+ 2021-02-28,7975949
61
+ 2021-03-01,7970632
62
+ 2021-03-02,7998865
63
+ 2021-03-03,7748662
64
+ 2021-03-04,8080043
65
+ 2021-03-05,7971011
66
+ 2021-03-06,8309959
67
+ 2021-03-07,7945271
68
+ 2021-03-08,8352635
69
+ 2021-03-09,7861647
70
+ 2021-03-10,7920726
71
+ 2021-03-11,7921232
72
+ 2021-03-12,8142874
73
+ 2021-03-13,7731725
74
+ 2021-03-14,8070687
75
+ 2021-03-15,7825047
76
+ 2021-03-16,7920469
77
+ 2021-03-17,7946897
78
+ 2021-03-18,8090998
79
+ 2021-03-19,8415152
80
+ 2021-03-20,8325436
81
+ 2021-03-21,8105278
82
+ 2021-03-22,7562433
83
+ 2021-03-23,8096085
84
+ 2021-03-24,8034268
85
+ 2021-03-25,8050876
86
+ 2021-03-26,8077321
87
+ 2021-03-27,7999117
88
+ 2021-03-28,8082481
89
+ 2021-03-29,8126444
90
+ 2021-03-30,7911341
91
+ 2021-03-31,8013013
92
+ 2021-04-01,8353242
93
+ 2021-04-02,8042185
94
+ 2021-04-03,8401675
95
+ 2021-04-04,8134408
96
+ 2021-04-05,8422480
97
+ 2021-04-06,8140096
98
+ 2021-04-07,8385138
99
+ 2021-04-08,8619576
100
+ 2021-04-09,7961949
101
+ 2021-04-10,8388608
102
+ 2021-04-11,8458290
103
+ 2021-04-12,8206730
104
+ 2021-04-13,8319338
105
+ 2021-04-14,8726486
106
+ 2021-04-15,8342572
107
+ 2021-04-16,8438884
108
+ 2021-04-17,8186918
109
+ 2021-04-18,8195134
110
+ 2021-04-19,8366630
111
+ 2021-04-20,8282495
112
+ 2021-04-21,8641338
113
+ 2021-04-22,8521710
114
+ 2021-04-23,8255078
115
+ 2021-04-24,8221890
116
+ 2021-04-25,8509398
117
+ 2021-04-26,8055670
118
+ 2021-04-27,8266410
119
+ 2021-04-28,8367438
120
+ 2021-04-29,8704248
121
+ 2021-04-30,8728816
122
+ 2021-05-01,8231674
123
+ 2021-05-02,8278534
124
+ 2021-05-03,8727522
125
+ 2021-05-04,8649710
126
+ 2021-05-05,8519563
127
+ 2021-05-06,8435867
128
+ 2021-05-07,8227322
129
+ 2021-05-08,8383810
130
+ 2021-05-09,8109287
131
+ 2021-05-10,8518147
132
+ 2021-05-11,8472640
133
+ 2021-05-12,8359580
134
+ 2021-05-13,8262562
135
+ 2021-05-14,8503389
136
+ 2021-05-15,8498352
137
+ 2021-05-16,9066670
138
+ 2021-05-17,8744235
139
+ 2021-05-18,8688343
140
+ 2021-05-19,8475700
141
+ 2021-05-20,8471826
142
+ 2021-05-21,9020316
143
+ 2021-05-22,8399861
144
+ 2021-05-23,8387758
145
+ 2021-05-24,8637948
146
+ 2021-05-25,8088783
147
+ 2021-05-26,8148275
148
+ 2021-05-27,8682340
149
+ 2021-05-28,8879871
150
+ 2021-05-29,8680501
151
+ 2021-05-30,8083372
152
+ 2021-05-31,8517990
153
+ 2021-06-01,8491801
154
+ 2021-06-02,9031534
155
+ 2021-06-03,8319351
156
+ 2021-06-04,8553246
157
+ 2021-06-05,8534097
158
+ 2021-06-06,8462584
159
+ 2021-06-07,8691699
160
+ 2021-06-08,8686964
161
+ 2021-06-09,8550358
162
+ 2021-06-10,8143101
163
+ 2021-06-11,8645316
164
+ 2021-06-12,8928652
165
+ 2021-06-13,9082265
166
+ 2021-06-14,8796515
167
+ 2021-06-15,8629607
168
+ 2021-06-16,8827278
169
+ 2021-06-17,8946278
170
+ 2021-06-18,8390857
171
+ 2021-06-19,8782778
172
+ 2021-06-20,8817338
173
+ 2021-06-21,8543719
174
+ 2021-06-22,8590990
175
+ 2021-06-23,8774391
176
+ 2021-06-24,8913737
177
+ 2021-06-25,8665876
178
+ 2021-06-26,8707038
179
+ 2021-06-27,8869334
180
+ 2021-06-28,9186579
181
+ 2021-06-29,8372464
182
+ 2021-06-30,8721093
183
+ 2021-07-01,8704509
184
+ 2021-07-02,8939614
185
+ 2021-07-03,9267015
186
+ 2021-07-04,8544557
187
+ 2021-07-05,8735065
188
+ 2021-07-06,8326629
189
+ 2021-07-07,8831147
190
+ 2021-07-08,8857992
191
+ 2021-07-09,9160117
192
+ 2021-07-10,8672036
193
+ 2021-07-11,8670423
194
+ 2021-07-12,8869283
195
+ 2021-07-13,8686309
196
+ 2021-07-14,8654144
197
+ 2021-07-15,8860853
198
+ 2021-07-16,9198488
199
+ 2021-07-17,8960260
200
+ 2021-07-18,9122667
201
+ 2021-07-19,9138658
202
+ 2021-07-20,8987305
203
+ 2021-07-21,8899455
204
+ 2021-07-22,9017914
205
+ 2021-07-23,8480182
206
+ 2021-07-24,8603099
207
+ 2021-07-25,8636410
208
+ 2021-07-26,8996817
209
+ 2021-07-27,9024807
210
+ 2021-07-28,9329236
211
+ 2021-07-29,8979426
212
+ 2021-07-30,8909272
213
+ 2021-07-31,8712314
214
+ 2021-08-01,8861903
215
+ 2021-08-02,8913143
216
+ 2021-08-03,9223398
217
+ 2021-08-04,9410437
218
+ 2021-08-05,9212329
219
+ 2021-08-06,9062121
220
+ 2021-08-07,9432522
221
+ 2021-08-08,9111057
222
+ 2021-08-09,8971236
223
+ 2021-08-10,8799249
224
+ 2021-08-11,9127038
225
+ 2021-08-12,9362940
226
+ 2021-08-13,9077857
227
+ 2021-08-14,9413465
228
+ 2021-08-15,8950079
229
+ 2021-08-16,9215173
230
+ 2021-08-17,9056307
231
+ 2021-08-18,8968187
232
+ 2021-08-19,9357610
233
+ 2021-08-20,8971426
234
+ 2021-08-21,9238276
235
+ 2021-08-22,9372279
236
+ 2021-08-23,9589375
237
+ 2021-08-24,8961875
238
+ 2021-08-25,9160096
239
+ 2021-08-26,9052229
240
+ 2021-08-27,8778271
241
+ 2021-08-28,9245534
242
+ 2021-08-29,9384023
243
+ 2021-08-30,9474742
244
+ 2021-08-31,9189054
245
+ 2021-09-01,9167277
246
+ 2021-09-02,9123056
247
+ 2021-09-03,9251321
248
+ 2021-09-04,9377700
249
+ 2021-09-05,9782022
250
+ 2021-09-06,8930331
251
+ 2021-09-07,9718666
252
+ 2021-09-08,9262001
253
+ 2021-09-09,9095889
254
+ 2021-09-10,9364629
255
+ 2021-09-11,9508131
256
+ 2021-09-12,9264013
257
+ 2021-09-13,9461281
258
+ 2021-09-14,9032235
259
+ 2021-09-15,9574777
260
+ 2021-09-16,9189740
261
+ 2021-09-17,9508023
262
+ 2021-09-18,9580631
263
+ 2021-09-19,9697272
264
+ 2021-09-20,9292315
265
+ 2021-09-21,9090518
266
+ 2021-09-22,9294810
267
+ 2021-09-23,9400956
268
+ 2021-09-24,9871832
269
+ 2021-09-25,9569204
270
+ 2021-09-26,9583588
271
+ 2021-09-27,9412385
272
+ 2021-09-28,9221235
273
+ 2021-09-29,9328174
274
+ 2021-09-30,9192142
275
+ 2021-10-01,9432155
276
+ 2021-10-02,9755500
277
+ 2021-10-03,9562636
278
+ 2021-10-04,9497084
279
+ 2021-10-05,9656472
280
+ 2021-10-06,9461320
281
+ 2021-10-07,9363588
282
+ 2021-10-08,9834844
283
+ 2021-10-09,9113802
284
+ 2021-10-10,9290592
285
+ 2021-10-11,9282316
286
+ 2021-10-12,9725761
287
+ 2021-10-13,9449353
288
+ 2021-10-14,9492895
289
+ 2021-10-15,9599402
290
+ 2021-10-16,9664876
291
+ 2021-10-17,9702569
292
+ 2021-10-18,9574962
293
+ 2021-10-19,9540428
294
+ 2021-10-20,9617606
295
+ 2021-10-21,9509561
296
+ 2021-10-22,9417190
297
+ 2021-10-23,9748484
298
+ 2021-10-24,9476970
299
+ 2021-10-25,9373507
300
+ 2021-10-26,9646801
301
+ 2021-10-27,9635634
302
+ 2021-10-28,9530612
303
+ 2021-10-29,9627467
304
+ 2021-10-30,9879362
305
+ 2021-10-31,9501436
306
+ 2021-11-01,9631220
307
+ 2021-11-02,10004975
308
+ 2021-11-03,9749567
309
+ 2021-11-04,9925777
310
+ 2021-11-05,9863408
311
+ 2021-11-06,9933505
312
+ 2021-11-07,9383028
313
+ 2021-11-08,9607159
314
+ 2021-11-09,9707735
315
+ 2021-11-10,9691895
316
+ 2021-11-11,9854091
317
+ 2021-11-12,9695957
318
+ 2021-11-13,10047149
319
+ 2021-11-14,9845653
320
+ 2021-11-15,9656831
321
+ 2021-11-16,10285056
322
+ 2021-11-17,9606579
323
+ 2021-11-18,9928425
324
+ 2021-11-19,9980182
325
+ 2021-11-20,9915679
326
+ 2021-11-21,9837099
327
+ 2021-11-22,9608834
328
+ 2021-11-23,9893666
329
+ 2021-11-24,9897017
330
+ 2021-11-25,10129048
331
+ 2021-11-26,9828852
332
+ 2021-11-27,10014982
333
+ 2021-11-28,10057900
334
+ 2021-11-29,10204676
335
+ 2021-11-30,10299217
336
+ 2021-12-01,9731627
337
+ 2021-12-02,9674146
338
+ 2021-12-03,9679469
339
+ 2021-12-04,10060861
340
+ 2021-12-05,9771507
341
+ 2021-12-06,9726983
342
+ 2021-12-07,10152789
343
+ 2021-12-08,9961637
344
+ 2021-12-09,9888931
345
+ 2021-12-10,10016144
346
+ 2021-12-11,10025271
347
+ 2021-12-12,10013123
348
+ 2021-12-13,10144930
349
+ 2021-12-14,10246870
350
+ 2021-12-15,9838107
351
+ 2021-12-16,9845904
352
+ 2021-12-17,10220516
353
+ 2021-12-18,9835059
354
+ 2021-12-19,9572522
355
+ 2021-12-20,10379305
356
+ 2021-12-21,9680446
357
+ 2021-12-22,10124238
358
+ 2021-12-23,9464659
359
+ 2021-12-24,9703857
360
+ 2021-12-25,10045897
361
+ 2021-12-26,10738865
362
+ 2021-12-27,10350408
363
+ 2021-12-28,10219445
364
+ 2021-12-29,10313337
365
+ 2021-12-30,10310644
366
+ 2021-12-31,10211187
model.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import pandas as pd
3
+ import numpy as np
4
+
5
+ class PredictionModel:
6
+ def __init__(self, model_path, data_path):
7
+ self.model_path = model_path
8
+ self.data_path = data_path
9
+ self.load_model()
10
+ self.load_data()
11
+
12
+ def load_model(self):
13
+ with open(self.model_path, 'rb') as f:
14
+ self.model = pickle.load(f)
15
+
16
+ def load_data(self):
17
+ self.df = pd.read_csv(self.data_path)
18
+ self.df.columns = ['date', 'receipt_count']
19
+
20
+ def predict(self, period, alpha=0.05):
21
+ yhat = self.model.forecast(period)
22
+ intervals = self.compute_confidence_intervals(alpha, yhat)
23
+ return yhat, intervals
24
+
25
+ def compute_confidence_intervals(self, alpha, yhat):
26
+ residuals = self.df.receipt_count - self.model.fittedvalues
27
+ z = abs(np.percentile(np.random.standard_normal(10000), [100 * alpha/2, 100 * (1 - alpha/2)]))
28
+ std_residual = residuals.std()
29
+ interval_upper = yhat + z[1] * std_residual * np.sqrt(1 + 1/len(self.df))
30
+ interval_lower = yhat - z[1] * std_residual * np.sqrt(1 + 1/len(self.df))
31
+ return [interval_lower, interval_upper]
models/damped_hw_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fe2517c3cb675a082dd0649e4d027ec4bb99019a2cfa4e9b1c92fa7b3292d050
3
+ size 28498
models/hw_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b54f6bc85ef9993b414a03a8ea140212bce994e5a044fa91425c3c04568ad229
3
+ size 28456