forked from stavinova/predictability-classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvaluateResults.py
32 lines (27 loc) · 1.1 KB
/
EvaluateResults.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
import pandas as pd
import numpy as np
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import auc
import matplotlib.pyplot as plt
def make_err_df(y_true, y_pred):
return pd.DataFrame(np.vstack((y_true, y_pred)).transpose(), columns=['y_true','y_pred'])
def plot_PRC(errs, lim, colors, linestyles):
recalls = {}
for im, err in enumerate(errs):
ytrue = err['y_true'].values
ypred = err['y_pred'].values
precision, recall, thr = precision_recall_curve(ytrue, ypred)
area = auc(recall, precision)
clr = colors[im]
lns = linestyles[im]
plt.plot(recall, precision, linewidth = 2, color = clr, label = err.name, linestyle = lns)
ind = np.argmin(recall > lim)
if ind < len(thr):
r = recall[ind]
recalls[err.name] = r
plt.xlabel('Recall', fontsize = 20)
plt.ylabel('Precision', fontsize = 20)
plt.ylim(0, 1)
plt.title('PR curve',size = 20,weight = 'bold')
plt.legend()
return recalls, precision[ind], thr[ind], area