Search code examples
scikit-learnhamming-distance

hamming_loss not support in cross_val_score?


I am using sklearn and skmultilearn to do some research about multilabel.

I was just wondering that why the hamming_loss can not be used in cross_val_score, since it can really be used alone.


Solution

  • In the documentation of cross_val_score, it is specified that:

    scoring : string, callable or None, optional, default: None

    A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).

    The strings that can be used in this are specified in section 3.3.1.1 here. These strings showed here are internally converted to scoring function objects using the make_scorer

    The hamming_loss is not in those strings, but we can use make_scorer on it to define our scoring function object, which can then be used in cross_val_score()

    Use it like this:

    from sklearn.metrics import make_scorer
    output_scores = cross_val_score(lasso, X, y, scoring = make_scorer(hamming_loss,greater_is_better=False))