Skip to content

cross_val_score can't take scoring parameters without a custom scoring function #5308

Closed
@bjlange

Description

@bjlange

When using cross_val_score, one can choose an averaging method easily using the various scoring presets. But if they want to choose a pos_label like those taken by f1, precision, and recall (to specify scoring with respect to a specific class), they have to define a custom scoring function like this:

def precision_class_2(estimator, X, y):
    y_pred = estimator.predict(X)
    return metrics.precision(y, y_pred, pos_label=2)

cross_val_score(estimator, X, y=None, scoring=precision_class_2)

This obviously isn't that big of a deal, but it would be nice to be able to pass scoring parameters into the function the same way you can pass fit parameters. Like:

cross_val_score(estimator, X, y=None, scoring='precision', scoring_params={'pos_label':2})

I'm happy to contribute code for this but wanted to open an issue first and see what others think/if I'm barking up the wrong tree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions