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

烈酒焚心 提交于 2019-12-02 12:57:42

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!