StratifiedKFold错误地分割数据

时间:2019-05-13 05:05:04

标签: python scikit-learn cross-validation

我将this数据读入一个numpy数组并将其拆分为折叠。数据包含27,558张图像。 (已感染13779-未感染13779)。但是当我拟合模型并对其进行评估时,classification_report说:

  • 13781被感染(0),
  • 13779(1)未感染。

classification_report

我使用了classification_report,因为所有的折痕都连接在一起了。这是我使用的方法:

originalclass = []
predictedclass = []

kfold = StratifiedKFold(n_splits = folds, shuffle = True, random_state = random_state)

for train_index, test_index in kfold.split(data, labels):
    fold_num = fold_num + 1

    x_train, x_test = data[train_index], data[test_index]
    y_train, y_test = labels[train_index], labels[test_index]
    y_train = np_utils.to_categorical(y_train, num_classes = classes)
    y_test = np_utils.to_categorical(y_test, num_classes = classes)

    model = CNNbuild(optimizer =  "Adam", activation = "softmax")

    histAdam[str(fold_num)] = model.fit(x_train, y_train, epochs = epochs, batch_size = batch_size, validation_data=(x_test, y_test))

    originalclass.extend(y_test)
    predictedclass.extend(model.predict(x_test))

y_predB = np.argmax(predictedclass, axis=1)
y_testB = np.argmax(originalclass, axis=1)
print(classification_report(y_testB, y_predB, target_names=target_names))

0 个答案:

没有答案