-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (42 loc) · 1.1 KB
/
main.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
# Import
from model.sequential import Sequential
from model.util.layer import Layer
from util.preprocess import preprocess
from util.metrics import binary_accuracy_score
import matplotlib.pyplot as plt
# Read *.csv file and preprocess
X, y = preprocess('./test/data_weather.csv')
# Define nb of layers and nb of neurons
model = Sequential([
Layer(5), # param 1: nb of neurons
Layer(5),
Layer(5),
Layer(5),
Layer(1)
])
# define batch_size and epochs as you wish!
batch_size = 2
epochs = 1000
# build model
model.compile()
# let's train!
model.fit(
X,
y,
epochs=epochs,
batch_size=batch_size,
)
# plotting cost (error)
times = [i for i in range(epochs)]
fig, ax = plt.subplots(figsize=(5,3))
ax.plot(times, model.optimizer.error_list)
fig.suptitle('Plotting Error')
ax.set_xlabel('Iterations / Epochs')
ax.set_ylabel('Error')
# show the plot
plt.show()
# predict input data by using predict method
y_pred = model.predict(X)
print('\n\nerror: {}'.format(model.optimizer.error_list.pop()))
print('output predict {}:\n{}'.format(X, y_pred))
print('accuracy: {}'.format(binary_accuracy_score(y, y_pred)))