python - 仅在 max_iter 之后停止训练 MLPRegressor (solver=lbfgs) 而不是因为“tol”
问题描述
我正在MLPRegressor
使用求解器训练模型lbfgs
。我已将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,因为它们超过了我在 500 中指定的max_iter
)
解决方案
该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 - 正确使用多处理
- arm64 - M1 Mac 上的 PostSharp 支持 (linux-arm64)
- bitlocker - 使用脚本更改密码 Bitlocker
- algorithm - 依次插入n个随机元素构建二叉搜索树的下界时间
- android - 清单活动未启动
- tensorflow - 如何在 Tensorflow 中加载数据集及其标签?
- java - 在 gradle 文件 android 中为 HTTP 添加什么依赖项;ByteArrayBody、HttpMultipartMode、StringBody 无法解析
- google-apps-script - 对于肯定存在的床单,一直保持错误
- javascript - form.submit(); 不运行形式的动作
- r - “无效的参数类型”通过函数的参数传递 html 颜色