我正在使用求解器 lbfgs
使用 MLPRegressor
训练模型。我已将 max_iter
参数从默认的 200 更改为 500。我想强制训练继续进行 500 次迭代,并且当损失没有改善至少 tol
时不要停止>。
我已经尝试将 tol 设置为 0.0,然后继续将其设置为负值(例如 -10)
mymodel = mlpr(hidden_layer_sizes=(3,), activation = 'tanh', solver =
'lbfgs',max_iter=500, tol=0.0, verbose=True)
for i in range(99):
mymodel = mymodel.fit(xtrain,ytrain)
print("The number of iterations ran was: ",mymodel.n_iter_)
这就是我得到的:
The number of iterations ran was: 56
The number of iterations ran was: 162
The number of iterations ran was: 154
The number of iterations ran was: 169
The number of iterations ran was: 127
The number of iterations ran was: 40
The number of iterations ran was: 501
The number of iterations ran was: 501
The number of iterations ran was: 502
The number of iterations ran was: 198
我预计每次都会有 500 次迭代。 (甚至不是 501 或 502,因为它们超过了我在 max_iter
中指定的 500)
最佳答案
tol
参数指定优化的容差。如果损失或分数没有改善至少 tol
,当达到收敛时,训练被认为完成。尝试设置tol
参数None
,如其所示 -infinity
,因此训练不会停止,直到 max_iter
已达到。
mymodel = mlpr(hidden_layer_sizes=(3,), activation = 'tanh', solver =
'lbfgs',max_iter=500, tol=None, verbose=True)
关于python - 仅在 max_iter 之后停止训练 MLPRegressor (solver=lbfgs),而不是因为 "tol",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55988440/