jpmuc
jpmuc

Reputation: 1154

Writing scikit-learn tests for own classifier

I am writing my own classifier for novelty detection with scikit-learn. Now, in order to be able to use it seamlessly within the framework, I need it to pass the check_estimator() test.

My problem is that my classifier only returns two labels (either 0 or 1, depending on whether it consider the input to correspond to an outlier or not).

But then the test check_classifiers_classes() in utils/estimator_checks.py fails because it expects the classifier to return more than two classes. What is the proper way to implement/test a novelty detector in scikit-learn?

Upvotes: 2

Views: 223

Answers (1)

You should add a method in your classifier to tell sklearn that is a binary classifier

def _more_tags(self) -> dict:
    return {"binary_only": True}

Upvotes: 0

Related Questions