StratifiedKFold: ValueError: Supported target types are: ('binary', 'multiclass'). Got 'multilabel-indicator' instead 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 no problem.

num_classes = len(np.unique(y_train))
y_train_categorical = keras.utils.to_categorical(y_train, num_classes)
kf=StratifiedKFold(n_splits=5, shuffle=True, random_state=999)


splitting data into different folds

for i, (train_index, val_index) in enumerate(kf.split(x_train, y_train_categorical)):
   x_train_kf, x_val_kf = x_train[train_index], x_train[val_index]
   y_train_kf, y_val_kf = y_train[train_index], y_train[val_index]

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


Is there a way I can used KFold with multi-class?
I had the same problem, you can find my detailed answer here.

Basically, KFold does not recognize your target as multi-class because it relies on these definitions:


  
  'binary': y contains &lt;= 2 discrete values and is 1d or a column
  vector.
  'multiclass': y contains more than two discrete values, is not a
  sequence of sequences, and is 1d or a column vector.
  'multiclass-multioutput': y is a 2d array that contains more
  than two discrete values, is not a sequence of sequences, and both
  dimensions are of size > 1.
  'multilabel-indicator': y is a label indicator matrix, an array
  of two dimensions with at least two columns, and at most 2 unique
  values.