小编Sai*_*van的帖子

无法在多标签分类器上使用 Stratified-K-Fold

以下代码用于进行 KFold 验证,但我要训练模型,因为它抛出错误

ValueError: Error when checking target: expected dense_14 to have shape (7,) but got array with shape (1,)
Run Code Online (Sandbox Code Playgroud)

我的目标变量有 7 个类。我正在使用LabelEncoder将类编码为数字。

通过看到此错误,如果我将其更改为MultiLabelBinarizer对类进行编码。我收到以下错误

ValueError: Supported target types are: ('binary', 'multiclass'). Got 'multilabel-indicator' instead.
Run Code Online (Sandbox Code Playgroud)

以下是KFold验证的代码

skf = StratifiedKFold(n_splits=10, shuffle=True)
scores = np.zeros(10)
idx = 0
for index, (train_indices, val_indices) in enumerate(skf.split(X, y)):
    print("Training on fold " + str(index+1) + "/10...")
    # Generate batches from indices
    xtrain, xval = X[train_indices], X[val_indices]
    ytrain, yval = y[train_indices], y[val_indices]
    model …
Run Code Online (Sandbox Code Playgroud)

scikit-learn cross-validation deep-learning keras

6
推荐指数
1
解决办法
6061
查看次数