-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproblem.py
52 lines (42 loc) · 1.71 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
import os
import numpy as np
import pandas as pd
import rampwf as rw
problem_title =\
'Cell population identification from single-cell mass cytometry data'
_target_column_name = 'cell type'
_prediction_label_names = [
'B-cell Frac A-C (pro-B cells)', 'Basophils', 'CD4 T cells', 'CD8 T cells',
'CLP', 'CMP', 'Classical Monocytes', 'Eosinophils', 'GMP', 'HSC',
'IgD- IgMpos B cells', 'IgDpos IgMpos B cells', 'IgM- IgD- B-cells',
'Intermediate Monocytes', 'MEP', 'MPP', 'Macrophages', 'NK cells',
'NKT cells', 'Non-Classical Monocytes', 'Plasma Cells', 'gd T cells',
'mDCs', 'pDCs']
# A type (class) which will be used to create wrapper objects for y_pred
Predictions = rw.prediction_types.make_multiclass(
label_names=_prediction_label_names)
# An object implementing the workflow
workflow = rw.workflows.FeatureExtractorClassifier()
score_types = [
rw.score_types.BalancedAccuracy(name='bac', precision=3),
rw.score_types.Accuracy(name='acc', precision=3),
rw.score_types.NegativeLogLikelihood(name='nll', precision=3),
]
def get_cv(X, y):
unique_replicates = np.unique(X['replicate'])
r = np.arange(len(X))
for replicate in unique_replicates:
train_is = r[(X['replicate'] != replicate).values]
test_is = r[(X['replicate'] == replicate).values]
yield train_is, test_is
def _read_data(path, f_name):
data = pd.read_csv(os.path.join(path, 'data', f_name))
y_array = data[_target_column_name]
X_df = data.drop([_target_column_name], axis=1)
return X_df, y_array
def get_train_data(path='.'):
f_name = 'train.csv.gz'
return _read_data(path, f_name)
def get_test_data(path='.'):
f_name = 'test.csv.gz'
return _read_data(path, f_name)