-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforcasting.py
More file actions
118 lines (57 loc) · 1.66 KB
/
Copy pathforcasting.py
File metadata and controls
118 lines (57 loc) · 1.66 KB
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
#!/usr/bin/env python
# coding: utf-8
# In[17]:
import pandas as pd
wsb_df = pd.read_csv('wsb.csv')
wsb_df.head(10)
# In[18]:
import matplotlib.pyplot as plt
import seaborn as sn
get_ipython().run_line_magic('matplotlib', 'inline')
# In[19]:
plt.figure(figsize=(10,4))
plt.xlabel("Month")
plt.ylabel("quantity")
plt.plot(wsb_df['Sale Quantity']);
# In[20]:
wsb_df.info()
# In[21]:
wsb_df['mavg_12'] = wsb_df['Sale Quantity'].rolling(window = 12).mean().shift(1)
# In[9]:
pd.set_option('display.float_format', lambda x: '%.2f' % x)
wsb_df[['Sale Quantity', 'mavg_12']][36:]
# In[22]:
plt.figure(figsize=(10,4))
plt.xlabel("Months")
plt.ylabel("Quantity")
plt.plot(wsb_df['Sale Quantity'][12:])
plt.plot(wsb_df['mavg_12'][12:], '.')
plt.legend();
# In[23]:
import numpy as np
def get_mape(actual, predicted):
y_true, y_pred = np.array(actual), np.array(predicted)
return np.round(np.mean(np.abs((actual - predicted)/ actual))*100, 2)
# In[24]:
get_mape(wsb_df['Sale Quantity'][36:].values,
wsb_df['mavg_12'][36:].values)
# In[25]:
from sklearn.metrics import mean_squared_error
np.sqrt(mean_squared_error(wsb_df['Sale Quantity'][36:].values,
wsb_df['mavg_12'][36:].values))
# In[32]:
wsb_df['ewm'] = wsb_df['Sale Quantity'].ewm(alpha = 0.2).mean()
# In[33]:
pd.options.display.float_format = '{:.2f}'.format
# In[34]:
wsb_df[36:]
# In[46]:
get_mape(wsb_df[['Sale Qunatity']][36:].values,
wsb_df[['ewm']][36:].values)
# In[47]:
plt.figure(figsize=(10,4))
plt.xlabel("Months")
plt.ylabel("Quantity")
plt.plot(wsb_df['Sale Quantity'][12:])
plt.plot(wsb_df['ewm'])[12:], '.')
plt.legend()