python - 仅在 max_iter 之后停止训练 MLPRegressor (solver=lbfgs),而不是因为 "tol"

标签 python scikit-learn neural-network

我正在使用求解器 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/

相关文章:

python - 毫秒到 HH :MM:SS time format

python - 如果 PyModule_Add* 函数失败,C 扩展是否应该在模块初始化中失败?

python - Discord 机器人踢命令

python - scikit-learn 分割数据集中的随机状态

machine-learning - 神经网络中的反向传播和前向传播

machine-learning - 神经网络作为通用逼近器

python - 如何用 Python 解决僵硬的问题?

python - 使用OLS基础学习者进行梯度提升

python - 将训练数据拆分为每个类的相同行数

python - 神经网络识别手写数字: Dealing with multiple outputs