|
78 | 78 | plt.title("Amount by percentage of transactions (transactions \$200+)") |
79 | 79 | plt.xlabel("Transaction amount (USD)") |
80 | 80 | plt.ylabel("Percentage of transactions (%)"); |
81 | | -plt.show() |
| 81 | +#plt.show() |
82 | 82 |
|
83 | 83 |
|
84 | 84 |
|
|
91 | 91 | plt.xlabel("Transaction time as measured from first transaction in the dataset (hours)") |
92 | 92 | plt.ylabel("Percentage of transactions (%)"); |
93 | 93 | #plt.hist((df.Time/(60*60)),bins) |
94 | | -plt.show() |
| 94 | +#plt.show() |
95 | 95 |
|
96 | 96 |
|
97 | 97 |
|
|
103 | 103 | plt.xlabel("Transaction time as measured from first transaction in the dataset (hours)") |
104 | 104 | plt.ylabel('Amount (USD)') |
105 | 105 | plt.legend(loc='upper right') |
106 | | -plt.show() |
| 106 | +#plt.show() |
107 | 107 |
|
108 | 108 |
|
109 | 109 |
|
|
143 | 143 | # nb_epoch = 100 |
144 | 144 | # batch_size = 128 |
145 | 145 | nb_epoch = 5 |
146 | | -batch_size = 32 |
| 146 | +batch_size = 128 |
147 | 147 |
|
148 | 148 | input_dim = train_x.shape[1] #num of columns, 30 |
149 | 149 | encoding_dim = 14 |
150 | 150 | hidden_dim = int(encoding_dim / 2) #i.e. 7 |
151 | 151 | learning_rate = 1e-7 |
| 152 | +# learning_rate = 1e-5 |
152 | 153 |
|
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') |
159 | 160 |
|
160 | 161 |
|
161 | 162 |
|
|
172 | 173 | verbose=0) |
173 | 174 |
|
174 | 175 | tb = TensorBoard(log_dir='logs/keras-fraud', |
175 | | - histogram_freq=0, |
| 176 | + histogram_freq=1, |
176 | 177 | write_graph=True, |
177 | 178 | write_images=True) |
178 | 179 |
|
|
184 | 185 | verbose=1, |
185 | 186 | callbacks=[cp, tb]).history |
186 | 187 |
|
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | 188 | autoencoder = load_model('models/autoencoder_fraud.h5') |
193 | 189 |
|
194 | 190 |
|
|
201 | 197 | plt.ylabel('Loss') |
202 | 198 | plt.xlabel('Epoch') |
203 | 199 | #plt.ylim(ymin=0.70,ymax=1) |
204 | | -plt.show() |
| 200 | +#plt.show() |
205 | 201 |
|
206 | 202 |
|
207 | 203 |
|
|
230 | 226 | plt.title('Receiver operating characteristic curve (ROC)') |
231 | 227 | plt.ylabel('True Positive Rate') |
232 | 228 | plt.xlabel('False Positive Rate') |
233 | | -plt.show() |
| 229 | +#plt.show() |
234 | 230 |
|
235 | 231 |
|
236 | 232 |
|
|
241 | 237 | plt.title('Recall vs Precision') |
242 | 238 | plt.xlabel('Recall') |
243 | 239 | plt.ylabel('Precision') |
244 | | -plt.show() |
| 240 | +#plt.show() |
245 | 241 |
|
246 | 242 |
|
247 | 243 |
|
|
253 | 249 | plt.xlabel('Threshold') |
254 | 250 | plt.ylabel('Precision/Recall') |
255 | 251 | plt.legend() |
256 | | -plt.show() |
| 252 | +#plt.show() |
257 | 253 |
|
258 | 254 |
|
259 | 255 |
|
|
272 | 268 | plt.title("Reconstruction error for different classes") |
273 | 269 | plt.ylabel("Reconstruction error") |
274 | 270 | plt.xlabel("Data point index") |
275 | | -plt.show(); |
| 271 | +#plt.show(); |
276 | 272 |
|
277 | 273 |
|
278 | 274 |
|
|
286 | 282 | plt.title("Confusion matrix") |
287 | 283 | plt.ylabel('True class') |
288 | 284 | plt.xlabel('Predicted class') |
289 | | -plt.show() |
| 285 | +#plt.show() |
0 commit comments