コード例 #1
0
# k-Fold Cross validation
kf = KFold(n_splits=splits, shuffle=True)
for i, (train_index, test_index) in enumerate(kf.split(x)):
    x_train, x_test = x[train_index], x[test_index]
    y_train, y_test = y[train_index], y[test_index]

    _cost, _accuracy = nnet.train(x_train,
                                  y_train,
                                  epochs=epochs,
                                  alpha=alpha,
                                  reg_para=reg_para,
                                  batch_size=batch_size,
                                  print_details=False,
                                  epochs_bw_details=epochs_bw_details,
                                  dropout=dropout_percent,
                                  dropout_layers=d_layers)

    op = nnet.predict(x_test)

    cumulative_acc += nnet.evaluate(op, y_test)
    print("-" * 30 + "\nKFold #{0}\n".format(i) + "-" * 30)
    print(classification_report(y_test.argmax(axis=1), op.argmax(axis=1)))
    print()

print("Mean cross validation accuracy = {0}".format(cumulative_acc / splits))

s = input("Dump model? (y/n)\n")
if s == 'y':
    nnet.dump()