-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem.py
80 lines (61 loc) · 2.76 KB
/
problem.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import numpy as np
import pandas as pd
import rampwf as rw
from sklearn.model_selection import StratifiedShuffleSplit
problem_title = 'Neurodevelopmental classification'
_target_column_name = 'dx'
_prediction_label_names = [0, 1]
Predictions = rw.prediction_types.make_multiclass(
label_names=_prediction_label_names)
workflow = rw.workflows.FeatureExtractorClassifier()
score_types = [
rw.score_types.ROCAUC(name='auc', precision=3),
rw.score_types.Accuracy(name='acc', precision=3),
]
def get_cv(X, y):
cv = StratifiedShuffleSplit(n_splits=8, test_size=0.2, random_state=42)
return cv.split(X, y)
def _read_data(path, filename):
subject_id = pd.read_csv(os.path.join(path, 'data', filename), header=None)
# read the list of the subjects
df_participants = pd.read_csv(os.path.join(path, 'data',
'participants.csv'),
index_col=0)
df_participants.columns = ['participants_' + col
for col in df_participants.columns]
# load the structural and functional MRI data
df_anatomy = pd.read_csv(os.path.join(path, 'data', 'anatomy.csv'),
index_col=0)
df_anatomy.columns = ['anatomy_' + col
for col in df_anatomy.columns]
df_fmri = pd.read_csv(os.path.join(path, 'data', 'fmri_filename.csv'),
index_col=0)
df_fmri.columns = ['fmri_' + col
for col in df_fmri.columns]
# load the QC for structural and functional MRI data
df_anatomy_qc = pd.read_csv(os.path.join(path, 'data', 'anatomy_qc.csv'),
index_col=0)
df_fmri_qc = pd.read_csv(os.path.join(path, 'data', 'fmri_qc.csv'),
index_col=0)
df_fmri_tr = pd.read_csv(os.path.join(path, 'data',
'fmri_repetition_time.csv'),
index_col=0)
# rename the columns for the QC to have distinct names
df_anatomy_qc = df_anatomy_qc.rename(columns={"select": "anatomy_select"})
df_fmri_qc = df_fmri_qc.rename(columns={"select": "fmri_select"})
X = pd.concat([df_participants, df_anatomy, df_anatomy_qc, df_fmri,
df_fmri_qc, df_fmri_tr], axis=1)
X = X.loc[subject_id[0]]
y = X['participants_dx']
X = X.drop('participants_dx', axis=1)
return X, y.values
def get_train_data(path='.'):
filename = 'train.csv'
return _read_data(path, filename)
def get_test_data(path='.'):
filename = 'test.csv'
return _read_data(path, filename)
def save_submission(y_pred, data_path, output_path, suffix):
np.savetxt(os.path.join(output_path, 'y_pred_{}.csv'.format(suffix)),
y_pred)