-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfeature_parser.py
116 lines (109 loc) · 4.29 KB
/
feature_parser.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import meta
from feature_entry import FeatureEntry
from util import read_all_data
import data_processor as dp
import numpy as np
class FeatureParser:
def __init__(self):
feature_tags = [
(meta.FEATURE_NO, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_RANGE, False, None),
(meta.FEATURE_NUM, False, None),
(meta.FEATURE_NUM, False, None),
(meta.FEATURE_LIST_MAX, False, 0),
(meta.FEATURE_LIST_ENUM, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
# M
(meta.FEATURE_LIST_ENUM, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
# Q
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_BIN, False, None),
# AE
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_NUM, False, 0),
(meta.FEATURE_RANGE, False, 0),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_NO, True, None),
(meta.FEATURE_NUM, False, 0),
(meta.FEATURE_BIN, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
# AO
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
# AS
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
# BA
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
(meta.FEATURE_ENUM, False, None),
]
self.feature_entries = list(map(
lambda e: FeatureEntry(e[0], e[1], e[2]), feature_tags
))
def parse(self, samples):
for sample in samples:
for i in range(len(self.feature_entries)):
self.feature_entries[i].add_sample(sample[i])
result = []
for sample in samples:
features = []
for i in range(len(self.feature_entries)):
feature = self.feature_entries[i].parse(sample[i])
if (feature is None):
features = None
break
features.extend(feature)
if (features is not None):
# engineered features
features.append(dp.get_enzyme_inducer_status(sample))
features.append(dp.get_amiodarone_status(
sample[meta.MEDICATIONS]
))
if (features is None):
result.append(None)
else:
result.append(np.array([features]))
return result
if __name__ == "__main__":
parser = FeatureParser()
samples = read_all_data("./data/warfarin.csv")
parser.parse(samples)