<jupyter_start><jupyter_text>ROC and AUC for Multiclass Classification<jupyter_code># print(type(y_test))
def multi_class_roc(y_test,predictions,nc):
#     print(y_test,predictions)
    roc_list = []
    auc_list = []
    for i in range(nc):
        tempy = y_test
        ptemp = pd.DataFrame(predictions)
        tempy = tempy.replace(i,-1)
        ptemp = ptemp.replace(i,-1)
        for j in range(nc):
            tempy = tempy.replace(j,0)
            ptemp = ptemp.replace(j,0)
        tempy = tempy.replace(-1,1)
        ptemp = ptemp.replace(-1,1)
#         print(tempy,ptemp)
        fpr,tpr,thresholds = metrics.roc_curve(tempy,ptemp)
        ras = metrics.roc_auc_score(tempy,ptemp)
        roc_list.append([fpr,tpr])
        auc_list.append(ras)
    return roc_list,auc_list
rl,al = multi_class_roc(y_test,predictions,3)
rl
import matplotlib.pyplot as plt
j = 0
for i in rl:
    print("ROC Curve for Class",j," VS All Others")
    j+=1
    plt.plot(i[0], i[1], marker='.')
    plt.show()
al<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13165537270087124, 'fraction_numerical': 0.012584704743465635, 'mean_word_length': 2.9166666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '658305', 'license': 'MIT', 'n_tokens_mistral': 408, 'n_tokens_neox': 398, 'n_words': 71, 'path': 'Multiclass Classification/Multiclass Classification - ROC, AUC, Confusion Matrix.ipynb', 'repo_name': 'mayank-kumar-giri/Machine-Learning-Coursework', 'size': '1033'}