Sklearn StratifiedKFold: ValueError: Supported target types are: ('binary', 'multiclass'). Got 'multilabel-indicator' instead

前端 未结 4 2155
攒了一身酷
攒了一身酷 2020-12-17 08:36

Working with Sklearn stratified kfold split, and when I attempt to split using multi-class, I received on error (see below). When I tried and split using binary, it works n

4条回答
  •  感动是毒
    2020-12-17 08:48

    keras.utils.to_categorical produces a one-hot encoded class vector, i.e. the multilabel-indicator mentioned in the error message. StratifiedKFold is not designed to work with such input; from the split method docs:

    split(X, y, groups=None)

    [...]

    y : array-like, shape (n_samples,)

    The target variable for supervised learning problems. Stratification is done based on the y labels.

    i.e. your y must be a 1-D array of your class labels.

    Essentially, what you have to do is simply to invert the order of the operations: split first (using your intial y_train), and convert to_categorical afterwards.

提交回复
热议问题