-
Notifications
You must be signed in to change notification settings - Fork 3
/
dm.py
67 lines (51 loc) · 2.25 KB
/
dm.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
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.python.keras import layers
import csv
FILENAME = "Data/Train_data.csv"
print("Start loading data")
operateList = []
with open(FILENAME) as f:
reader = csv.reader(f)
for line in reader:
tempLine = []
for element in line:
tempLine.append(float(element))
operateList.append(tempLine)
inputList = []
for line in operateList:
tempLine = []
for element in line[:8]:
tempLine.append(element)
inputList.append(tempLine)
outputList = []
for line in operateList:
tempLine = []
tempLine.append(line[9])
outputList.append(tempLine)
inputData = np.array(inputList)
outputData = np.array(outputList)
print("Start modeling the NN")
model = tf.keras.Sequential()
# for input layer
model.add(layers.Dense(9, activation="relu"))
# for hidden layer
model.add(layers.Dense(18, activation="relu", bias_initializer=tf.keras.initializers.constant(1.0)))
model.add(layers.Dense(18, activation="relu", bias_initializer=tf.keras.initializers.constant(1.0)))
# model.add(layers.Dense(18, activation="relu", bias_initializer=tf.keras.initializers.constant(1.0)))
# model.add(layers.Dense(18, activation="relu", bias_initializer=tf.keras.initializers.constant(1.0)))
# model.add(layers.Dense(18, activation="relu", bias_initializer=tf.keras.initializers.constant(1.0)))
# for output layer
model.add(layers.Dense(1, activation="relu", bias_initializer=tf.keras.initializers.constant(1.0)))
# compile the model
#model.compile(optimizer=keras.optimizers.SGD(lr=0.001, momentum=0.9, nesterov=True), loss='mse', metrics=['mae'])
#model.compile(optimizer=keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False), loss='mse', metrics=['mae'])
#model.compile(optimizer=keras.optimizers.SGD(lr=0.01, momentum=0.9, nesterov=True), loss='categorical_crossentropy', metrics=['accuracy'])
model.compile(optimizer=keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False), loss='mse',metrics=['mae'])
# fit the model
#
model.fit(inputData, outputData, epochs=10, batch_size=3)
# evaluate the result
print("Priting the evaluate result")
model.evaluate(inputData, outputData, batch_size=3)