INNER CODE UNIT · Python
plot_f1
alteryx/open_source_demos · predict-appointment-noshow/utils.py:69
def plot_f1(y_test, probs, nprecs):
threshes = [x/1000. for x in range(50, nprecs)]
precisions = [precision_score(y_test, probs[:, 1] > t) for t in threshes]
recalls = [recall_score(y_test, probs[:, 1] > t) for t in threshes]
fones = [f1_score(y_test, probs[:, 1] > t) for t in threshes]
output_notebook()
p = figure(height=400, width=400)
p.line(x=threshes, y=precisions, color='green', legend_label='precision')
p.line(x=threshes, y=recalls, color='blue', legend_label='recall')
p.line(x=threshes, y=fones, color='red', legend_label='f1')
p.xaxis.axis_label = 'Threshold'
p.title.text = 'Precision, Recall, and F1 by Threshold'
return(p)
def plot_kfirst(ytest, probs, firstk=500):
A = pd.DataFrame(probs)