model = Sequential()
model.add(Dense(10, input_dim=cols, kernel_initializer='normal', activation='relu'))
model.add(Dense(1, kernel_initializer='normal'))
# Compile model
model.compile(loss='mse', optimizer='adam')
early_stop = EarlyStopping(monitor='val_loss', patience=20)
r_value_max = 0
train_samples_max = []
for i in range(0,1000):
X_train, X_test, y_train, y_test = train_test_split(inputs, outputs, train_size=11)
model.fit(X_train, y_train, epochs=100, batch_size=10, verbose=0, validation_split=0.2, callbacks=[early_stop])
ynew = model.predict(X_test)
tf.keras.backend.clear_session()
slope, intercept, r_value, p_value, std_err = stats.linregress(ynew[:,0],y_test)
print(r_value)
print(i)
if (r_value > r_value_max):
r_value_max = r_value
train_samples_max = X_train
print(r_value_max)
print(train_samples_max)
当我运行此循环时,r_value似乎随着每次迭代而稳步增加,我不确定为什么会这样。我尝试将模型创建放入循环中,并在每次迭代后删除模型,但这没有用。
谢谢。