DOC Fixed Plot Mnist Example
@@ -18,10 +18,16 @@ 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.
+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.
"""
+
+import warnings
+
import matplotlib.pyplot as plt
from sklearn.datasets import fetch_openml
+from sklearn.exceptions import ConvergenceWarning
from sklearn.neural_network import MLPClassifier
print(__doc__)
@@ -38,7 +44,13 @@ mlp = MLPClassifier(hidden_layer_sizes=(50,), max_iter=10, alpha=1e-4,
solver='sgd', verbose=10, random_state=1,
learning_rate_init=.1)
+# this example won't converge because of CI's time constraints, so we catch the
+# warning and are ignore it here
+with warnings.catch_warnings():
+ warnings.filterwarnings("ignore", category=ConvergenceWarning,
+ module="sklearn")
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))
