Skip to content

Commit

Permalink
Added commands for TensorBoard
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiwaehner committed Dec 9, 2018
1 parent 8581914 commit 163e827
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions Python Tensorflow Keras Fraud Detection Autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
plt.title("Amount by percentage of transactions (transactions \$200+)")
plt.xlabel("Transaction amount (USD)")
plt.ylabel("Percentage of transactions (%)");
plt.show()
#plt.show()



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



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



Expand Down Expand Up @@ -143,19 +143,20 @@
# nb_epoch = 100
# batch_size = 128
nb_epoch = 5
batch_size = 32
batch_size = 128

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

input_layer = Input(shape=(input_dim, ))
encoder = Dense(encoding_dim, activation="tanh", activity_regularizer=regularizers.l1(learning_rate))(input_layer)
encoder = Dense(hidden_dim, activation="relu")(encoder)
decoder = Dense(hidden_dim, activation='tanh')(encoder)
decoder = Dense(input_dim, activation='relu')(decoder)
autoencoder = Model(inputs=input_layer, outputs=decoder)
input_layer = Input(shape=(input_dim, ), name='CreditCardInput')
encoder = Dense(encoding_dim, activation='tanh', name='Encoder1', activity_regularizer=regularizers.l1(learning_rate))(input_layer)
encoder = Dense(hidden_dim, activation='relu', name='Encoder2')(encoder)
decoder = Dense(hidden_dim, activation='tanh', name='Decoder1')(encoder)
decoder = Dense(input_dim, activation='relu', name='Decoder2')(decoder)
autoencoder = Model(inputs=input_layer, outputs=decoder, name='FraudDetectionAutoencoder')



Expand All @@ -172,7 +173,7 @@
verbose=0)

tb = TensorBoard(log_dir='logs/keras-fraud',
histogram_freq=0,
histogram_freq=1,
write_graph=True,
write_images=True)

Expand All @@ -184,11 +185,6 @@
verbose=1,
callbacks=[cp, tb]).history






autoencoder = load_model('models/autoencoder_fraud.h5')


Expand All @@ -201,7 +197,7 @@
plt.ylabel('Loss')
plt.xlabel('Epoch')
#plt.ylim(ymin=0.70,ymax=1)
plt.show()
#plt.show()



Expand Down Expand Up @@ -230,7 +226,7 @@
plt.title('Receiver operating characteristic curve (ROC)')
plt.ylabel('True Positive Rate')
plt.xlabel('False Positive Rate')
plt.show()
#plt.show()



Expand All @@ -241,7 +237,7 @@
plt.title('Recall vs Precision')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.show()
#plt.show()



Expand All @@ -253,7 +249,7 @@
plt.xlabel('Threshold')
plt.ylabel('Precision/Recall')
plt.legend()
plt.show()
#plt.show()



Expand All @@ -272,7 +268,7 @@
plt.title("Reconstruction error for different classes")
plt.ylabel("Reconstruction error")
plt.xlabel("Data point index")
plt.show();
#plt.show();



Expand All @@ -286,4 +282,4 @@
plt.title("Confusion matrix")
plt.ylabel('True class')
plt.xlabel('Predicted class')
plt.show()
#plt.show()

0 comments on commit 163e827

Please sign in to comment.