Computing ROC – AUC Score
Now let’s calculate the ROC – AUC score for the predictions made by the model using the one v/s all method.
Python3
model = OneVsRestClassifier(LogisticRegression(random_state = 0 ))\ .fit(train_X, train_y) prob_test_vec = model.predict_proba(test_X) n_classes = 3 fpr = [ 0 ] * 3 tpr = [ 0 ] * 3 thresholds = [ 0 ] * 3 auc_score = [ 0 ] * 3 for i in range (n_classes): fpr[i], tpr[i], thresholds[i] = roc_curve(test_y[:, i], prob_test_vec[:, i]) auc_score[i] = auc(fpr[i], tpr[i]) auc_score |
Output:
[1.0, 0.8047138047138047, 1.0]
The AUC score with Setosa as positive class is 1, with Versicolour as positive class is 0.805, and with Virginica as positive class is 1.
After taking the average we get 93.49% accuracy.
Python3
sum (auc_score) / n_classes |
0.9349046015712682
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).