收敛警告:随机优化器:已达到最大迭代次数 (10) 且优化尚未收敛 [英] ConvergenceWarning: Stochastic Optimizer: Maximum iterations (10) reached and the optimization hasn't converged yet

查看:287
本文介绍了收敛警告:随机优化器:已达到最大迭代次数 (10) 且优化尚未收敛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sklearn 撰写有关在 MNIST 数据集上训练中立工作的文章.为什么优化器没有收敛?还可以做些什么来提高我输入的准确性?

I am trying sklearn to write about the training of a neutral_work on MNIST datasets. Why the optimizer did not converge? What else can be done to increase the accuracy which I get in?

import matplotlib.pyplot as plt
from sklearn.datasets import fetch_openml
from sklearn.neural_network import MLPClassifier

print(__doc__)

# load data from http://www.openml.org/d/d554
X, y = fetch_openml('mnist_784', version=1, return_X_y=True)
X = X / 255.

# rescale the data. use the traditional train/test split
X_train, X_test = X[:60000], X[60000:]
y_train, y_test = y[:60000], y[60000:]

# mlp = MLPClassifier(hidden_layer_sizes=(100, 100), max_iter=400, alpha=1e-4,
#                    solver='sgd' , verbose=10, tol=14-4, random_state=1)
mlp = MLPClassifier(hidden_layer_sizes=(50,), max_iter=10, alpha=1e-4,
                    solver='sgd', verbose=10, tol=1e-4, random_state=1,
                    learning_rate_init=.1)

mlp.fit(X_train, y_train)
print("Training set score: %f" % mlp.score(X_train, y_train))
print("Test set score: %f" % mlp.score(X_test, y_test))

fig, axes = plt.subplots(4, 4)
# use global min/max to ensure all weights are shown on the same scale
vmin, vmax = mlp.coefs_[0].min(), mlp.coefs_[0].max()
for coef, ax in zip(mlp.coefs_[0].T, axes.ravel()):
    ax.matshow(coef.reshape(28, 28), cmap=plt.cm.gray, vmin=.5 * vmin,
               vmax=.5 * vmax)
    ax.set_xticks(())
    ax.set_yticks(())

plt.show()

推荐答案

"ConvergenceWarning: Stochastic Optimizer: 已达到最大迭代次数 (10),但优化尚未收敛.收敛警告)"

"ConvergenceWarning: Stochastic Optimizer: Maximum iterations (10) reached and the optimization hasn't converged yet. ConvergenceWarning)"

收敛点是机器学习模型的局部最优状态.它基本上意味着模型中的变量具有最佳可能值(在某个附近),以便根据另一组特征预测目标特征.在多层感知器 (MLP) 中,这些变量是每个神经元内的权重.通常,当数据集不代表有组织且可辨别的模式时,机器学习算法可能无法找到收敛点.但是,如果存在收敛点,机器学习模型会尽力找到它.为了训练 MLP,您需要多次迭代网络中的数据集,以便其权重找到收敛点.您还可以限制迭代次数以限制处理时间或作为正则化工具.

A convergence point is a machine learning models localized optimal state. It basically means that the variables within the model have the best posible values (Within a certain vicinity) in order to predict a target feature based on another set of features. In a Multi-layer perceptron (MLP), these variables are the weights within each neuron. Generally, when a data set doesn't represent a organized and discernable pattern, machine learning algorithms might not be able to find a convergence point. However, if there is a convergence point, a machine learning model will do its best to find it. In order to train a MLP you need to iterate a data set within the network many times in order for its weights to find a convergence point. You can also limit the amount of iterations in order to limit processing time or as a regularization tool.

在您的代码示例中,您有 2 个 MLP 模型,但我将重点关注未注释的代码段:

In your code example you have 2 MLP models, however I'll focus on the snippet that isn't commented:

mlp = MLPClassifier(hidden_layer_sizes=(50,), max_iter=10, alpha=1e-4,solver='sgd', verbose=10, tol=1e-4, random_state=1,learning_rate_init=.1)

有几个参数可能会影响模型收敛所需的迭代次数,但是您可以做出的最简单的更改是增加最大迭代次数,例如将其设置为 max_iter=100 或任何其他需要的更大价值.

There are several parameters that could influence the amount of iterations the model would need in order to converge, however the simplest change you could make is increasing the maximum amount of iterations, for example setting it to max_iter=100 or any other needed greater value.

但是,这个机器学习模型中可能存在更深层次的问题.MNIST 数据集是一组书写的字符图像.MLP 是一种高度灵活的机器学习模型,然而,它可能不是计算机视觉和图像分类的合适模型.使用 MLP 可能会得到一些积极的结果,使用卷积神经网络可能会得到更好的结果,它们基本上是非常花哨的 MLP.

However, there might be a deeper issue in this machine learning model. The MNIST data set is a set of written character images. MLP is a highly flexible machine learning model, nevertheless, it might not be an adequate model for computer vision and image classification. You might get some positive results with MLP, you might get even better results with Convolutional Neural Networks, which are basically really fancy MLPs.

这篇关于收敛警告:随机优化器:已达到最大迭代次数 (10) 且优化尚未收敛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆