
176
|
第
8
章
可以用以下函数绘制
ROC
曲线(正例与假正例的相关性):
def
create_roc_plot():
plt.style.use('classic')
fig = plt.figure(figsize=(13, 8))
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.ylabel('True Positive Rate')
plt.xlabel('False Positive Rate')
plt.rc('axes', prop_cycle=(cycler('color',
['r', 'g', 'b', 'c', 'm', 'y', 'k'])))
plt.plot([0, 1], [0, 1], linestyle='--', label='Random score
(AUC = 0.50)')
return
plt, fig
def
add_curve(plt, title, fpr, tpr, roc):
plt.plot(fpr, tpr, label=f"{title} (AUC = {roc:0.2})")
可按如下方式调用该函数:
plt, fig = create_roc_plot()
add_curve(plt, "Common Authors",
basic_results["fpr"], basic_results["tpr"], basic_results["roc_auc"]) ...