Issue
I use below code to create ROC curve:
probs = model.predict_proba(X)[::,1]
auc = metrics.roc_auc_score(y, probs)
fper, tper, thresholds = roc_curve(y, probs)
plt.plot(fper, tper, label= model_name + " (auc = %0.3f)" % auc, color=color)
plt.plot([0, 1], [0, 1], color='black', linestyle='--')
plt.xlabel('False Positive Rate', fontsize=15)
plt.ylabel('True Positive Rate', fontsize=15)
plt.xticks(fontsize=15)
plt.yticks(fontsize=15)
plt.show()
Nevertheless, in this way I can create ROC only for 1 model nevertheless how can I modyfy this code, sa as to present ROC curves concerning a few models not only 1 model like above ?
Solution
It's not clear exactly what type of plot you'd like, are you asking for the ROC curves to be in multiple separate plots or overlaid on each other?
If you want multiple plots, check out this function: https://matplotlib.org/devdocs/gallery/subplots_axes_and_figures/subplots_demo.html
Here is an example they give for how to use plt.subplots
to place 4 plots on a single figure:
fig, axs = plt.subplots(2, 2)
axs[0, 0].plot(x, y)
axs[0, 0].set_title('Axis [0, 0]')
axs[0, 1].plot(x, y, 'tab:orange')
axs[0, 1].set_title('Axis [0, 1]')
axs[1, 0].plot(x, -y, 'tab:green')
axs[1, 0].set_title('Axis [1, 0]')
axs[1, 1].plot(x, -y, 'tab:red')
axs[1, 1].set_title('Axis [1, 1]')
for ax in axs.flat:
ax.set(xlabel='x-label', ylabel='y-label')
# Hide x labels and tick labels for top plots and y ticks for right plots.
for ax in axs.flat:
ax.label_outer()
So for you, instead of plotting with plt.plot(fper, tper, label= model_name + " (auc = %0.3f)" % auc, color=color)
, you need to create subplots and instead do axs[i, j].plot(fper, tper, label= model_name + " (auc = %0.3f)" % auc, color=color)
If you want the ROC curves to be overlaid on the same plot, matplotlib does this by default. Simply plot all of the data as described here: How to get different colored lines for different plots in a single figure?.
Answered By - doduo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.