我正在學習如何使用scikit-learn開發反向傳播神經網絡。我仍然對如何在我的神經網絡中實現k-fold交叉驗證感到困惑。我希望你們能幫助我。我的代碼如下:在MLPClassification中實現K-fold交叉驗證Python
import numpy as np
from sklearn.model_selection import KFold
from sklearn.neural_network import MLPClassifier
f = open("seeds_dataset.txt")
data = np.loadtxt(f)
X=data[:,0:]
y=data[:,-1]
kf = KFold(n_splits=10)
X_train, X_test, y_train, y_test = X[train], X[test], y[train], y[test]
clf = MLPClassifier(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1)
clf.fit(X, y)
MLPClassifier(activation='relu', alpha=1e-05, batch_size='auto',
beta_1=0.9, beta_2=0.999, early_stopping=False,
epsilon=1e-08, hidden_layer_sizes=(5, 2), learning_rate='constant',
learning_rate_init=0.001, max_iter=200, momentum=0.9,
nesterovs_momentum=True, power_t=0.5, random_state=1, shuffle=True,
solver='lbfgs', tol=0.0001, validation_fraction=0.1, verbose=False,
warm_start=False)
我認爲你的意圖是你想做kfold分裂和得分。你可以使用['cross_val_score'](http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.cross_val_score.html)。它會爲你做Kfold,同時也會生成分數列表。 –