-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.py
45 lines (40 loc) · 1.42 KB
/
misc.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
import json
from sklearn.metrics import recall_score, roc_auc_score, confusion_matrix
from sklearn.base import BaseEstimator, TransformerMixin
def construct_line(model_name , dataset, scores, y, best_parameters):
row=[]
row.append(model_name)
row.append(dataset)
if scores is not None:
for i in scores:
row.append(i)
else:
if 'predicted' in y.keys():
row.append(100*recall_score(y['input'],y['predicted'],pos_label=1))
row.append(None)
row.append(100*recall_score(y['input'],y['predicted'],pos_label=0))
row.append(None)
else:
row.append(None)
row.append(None)
row.append(None)
row.append(None)
if 'scores' in y.keys():
row.append(100*roc_auc_score(y['input'],y['scores']))
else:
row.append(None)
row.append(None)
table = confusion_matrix(y['input'], y['predicted'])
row.append(table[0][0])
row.append(table[0][1])
row.append(table[1][0])
row.append(table[1][1])
row.append(json.dumps(best_parameters))
return row
class DataFrameSelector(BaseEstimator, TransformerMixin):
def __init__(self, attribute_names):
self.attribute_names = attribute_names
def fit(self, X, y=None):
return self
def transform(self, X):
return X[self.attribute_names].values