-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot.py
106 lines (90 loc) · 3.04 KB
/
plot.py
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
import tensorflow as tf
import matplotlib as mplt
mplt.use('agg') # Must be before importing matplotlib.pyplot or pylab!
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from math import sqrt
import csv
from math import sin
from math import radians
from matplotlib import pyplot
np.random.seed(1)
tf.set_random_seed(1)
class Config():
input_size = 1
num_steps = 7#5
lstm_size = 32
num_layers = 1
keep_prob = 0.8
batch_size = 8
init_learning_rate = 0.01
learning_rate_decay = 0.99
init_epoch = 5 # 5
max_epoch = 60 # 100 or 50
test_ratio = 0.2
fileName = 'store165_2.csv'
graph = tf.Graph()
features = 4
column_min_max = [[0,11000], [1,7]]
columns = ['Sales', 'DayOfWeek','SchoolHoliday', 'Promo']
config = Config()
# create a differenced series
def difference(dataset, interval=1):
return dataset
# invert differenced forecast
def inverse_difference(last_ob, value):
return value + last_ob
#
# def plot_sales():
#
# # store_data = pd.read_csv(config.fileName)
#
# # store_data = store_data.drop(store_data[(store_data.Open == 0) & (store_data.Sales == 0)].index)
#
# # store_data = store_data[(store_data.Month == 2) & (store_data.Year == 2013)]
#
# fig = plt.figure()
# fig = plt.figure(dpi=100, figsize=(20, 7))
# days = range(len(store_data))
# plt.plot(days, store_data[config.columns[0]], label='pred sales')
# plt.legend(loc='upper left', frameon=False)
# plt.xlabel("day")
# plt.ylabel("sales")
# plt.grid(ls='--')
# plt.savefig("sales graph.png", format='png', bbox_inches='tight', transparent=False)
# plt.close()
if __name__ == '__main__':
store_data = pd.read_csv(config.fileName)
# store_data = store_data.drop(store_data[(store_data.Open == 0) & (store_data.Sales == 0)].index)
store_data = store_data[(store_data.Month == 1) & (store_data.Year == 2013)]
fig = plt.figure()
fig = plt.figure(dpi=100, figsize=(20, 7))
days = range(len(store_data))
plt.plot(days, store_data[config.columns[0]], label='pred sales')
plt.legend(loc='upper left', frameon=False)
plt.xlabel("day")
plt.ylabel("sales")
plt.grid(ls='--')
plt.savefig("sales graph.png", format='png', bbox_inches='tight', transparent=False)
plt.close()
# difference the dataset
store_data['Sales'] = store_data['Sales'].diff(periods=14)
fig = plt.figure()
fig = plt.figure(dpi=100, figsize=(20, 7))
days = range(len(store_data))
plt.plot(days, store_data.Sales, label='pred sales')
plt.legend(loc='upper left', frameon=False)
plt.xlabel("day")
plt.ylabel("sales")
plt.grid(ls='--')
plt.savefig("sales graph 2.png", format='png', bbox_inches='tight', transparent=False)
plt.close()
# pyplot.plot(diff)
# pyplot.show()
# invert the difference
# inverted = [inverse_difference(store_data[i], diff[i]) for i in range(len(diff))]
# pyplot.plot(inverted)
# pyplot.show()