[Python] How to use GridSearchCV with a custom scoring metric in a classification problem?

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I want to use GridSearchCV to tune hyperparameters for a classifier, but I also want to use a custom scoring function that gives higher weight to recall. How can I implement this properly in scikit-learn?

    from sklearn.metrics import make_scorer, recall_score

    def custom_score(y_true, y_pred):
    return recall_score(y_true, y_pred) * 1.5

    scorer = make_scorer(custom_score)


    Is this the correct way to pass a weighted scoring function?
    Do I need to define greater_is_better?

    Continue reading...

Compartilhe esta Página