【发布时间】:2020-02-08 10:26:07
【问题描述】:
我正在构建一个 CNN 模型来对数据进行分类,并且正在研究使用 Scikit-Learn 进行交叉验证。我正在使用两个输入,并且想知道如何使用两个输入进行交叉验证。
据我所知,它只接受 X 输入和 y 输出,并尝试使用输入列表,但它们被读取为单个列表。
我已使用以下代码遍历一个模型并对其进行交叉验证,但是我没有看到任何使用两个输入进行交叉验证的方法。
np.random.seed(seed)
kfold = StratifiedKfold(n_splits=10m shuffle=True, random_state=seed)
for train, test in kfold.split(x, y):
input = Input(shape=(100, 150, 1))
dense = Dense(2, activation='relu')(input)
output = Dense(1, activation='relu')(dense)
model = Model(input, output)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X[train], Y[train], epochs=150, batch_size=10, verbose=0)
scores = model.evaluate(X[test], Y[test], verbose=0)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
cvscores.append(scores[1] * 100)
print("%.2f%% (+/- %.2f%%)" % (numpy.mean(cvscores), numpy.std(cvscores)))
【问题讨论】:
标签: tensorflow machine-learning keras scikit-learn