8000 [MRG+1] Refactoring plot_iris svm example. by lemonlaug · Pull Request #8279 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] Refactoring plot_iris svm example. #8279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 23, 2017

Conversation

lemonlaug
Copy link
Contributor
@lemonlaug lemonlaug commented Feb 3, 2017

What does this implement/fix? Explain your changes.

This refactors without in any way changing the outcome of the code in the "Plot different SVM classifiers in the iris dataset" example.

A couple of features of the current state of affairs that are motivating:

  1. It mixes the concerns of model fitting, predicting and plot making, which in my experience makes it both hard to comprehend, and difficult to reuse in other applications.
  2. It demonstrates a couple of less-than-best practices, such as:
  • Using enumerate where zip would be more appropriate.
  • Some repeated code, such as slicing columns of X, fitting, restating names of models.
  1. It uses the matplotlib state machine interface rather than the object-oriented interface and stretches that interface about as far as it ought to be stretched, making the code unsuitable to serve as the basis for extension or reuse.

I've addressed the concerns by switching to OO interface for matplotlib and by trying to follow some best practices, most notably by using the function signature recommended by matplotlib.

Any other comments?

I think this is important, because it's one of the chief ways people learn about both sklearn and matplotlib, so demonstrating best practices can have a positive effect for people with limited exposure to both packages--those who are most likely to be cribbing from examples.

If this is considered to be an improvement, would love to give more of the examples the same treatment.

@lemonlaug lemonlaug changed the title [WIP] Refactoring Plotting Examples [MRG] Refactoring Plotting Examples Feb 3, 2017
@lemonlaug lemonlaug changed the title [MRG] Refactoring Plotting Examples [MRG] Refactoring plot_iris svm example. Feb 6, 2017
@lemonlaug
Copy link
Contributor Author

@ogrisel, it looks like you were the last one to do a similar revision to this example.

Copy link
Member
@TomDLT TomDLT left a comment

Choose a reason for hiding this comment

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

Pretty clean, I like it. Indeed it does not change the result.
LGTM

Parameters
----------
ax: matplotlib axes object
clf: a classifier
Copy link
Member

Choose a reason for hiding this comment

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

a fitted classifier

@TomDLT TomDLT changed the title [MRG] Refactoring plot_iris svm example. [MRG+1 Refactoring plot_iris svm example. Feb 10, 2017
@TomDLT TomDLT changed the title [MRG+1 Refactoring plot_iris svm example. [MRG+1] Refactoring plot_iris svm example. Feb 10, 2017
@tguillemot
Copy link
Contributor

capture du 2017-02-13 16-45-48

@lemonlaug Is-it possible to add black contours at each circle ?

@lemonlaug
Copy link
Contributor Author

@TomDLT That's a default style change in matplotlib 2.0, fixed.

@codecov
Copy link
codecov bot commented Feb 13, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@53f8082). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master    #8279   +/-   ##
=========================================
  Coverage          ?   94.75%           
=========================================
  Files             ?      342           
  Lines             ?    60801           
  Branches          ?        0           
=========================================
  Hits              ?    57609           
  Misses            ?     3192           
  Partials          ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53f8082...fe36306. Read the comment docs.

@tguillemot
Copy link
Contributor

@lemonlaug Perfect :)

LGTM

point_params: dictionary of params to pass to `ax.scatter`, optional
countour_params: dictionary of params to pass to `plot_contours`, optional
"""
contours = plot_contours(ax, clf, xx, yy, **contour_params)
Copy link
Member

Choose a reason for hiding this comment

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

It seems a bit silly to have a shared function for contour and point plotting, if their arguments are disjoint and both are delegated to other functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I also waffled over this. I think my initial impulse was to try and get all of the plotting concerns separated into functions, but given that it ultimately doesn't make sense for the axis formatting, I agree that maybe this is a step too far.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I now see more clearly that the setting of xlim and ylim doesn't belong in the contour function.

@lemonlaug
Copy link
Contributor Author

@jnothman Did those changes address your concerns?

I'm not sure what the failure from codecov is complaining about. Would love a tip from anyone on how to address that.

@jnothman
Copy link
Member

LGTM, thanks!

@jnothman jnothman merged commit 9743579 into scikit-learn:master Feb 23, 2017
sergeyf pushed a commit to sergeyf/scikit-learn that referenced this pull request Feb 28, 2017
@Przemo10 Przemo10 mentioned this pull request Mar 17, 2017
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
lemonlaug added a commit to lemonlaug/scikit-learn that referenced this pull request Jan 6, 2021
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.

4 participants
0