简体   繁体   中英

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?

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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM