TSaala commited on
Commit
7a44ed3
·
verified ·
1 Parent(s): 9f95877

Create Model.py

Browse files
Files changed (1) hide show
  1. Model.py +47 -0
Model.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import keras
2
+ from keras.layers import Dense
3
+ from keras.optimizers import Nadam
4
+ from keras.callbacks import ModelCheckpoint, EarlyStopping
5
+
6
+ import pandas as pd
7
+ import numpy as np
8
+
9
+ # Model parameters:
10
+ activation = 'relu'
11
+ final_activation = 'softmax'
12
+ loss = 'categorical_crossentropy'
13
+ batchsize = 100
14
+ epochs = 200
15
+ lr = 0.001
16
+
17
+ # Model architecture:
18
+ model = keras.Sequential()
19
+ model.add(Dense(units=8, input_shape=(8,), activation=activation))
20
+ model.add(Dense(units=8, activation=activation))
21
+ model.add(Dense(units=4, activation=activation))
22
+ model.add(Dense(units=4, activation=activation))
23
+ model.add(Dense(units=2, activation=final_activation))
24
+
25
+ model.compile(optimizer=Nadam(learning_rate=lr), loss=loss,
26
+ metrics=['accuracy', 'AUC'])
27
+ model.summary()
28
+
29
+
30
+ # Model checkpoints:
31
+ saveModel = ModelCheckpoint('best_model.hdf5',
32
+ save_best_only=True,
33
+ monitor='val_loss',
34
+ mode='min')
35
+
36
+
37
+ # Model training:
38
+ model.fit(
39
+ x_train,
40
+ y_train,
41
+ batch_size=batchsize,
42
+ callbacks=[EarlyStopping(verbose=True, patience=20, monitor='val_loss'), saveModel],
43
+ epochs=epochs,
44
+ validation_data=(
45
+ x_val,
46
+ y_val),
47
+ shuffle=True)