-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc_train_no_weights_automatic.py
43 lines (26 loc) · 1.3 KB
/
cc_train_no_weights_automatic.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
import numpy as np
import scipy.sparse
import tensorflow as tf
import tensorflow.keras as keras
from classifier_chains import ClassifierChain
np.random.seed(0)
tf.set_random_seed(0)
X_train = scipy.sparse.load_npz('X_train.npz')
X_test = scipy.sparse.load_npz('X_test.npz')
y_train = np.load('y_train.npy')
model = keras.models.Sequential()
model.add(keras.layers.Dense(units=50, input_dim=X_train.shape[1], activation='relu'))
model.add(keras.layers.Dropout(0.1))
model.add(keras.layers.Dense(units=2, input_dim=50, activation='softmax'))
sgd_optimizer = keras.optimizers.SGD(lr=0.1, decay=1e-15, momentum=.9)
model.compile(optimizer=sgd_optimizer, loss='binary_crossentropy')
optimizers= [sgd_optimizer]
losses = ['binary_crossentropy']
cc = ClassifierChain(classifier=model, num_labels=2, name='AG_NT_no_weights_automatic', optimizers=optimizers, losses=losses, create_missing=True)
sample_weights = np.ones(y_train.shape[0])
predefined_sample_weights = [sample_weights]
cc.fit(X=X_train, y=y_train, epochs=15, batch_size=64, weights_mode='chain', predefined_weights=predefined_sample_weights, debalancing=[0, 1.4])
preds_train = cc.predict(X_train)
preds_test = cc.predict(X_test)
np.save('preds_train_AG_NT_no_weights_automatic.npy', preds_train)
np.save('preds_test_AG_NT_no_weights_automatic.npy', preds_test)