Scikit-learn TypeError: If no scoring is specified, the estimator passed should have a 'score' method

前端 未结 1 1764
执念已碎
执念已碎 2020-12-12 03:08

I have created a custom model in python using scikit-learn, and I want to use cross validation.

The class for the model is defined as follows:

clas         


        
1条回答
  •  一生所求
    2020-12-12 03:48

    The easiest way to make the error go away is to pass scoring="accuracy" or scoring="hamming" to cross_val_score. The cross_val_score function itself doesn't know what kind of problem you are trying to solve, so it doesn't know what an appropriate metric is. It looks like you are trying to do multi-label classification, so maybe you want to use the hamming loss?

    You can also implement a score method as explained in the "Roll your own estimator" docs, which has as signature def score(self, X, y_true). See http://scikit-learn.org/stable/developers/#different-objects

    By the way, you do know about the OneVsRestClassifier, right? It looks a bit like you are reimplementing it.

    0 讨论(0)
提交回复
热议问题