2
$\begingroup$

I have classified a data with multiple classes (not binary) by using several classifiers, and I would like to compare the performance of these classifiers by drawing their ROC curves using scikitplot.

The code below produces the ROC curves for each model separately, I would like to get them on the same figure and keep using scikitplot. Any suggestions would be highly appreciated!

from sklearn.pipeline import make_pipeline
import matplotlib.pyplot as plt
import scikitplot as skplt
import matplotlib.pyplot as plt
from matplotlib.pyplot import *
fig = plt.figure()
for i in range(0,6):
    num+=1
    predicted_probas = model[i].predict_proba(X_test)
    skplt.metrics.plot_roc(y_test, predicted_probas, plot_micro=False, plot_macro=False, classes_to_plot=1)
    plt.title('ROC Curve of '+model_name[i])
    plt.show()

enter image description here

$\endgroup$
2
  • $\begingroup$ have you tried indenting the last code line 'plt.show' (to the left)? $\endgroup$ Commented Nov 22, 2019 at 8:08
  • $\begingroup$ Yes, but that doesn't plot them in a one figure! $\endgroup$
    – mhdella
    Commented Nov 22, 2019 at 13:06

1 Answer 1

1
$\begingroup$

In version 0.22, scikit-learn introduced the plot_roc_curve function and a new plotting API (release highlights)

This is the example they provide to add multiple plots in the same figure.

svc = SVC(random_state=42)
svc.fit(X_train, y_train)
rfc = RandomForestClassifier(random_state=42)
rfc.fit(X_train, y_train)

svc_disp = plot_roc_curve(svc, X_test, y_test)
rfc_disp = plot_roc_curve(rfc, X_test, y_test, ax=svc_disp.ax_)
rfc_disp.figure_.suptitle("ROC curve comparison")

plt.show()

I hope that helps

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.