Visualizing ROC Curve

Now by using the predictions for the three classes we will try to visualise the roc curve for each of the classes. Like one v/s all.

Python3




fig, ax = plt.subplots(figsize=(10, 10))
target_names = iris_data.target_names
colors = cycle(["aqua", "darkorange", "cornflowerblue"])
for class_id, color in zip(range(n_classes), colors):
    RocCurveDisplay.from_predictions(
        test_y[:, class_id],
        prob_test_vec[:, class_id],
        name=f"ROC curve for {target_names[class_id]}",
        color=color,
        ax=ax,
    )


Output:

ROC Curve for each of the classes.

In the above graph we are able to see only two lines but that is not the case because the roc-auc score for setosa and the virginica class is same due to which the roc curve for these two classes overlap with each other.



Multiclass Receiver Operating Characteristic (roc) in Scikit Learn

The ROC curve is used to measure the performance of classification models. It shows the relationship between the true positive rate and the false positive rate. The ROC curve is used to compute the AUC score. The value of the AUC score ranges from 0 to 1. The higher the AUC score, the better the model. This article discusses how to use the ROC curve in scikit learn.

ROC for Multi class Classification

Now, let us understand how to use ROC for multi class classifier. So, we will build a simple logistic regression model to predict the type of iris. We will be using the iris dataset provided by sklearn. The iris dataset has 4 features and 3 target classes (Setosa, Versicolour, and Virginica).

Similar Reads

Import Required Libraries

Python libraries make it very easy for us to handle the data and perform typical and complex tasks with a single line of code....

Load the Dataset

...

Computing ROC – AUC Score

We will use the iris datasets which is one of the most common benchmark dataset for the classification models. Let’s load this dataset using the sklearn.datasets....

Visualizing ROC Curve

...