-
Notifications
You must be signed in to change notification settings - Fork 1
/
outlier_model.py
62 lines (47 loc) · 1.98 KB
/
outlier_model.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
import numpy as np
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.metrics import make_scorer, recall_score
from sklearn.model_selection import cross_val_score
from features import get_all_features
def train_model_outcomes(recordings, murmur_labels):
# labels are murmur_labels, {0, 1, 2}
labels = murmur_labels.reshape(-1) # reshape column to row vector
features = []
for rec in recordings:
features.append(get_all_features(rec))
features = np.vstack(features)
model = GradientBoostingClassifier()
model.fit(features, labels)
return model
def run_model_outcomes(model, recordings):
features = []
for rec in recordings:
features.append(get_all_features(rec))
features = np.vstack(features)
# returns an array of pred/prob for each recording
preds = model.predict(features)
probs = model.predict_proba(features)
return preds, probs
def train_model(recordings, murmur_labels, num_recs, heart_rates):
# labels are murmur_labels, {0, 1, 2}
labels = murmur_labels.reshape(-1) # reshape column to row vector
heart_rates = heart_rates.reshape(-1,1) # reshape row to column vector ¯\_(ツ)_/¯
features = []
for rec in recordings:
features.append(get_all_features(rec))
features = np.vstack(features)
features = np.concatenate((features, num_recs, heart_rates), axis = 1)
model = GradientBoostingClassifier()
model.fit(features, labels)
return model
def run_model(model, recordings, num_recs, heart_rates):
heart_rates = heart_rates.reshape(-1,1) # reshape row to column vector
features = []
for rec in recordings:
features.append(get_all_features(rec))
features = np.vstack(features)
features = np.concatenate((features, num_recs, heart_rates), axis = 1)
# returns an array of pred/prob for each recording
preds = model.predict(features)
probs = model.predict_proba(features)
return preds, probs