Skip to content

Commit 163e827

Browse files
committed
Added commands for TensorBoard
1 parent 8581914 commit 163e827

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

Python Tensorflow Keras Fraud Detection Autoencoder.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
plt.title("Amount by percentage of transactions (transactions \$200+)")
7979
plt.xlabel("Transaction amount (USD)")
8080
plt.ylabel("Percentage of transactions (%)");
81-
plt.show()
81+
#plt.show()
8282

8383

8484

@@ -91,7 +91,7 @@
9191
plt.xlabel("Transaction time as measured from first transaction in the dataset (hours)")
9292
plt.ylabel("Percentage of transactions (%)");
9393
#plt.hist((df.Time/(60*60)),bins)
94-
plt.show()
94+
#plt.show()
9595

9696

9797

@@ -103,7 +103,7 @@
103103
plt.xlabel("Transaction time as measured from first transaction in the dataset (hours)")
104104
plt.ylabel('Amount (USD)')
105105
plt.legend(loc='upper right')
106-
plt.show()
106+
#plt.show()
107107

108108

109109

@@ -143,19 +143,20 @@
143143
# nb_epoch = 100
144144
# batch_size = 128
145145
nb_epoch = 5
146-
batch_size = 32
146+
batch_size = 128
147147

148148
input_dim = train_x.shape[1] #num of columns, 30
149149
encoding_dim = 14
150150
hidden_dim = int(encoding_dim / 2) #i.e. 7
151151
learning_rate = 1e-7
152+
# learning_rate = 1e-5
152153

153-
input_layer = Input(shape=(input_dim, ))
154-
encoder = Dense(encoding_dim, activation="tanh", activity_regularizer=regularizers.l1(learning_rate))(input_layer)
155-
encoder = Dense(hidden_dim, activation="relu")(encoder)
156-
decoder = Dense(hidden_dim, activation='tanh')(encoder)
157-
decoder = Dense(input_dim, activation='relu')(decoder)
158-
autoencoder = Model(inputs=input_layer, outputs=decoder)
154+
input_layer = Input(shape=(input_dim, ), name='CreditCardInput')
155+
encoder = Dense(encoding_dim, activation='tanh', name='Encoder1', activity_regularizer=regularizers.l1(learning_rate))(input_layer)
156+
encoder = Dense(hidden_dim, activation='relu', name='Encoder2')(encoder)
157+
decoder = Dense(hidden_dim, activation='tanh', name='Decoder1')(encoder)
158+
decoder = Dense(input_dim, activation='relu', name='Decoder2')(decoder)
159+
autoencoder = Model(inputs=input_layer, outputs=decoder, name='FraudDetectionAutoencoder')
159160

160161

161162

@@ -172,7 +173,7 @@
172173
verbose=0)
173174

174175
tb = TensorBoard(log_dir='logs/keras-fraud',
175-
histogram_freq=0,
176+
histogram_freq=1,
176177
write_graph=True,
177178
write_images=True)
178179

@@ -184,11 +185,6 @@
184185
verbose=1,
185186
callbacks=[cp, tb]).history
186187

187-
188-
189-
190-
191-
192188
autoencoder = load_model('models/autoencoder_fraud.h5')
193189

194190

@@ -201,7 +197,7 @@
201197
plt.ylabel('Loss')
202198
plt.xlabel('Epoch')
203199
#plt.ylim(ymin=0.70,ymax=1)
204-
plt.show()
200+
#plt.show()
205201

206202

207203

@@ -230,7 +226,7 @@
230226
plt.title('Receiver operating characteristic curve (ROC)')
231227
plt.ylabel('True Positive Rate')
232228
plt.xlabel('False Positive Rate')
233-
plt.show()
229+
#plt.show()
234230

235231

236232

@@ -241,7 +237,7 @@
241237
plt.title('Recall vs Precision')
242238
plt.xlabel('Recall')
243239
plt.ylabel('Precision')
244-
plt.show()
240+
#plt.show()
245241

246242

247243

@@ -253,7 +249,7 @@
253249
plt.xlabel('Threshold')
254250
plt.ylabel('Precision/Recall')
255251
plt.legend()
256-
plt.show()
252+
#plt.show()
257253

258254

259255

@@ -272,7 +268,7 @@
272268
plt.title("Reconstruction error for different classes")
273269
plt.ylabel("Reconstruction error")
274270
plt.xlabel("Data point index")
275-
plt.show();
271+
#plt.show();
276272

277273

278274

@@ -286,4 +282,4 @@
286282
plt.title("Confusion matrix")
287283
plt.ylabel('True class')
288284
plt.xlabel('Predicted class')
289-
plt.show()
285+
#plt.show()

0 commit comments

Comments
 (0)