Skip to content

[Python] Predicted target type is string but is expected to be boolean #1954

@memo26167

Description

@memo26167

Problem: The training target is boolean and the predicted target is string. When calling the score method, it throws an error.
catboost version: 1.0.3
Operating System: Windows 10
CPU: -
GPU: -

from catboost import CatBoostClassifier
import numpy as np

clf = CatBoostClassifier(silent=True)
clf.fit(np.array([[0,1,2],[2,3,4]]), np.array([[True],[False]]))
print(clf.predict(np.array([[0,1,2],[2,3,4]])))

clf.score(np.array([[0,1,2],[2,3,4]]), np.array([[True],[False]]))

Throwing the following error

CatBoostError                             Traceback (most recent call last)
----> 1 clf.score(np.array([[0,1,2],[2,3,4]]), np.array([[True],[False]]))

\my_env\lib\site-packages\catboost\core.py in score(self, X, y)
   5032                 raise CatBoostError('predicted classes have string type but specified y is numeric')
   5033             elif np.issubdtype(y.dtype, np.bool_):
-> 5034                 raise CatBoostError('predicted classes have string type but specified y is boolean')
   5035         return np.mean(np.array(predicted_classes) == np.array(y))
   5036 

CatBoostError: predicted classes have string type but specified y is boolean

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions