An unknown error occurred when performing stratified cross-validation. How can I improve it?

Error message
ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead.
Applicable source code
# Definition of objective and explanatory variables
x_train = train.iloc [:, [0,1,3,4,5,6,7,8,9]]
y_train = train ['kpl']
x_test = test
# Cross-validation by k division by stratification method
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import cross_val_score
kf = StratifiedKFold (n_splits = 3, shuffle = True, random_state = 1)
lr = LinearRegression ()
print (cross_val_score (lr, x_train, y_train, cv = kf))

Rechecked the contents of x_train and y_train.

Supplemental information (FW/tool version etc.)

Please provide more detailed information here.

  • Answer # 1


    ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead.

    Since the error message in the question text is excerpted, it includes the following speculation (because it is better to post the full text from the first line of Traceback, please do so in the next question)

    Probably an exception thrown from insideStratifiedKFold. It is an error that stratification is not possible with a continuous target

    In the meantime, replacing it withKFoldwill solve it.

    sklearn.model_selection.KFold — scikit-learn 0.21.3 documentation