【发布时间】:2019-07-20 07:33:13
【问题描述】:
以下代码用于进行 KFold 验证,但我要在模型抛出错误时对其进行训练
ValueError: Error when checking target: expected dense_14 to have shape (7,) but got array with shape (1,)
我的目标变量有 7 个类。我正在使用LabelEncoder 将类编码为数字。
通过看到此错误,如果我将 MultiLabelBinarizer 更改为对类进行编码。我收到以下错误
ValueError: Supported target types are: ('binary', 'multiclass'). Got 'multilabel-indicator' instead.
以下是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 = None
model = load_model() //defined above
scores[idx] = train_model(model, xtrain, ytrain, xval, yval)
idx+=1
print(scores)
print(scores.mean())
我不知道该怎么办。我想在我的模型上使用分层 K 折叠。请帮帮我。
【问题讨论】:
标签: keras scikit-learn deep-learning cross-validation