Skip to content

DOC Fixed Plot Mnist Example#16200

Merged
thomasjpfan merged 4 commits intoscikit-learn:masterfrom
marimeireles:issue/14117
Apr 17, 2020
Merged

DOC Fixed Plot Mnist Example#16200
thomasjpfan merged 4 commits intoscikit-learn:masterfrom
marimeireles:issue/14117

Conversation

@marimeireles
Copy link
Copy Markdown
Contributor

@marimeireles marimeireles commented Jan 25, 2020

Fixes #14117
Fixes the warning about the MLPClassifier not being able to converge, now it does.

@adrinjalali, @noatamir

@marimeireles marimeireles changed the title Fixes #14117 The Plot Misnt Example now converges Jan 25, 2020
@marimeireles marimeireles changed the title The Plot Misnt Example now converges The Plot Mnist Example now converges Jan 25, 2020
@marimeireles marimeireles changed the title The Plot Mnist Example now converges Fixed Plot Mnist Example Jan 25, 2020
@adrinjalali
Copy link
Copy Markdown
Member

Could you also say how long it takes not to run the example, and what the output is compared to what's on master?

@marimeireles
Copy link
Copy Markdown
Contributor Author

Hi @adrinjalali

So this is my results after I made the model converge:
Figure_1
And it took 70.39416408538818 seconds.

Without any changes:
Figure_2
And it takes 28.29195475578308 seconds to run.

Which is pretty much expected, IMO. Since I had to increase the number of steps so it could converge.
Also, comparing the before and after they're somewhat alike. What do you think?
Is is good enough or should I try to make it more alike?

Thanks for the feedback :)

Copy link
Copy Markdown
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the CI, it takes already 1 minute. I don't think that we should increase this time. I think that we state in the example the following:

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.

Thus, I would improve the discussion stating that we don't let the neural-network converge (which will issue a warning).

y_train, y_test = y[:60000], y[60000:]

mlp = MLPClassifier(hidden_layer_sizes=(50,), max_iter=10, alpha=1e-4,
mlp = MLPClassifier(hidden_layer_sizes=(100,), max_iter=40, alpha=1e-4,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why increasing the number of hidden layers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked around the sprint and nobody could explain me why there was a 50 in the example so I decided it was better to just use the default in the docs.
No other reason, I can change it =)

Copy link
Copy Markdown
Member

@glemaitre glemaitre Jan 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to limit the complexity of the model to have a faster training from what I can see in the narration.

@marimeireles
Copy link
Copy Markdown
Contributor Author

If @adrinjalali doesn't see a problem with it than I'll do it.

@adrinjalali
Copy link
Copy Markdown
Member

Yeah we need to have it much faster than what it is now. It'll make the CI time out if we have a few of these slow examples. @glemaitre is also another core developer like me, you can trust him ;)

I'd say we can say in the example that for performance reasons we have it like this, and that it will raise a warning, and catch the warning in the code so that running the example doesn't show the warning.

Let us know if you need any help with any of that :)

@marimeireles
Copy link
Copy Markdown
Contributor Author

@adrinjalali haha it's not that I don't trust him, it's because I pinged and talked to you first.
Okay! I'll revert it and add a message.
Thanks for your input!

@glemaitre
Copy link
Copy Markdown
Member

Catching the warning could be a solution with a nice comment explaining why we do so. Beter to repeat ourself :)

@adrinjalali
Copy link
Copy Markdown
Member

You could also catch the warning the way we do it in plot_mlp_training_curves.py, with a comment:

        # some parameter combinations will not converge as can be seen on the
        # plots so they are ignored here
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=ConvergenceWarning,
                                    module="sklearn")
            mlp.fit(X, y)

@cmarmo
Copy link
Copy Markdown
Contributor

cmarmo commented Mar 2, 2020

@marimeireles the failing check could probably be solved by a synchronisation with upstream. Could you please do this? Thanks a lot!

@cmarmo
Copy link
Copy Markdown
Contributor

cmarmo commented Apr 15, 2020

Hi @marimeireles, hope you are doing well in those difficult times... are you still interested in finishing this PR? Thanks for the work you already did!

@marimeireles
Copy link
Copy Markdown
Contributor Author

Hey @cmarmo, thanks for reaching out again, I lost this in my backlog.
I'm fine! Hope you're okay too.
Lemme give a try on this now =)

@marimeireles marimeireles requested a review from glemaitre April 16, 2020 17:37
Copy link
Copy Markdown
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @marimeireles !

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
constringements.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean the following?

Suggested change
constringements.
constraints.

solver='sgd', verbose=10, random_state=1,
learning_rate_init=.1)

# this example won't converge because of CI's constrigements, so we catch the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean the following?

Suggested change
# this example won't converge because of CI's constrigements, so we catch the
# this example won't converge because of CI's time constraints, so we catch the

Comment on lines 49 to 53
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=ConvergenceWarning,
module="sklearn")

mlp.fit(X_train, y_train)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fit needs to be indented to catch

Suggested change
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=ConvergenceWarning,
module="sklearn")
mlp.fit(X_train, y_train)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=ConvergenceWarning,
module="sklearn")
mlp.fit(X_train, y_train)

@marimeireles
Copy link
Copy Markdown
Contributor Author

Would you like me to rebase these commits?

@cmarmo
Copy link
Copy Markdown
Contributor

cmarmo commented Apr 17, 2020

Would you like me to rebase these commits?

Thanks @marimeireles! No need to rebase: core-devs will stash the commits when merging.
@scikit-learn/core-devs, this is the last example to solve #14117: someone available for reviewing? Thanks!

Copy link
Copy Markdown
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks @marimeireles

Copy link
Copy Markdown
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @marimeireles !

@thomasjpfan thomasjpfan changed the title Fixed Plot Mnist Example DOC Fixed Plot Mnist Example Apr 17, 2020
@thomasjpfan thomasjpfan merged commit 269afa3 into scikit-learn:master Apr 17, 2020
gio8tisu pushed a commit to gio8tisu/scikit-learn that referenced this pull request May 15, 2020
viclafargue pushed a commit to viclafargue/scikit-learn that referenced this pull request Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix warnings in examples

5 participants