Skip to content

Update plot_compare_reduction.py#10394

Merged
lesteve merged 1 commit intoscikit-learn:masterfrom
krazedkrish:patch-1
Jan 4, 2018
Merged

Update plot_compare_reduction.py#10394
lesteve merged 1 commit intoscikit-learn:masterfrom
krazedkrish:patch-1

Conversation

@krazedkrish
Copy link
Copy Markdown
Contributor

@krazedkrish krazedkrish commented Jan 3, 2018

Misplaced plt.show(), fixed.

Like me a few scikit-learn newbies might be wondering where is the graph 😁 .

Reference Issues/PRs

What does this implement/fix? Explain your changes.

A graph is supposed to be showen in the example: of Selecting dimensionality reduction with Pipeline and GridSearchCV. But it does not show due to misplaced plt.show()

Misplaced plt.show(), fixed.

Like me a few scikit-learn newbies might be wondering where is the graph 😁 .
@krazedkrish
Copy link
Copy Markdown
Contributor Author

Thanks for this awesome library and wonderful tutorials! :-D

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Jan 3, 2018

I am pretty sure the example works fine as it is.

Is the problem that you copied and pasted bits of code from http://scikit-learn.org/stable/auto_examples/plot_compare_reduction.html and that basically the plt.plot() stands a bit on its own at the end of the example and can be easily forgotten?

I would say:

  • either we do not do anything. After all downloading the code via the download button is probably the recommended way of getting the full code.
  • maybe as an intermediary solution, we can move plt.plot to the previous code cell. I am not really convinced to be honest. In general plt.show() is at the end of our example (not in each code cell). Also it's probably a good idea to use ipython --matplotlib when copying and pasting code in an interactive console, so you don't have to use plt.show.

Copy link
Copy Markdown
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

I don't think show needs to be at the end (rather than elsewhere). Why is this change bad, @lesteve

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Jan 3, 2018

I just think plt.show() tend to be at the end of most examples and I'd rather leave it there because:

  • it is easy to add more code afterwards and forget to move plt.plot
  • if I guessed the use case right (waiting for @krazedkrish's answer on this one), I don't think there is any guarantee that copying and pasting code blocks from an example will produce the plots. In other words, I don't think we should have a plt.plot at the end of each code block just to be nice to this use case.

@krazedkrish
Copy link
Copy Markdown
Contributor Author

krazedkrish commented Jan 3, 2018

@lesteve, you are right the code runs well as it is now. I suggest the change for the sake of presentations in http://scikit-learn.org/stable/auto_examples/plot_compare_reduction.html.

You can see in the screenshot that there are two headings:

  • Illustration of Pipeline and GridSearchCV
  • Caching transformers within a Pipeline

Giving the impression that each can be run independently. But you can see in the screenshot that plt.show() is below the second Heading, which might leave the readers reading only Caching transformers within a Pipeline what is plt.show() doing out of no where.

2018-01-04-095941_446x827_scrot

2018-01-04-100337_629x913_scrot

The current structure is also ok with me, and reasons pointed by @lesteve are perfectly valid. My only point is the presentation.

Thanks!
🙂

@krazedkrish
Copy link
Copy Markdown
Contributor Author

Since the main heading is Selecting dimensionality reduction with Pipeline and GridSearchCV, but second heading Caching transformers within a Pipeline has loose connection with the main heading, I believe a better solution would be to have the examples in separate pages, in future edits. That way all @lesteve's points will be preserved and will also be presentably good.

What do you guys say?

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Jan 4, 2018

I am going to merge this one, because I don't think it is worth spending too much discussing it. What I want to make clear: problems like the one reported in this issue is a slightly negative side-effect of using a notebook-like example. I don't think there is much we can (or even should) do about it. In particular I don't think it is worth modifying other examples.

All in all I don't think it impacts most of our users:

  • a lot of them probably use a Jupyter notebook with %matplotlib inline or a IPython console with --matplotlib
  • or they know about plt.show

@lesteve lesteve merged commit f1fa2ed into scikit-learn:master Jan 4, 2018
@lesteve
Copy link
Copy Markdown
Member

lesteve commented Jan 4, 2018

Merged, thanks a lot @krazedkrish!

Note: the CircleCI ipython 2 error was a glitch with the mldata website.

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Jan 4, 2018

FWIW a binder integration has been merged into sphinx-gallery master so that for beginners this may be the best way to run the example (as long as they are familiar with the Jupyter notebook). Look at https://sphinx-gallery.github.io/auto_examples/plot_seaborn.html#sphx-glr-auto-examples-plot-seaborn-py for example and click on the binder button at the bottom of the example.

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.

3 participants