To compute the micro-average ROC AUC, TPR, and FPR for a multiclass classification problem using scikit-learn, you can use the roc_auc_score function with the multi_class parameter set to 'ovr' or 'ovr_weighted', and the average parameter set to 'micro'.
Here's an example:
from sklearn.metrics import roc_auc_score
# assume y_true and y_score are your true labels and predicted scores
y_true = [1, 1, 2, 2, 3, 3]
y_score = [[0.9, 0.1, 0.2],
[0.8, 0.2, 0.3],
[0.1, 0.5, 0.4],
[0.2, 0.6, 0.2],
[0.3, 0.4, 0.3],
[0.4, 0.5, 0.1]]
# compute micro-average ROC AUC
micro_auc = roc_auc_score(y_true, y_score, multi_class='ovr', average='micro')
# compute micro-average TPR and FPR
micro_tpr, micro_fpr, thresholds = roc_curve(y_true, y_score, pos_label=None, drop_intermediate=False, multi_class='ovr', sample_weight=None)
# micro-average TPR and FPR are typically computed at a single threshold (e.g., the highest score)
best_threshold_idx = np.argmax(micro_tpr * (1 - micro_fpr))
best_threshold = thresholds[best_threshold_idx]
micro_tpr_at_best_threshold = micro_tpr[best_threshold_idx]
micro_fpr_at_best_threshold = micro_fpr[best_threshold_idx]
In this example, y_true and y_score are the true labels and predicted scores for a multiclass classification problem with 3 classes. The roc_auc_score function is used to compute the micro-average ROC AUC, with the multi_class parameter set to 'ovr' (one-vs-rest) and the average parameter set to 'micro'.
To compute the micro-average TPR and FPR, the roc_curve function is used with the same multi_class and average parameters. The roc_curve function returns the true positive rate (TPR), false positive rate (FPR), and threshold values at different operating points. To compute the micro-average TPR and FPR at a single threshold, you can choose the threshold that maximizes the product of TPR and (1 - FPR) (i.e., the point on the ROC curve that is closest to the top-left corner). In this example, the np.argmax function is used to find the index of the best threshold, and the TPR and FPR at that threshold are extracted using the index.
Note that the pos_label parameter in roc_curve is set to None to compute the TPR and FPR for all classes. If you want to compute the TPR and FPR for a specific class, you can set pos_label to the label of that class.