# How to compute AUC in gridsearchSV (multiclass problem)

I'm working on a multiclass classification problem, comparing results from SVM and Random Forest classificators. I would like to use gridsearchCV for hyperparameters tuning and find that AUC is the most used metrics for this kind of problem.

I know how to use other metrics of scoring like accuracy etc. but the default ROC_AUC only works for binary class. Is there a method to use AUC in gridsearchCV for multiclass problems?

sklearn's roc_auc_score actually does handle multiclass and multilabel problems, with its average and multiclass parameters. The default average='macro' is fine, though you should consider the alternative(s). But the default multiclass='raise' will need to be overridden. To use that in a GridSearchCV, you can curry the function, e.g.

import functools

multiclass_roc_auc = functools.partial(roc_auc_score, multiclass='ovr')
search = GridSearchCV(estimator=...,
eval=multiclass_roc_auc,
...)

• I fixed my problem by defining my multiclass_roc_auc function. Your solution is very helpful and slightly shorter, thanks a lot! – okraw May 11 '20 at 15:29

Metrics are independent from ML algorithms, so it doesn't matter which algorithms did you use.

To calculate multiclass AUC you could use lib pRoc in R or use code this link(in Python).

Sources:

• I mean the evaluation metrics that the GridsearchCV function uses to find best params – okraw Apr 4 '20 at 18:38