-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathkkeras_util.py
98 lines (81 loc) · 2.75 KB
/
kkeras_util.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
#from keras.models import Sequential
from keras.layers import Dense, Input
from keras.models import Model
from keras.regularizers import l1
import matplotlib.pyplot as plt
def plot_model_history( history):
"""
accuracy and loss are depicted.
"""
plt.plot(history.history['acc'])
#plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
#plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
#plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
#plt.legend(['train', 'test'], loc='upper left')
plt.show()
def plot_history( history):
"""
accuracy and loss are depicted.
"""
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
class Model_Ordinary( Model):
"""
Adaptive linear model based on Keras Model
"""
def __init__(self, X_shape_1):
in_model = Input(shape=(X_shape_1,))
out_model = Dense(1, activation='linear')(in_model)
super().__init__(input = in_model, output=out_model)
self.compile(optimizer='adadelta', loss='mse', metrics=['accuracy'])
class Model_Ordinary_Hidden( Model):
"""
Adaptive linear model based on Keras Model
"""
def __init__(self, X_shape_1, n_h_nodes):
in_model = Input(shape=(X_shape_1,))
hidden_l = Dense(n_h_nodes, activation='relu')(in_model)
out_model = Dense(1, activation='linear')(hidden_l)
super().__init__(input = in_model, output=out_model)
self.compile(optimizer='adadelta', loss='mse', metrics=['accuracy'])
class Model_Lasso( Model):
"""
Adaptive linear model based on Keras Model
"""
def __init__(self, X_shape_1, alpha):
in_model = Input(shape=(X_shape_1,))
out_model = Dense(1, activation='linear', W_regularizer=l1(alpha))(in_model)
super().__init__(input = in_model, output=out_model)
self.compile(optimizer='adadelta', loss='mse', metrics=['accuracy'])
class Model_Lasso_Hidden( Model):
"""
Adaptive linear model based on Keras Model
"""
def __init__(self, X_shape_1, n_h_nodes, alpha):
in_model = Input(shape=(X_shape_1,))
hidden_l = Dense(n_h_nodes, activation='relu', W_regularizer=l1(alpha))(in_model)
out_model = Dense(1, activation='linear', W_regularizer=l1(alpha))(hidden_l)
super().__init__(input = in_model, output=out_model)
self.compile(optimizer='adadelta', loss='mse', metrics=['accuracy'])