-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpipeline.py
More file actions
executable file
·64 lines (49 loc) · 2.59 KB
/
Copy pathpipeline.py
File metadata and controls
executable file
·64 lines (49 loc) · 2.59 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import logging
import numpy as np
import pandas as pd
from sklearn.model_selection import StratifiedKFold
from utils import features_utils, nn_utils
from utils.data_params import DataParams as dp
from utils.hyperparams import Hyperparameters
EXPERIMENT_CONFIG_FILE_PATH = 'config/experiment_setup.yml'
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Y_true = np.reshape(np.array([1] * 82 + [0] * 64), (1, 146))
def main():
hp = Hyperparameters(EXPERIMENT_CONFIG_FILE_PATH)
logger.info('Loading data...')
df = pd.read_csv(hp.data_file, sep='\t', header=None, index_col=0).T
logger.info('Loaded data...')
shuffle = np.random.permutation(Y_true.shape[1])
X = nn_utils.norm_data(df)
X['Case'] = ['AUTISM'] * dp.num_autism + ['CONTROL'] * dp.num_control
skf = StratifiedKFold(n_splits=hp.cross_validation_folds)
cv_acc = {'fisher': [], 'corr': [], 'ttest': [], 'random': []}
for fold_id, (train_idxs, test_idxs) in enumerate(skf.split(X.values, Y_true.reshape(146))):
X_train = X.iloc[train_idxs]
Y_train = Y_true[:, train_idxs]
X_test = X.iloc[test_idxs]
Y_test = Y_true[:, test_idxs]
selected_features = features_utils.execute_selection(hp.selection_methods, X_train)
for method, X_train_sel_features in selected_features.items():
init_parameters = nn_utils.init_parameters(input_size=hp.input_size,
hidden_sizes=hp.hidden_sizes,
output_size=hp.output_size)
trained_params, _ = nn_utils.train_nn(X_train_sel_features,
Y_train,
init_parameters,
method,
hp.activation_function,
'[{}/{}]'.format(fold_id + 1,
hp.cross_validation_folds),
hp)
X_test_sel_features = features_utils.apply_selection(method, X_test,
num_features=hp.num_features)
fold_acc = nn_utils.test_nn(X_test_sel_features, Y_test, trained_params, method,
hp.activation_function, hp)
cv_acc[method].append(fold_acc)
for m in hp.selection_methods:
logger.info('%d-fold cross-validation accuracy for [%s] method : [%d]',
hp.cross_validation_folds, m, sum(cv_acc[m]) / len(cv_acc[m]))
if __name__ == '__main__':
main()