INNER CODE UNIT · Python
plot_kfirst
alteryx/open_source_demos · predict-appointment-noshow/utils.py:85
def plot_kfirst(ytest, probs, firstk=500):
A = pd.DataFrame(probs)
A['y_test'] = ytest.values
krange = range(firstk)
firstk = []
for K in krange:
a = A[1][:K]
a = [1 for prob in a]
b = A['y_test'][:K]
firstk.append(precision_score(b, a))
output_notebook()
p = figure(height=400, width=400)
p.step(x=krange, y=firstk)
p.xaxis.axis_label = 'Predictions sorted by most likely'
p.yaxis.axis_label = 'Precision'
p.title.text = 'K-first'
p.yaxis[0].formatter.use_scientific = False