Skip to content

Commit

Permalink
DOC Changed layer number and learning rate init to make execution of …
Browse files Browse the repository at this point in the history
…plot_mnist_filters.py quicker (scikit-learn#21647)

* Changed layer number and learning rate init to make execution of example faster

* Update plot_mnist_filters.py

* Update plot_mnist_filters.py

* Update plot_mnist_filters.py

* Update plot_mnist_filters.py
  • Loading branch information
Sven Eschlbeck authored Nov 23, 2021
1 parent 4dfaaf9 commit 11222e0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions examples/neural_networks/plot_mnist_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,45 @@
MLPClassifier trained on the MNIST dataset.
The input data consists of 28x28 pixel handwritten digits, leading to 784
features in the dataset. Therefore the first layer weight matrix have the shape
features in the dataset. Therefore the first layer weight matrix has the shape
(784, hidden_layer_sizes[0]). We can therefore visualize a single column of
the weight matrix as a 28x28 pixel image.
To make the example run faster, we use very few hidden units, and train only
for a very short time. Training longer would result in weights with a much
smoother spatial appearance. The example will throw a warning because it
doesn't converge, in this case this is what we want because of CI's time
constraints.
doesn't converge, in this case this is what we want because of resource
usage constraints on our Continuous Integration infrastructure that is used
to build this documentation on a regular basis.
"""

import warnings

import matplotlib.pyplot as plt
from sklearn.datasets import fetch_openml
from sklearn.exceptions import ConvergenceWarning
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split

# Load data from https://www.openml.org/d/554
X, y = fetch_openml("mnist_784", version=1, return_X_y=True)
X = X / 255.0

# 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:]
# Split data into train partition and test partition
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0, test_size=0.7)

mlp = MLPClassifier(
hidden_layer_sizes=(50,),
max_iter=10,
hidden_layer_sizes=(40,),
max_iter=8,
alpha=1e-4,
solver="sgd",
verbose=10,
random_state=1,
learning_rate_init=0.1,
learning_rate_init=0.2,
)

# this example won't converge because of CI's time constraints, so we catch the
# warning and are ignore it here
# this example won't converge because of resource usage constraints on
# our Continuous Integration infrastructure, so we catch the warning and
# ignore it here
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=ConvergenceWarning, module="sklearn")
mlp.fit(X_train, y_train)
Expand Down

0 comments on commit 11222e0

Please sign in to comment.