Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 #8369

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

Closed
wants to merge 3 commits into from
Closed

[MRG] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 #8369

wants to merge 3 commits into from

Conversation

rishikksh20
Copy link
Contributor

@rishikksh20 rishikksh20 commented Feb 16, 2017

Reference Issue

#8364

What does this implement/fix? Explain your changes.

Modify scikit-learn examples for better looking plots in matplotlib v2

Any other comments?

@lesteve
Copy link
Member

lesteve commented Feb 16, 2017

I updated your description, this should not close #8364 which is a generic issue about all the examples. Your PR is about one of the examples.

@lesteve
Copy link
Member

lesteve commented Feb 16, 2017

I would advise you to disable CircleCI on your fork unless you have a very good reason not to. There are a variety of reasons for this that I am not going to go into. One is that we have convenient ways to find the generated documentation that do not work if CircleCI is enabled on your fork.

@lesteve
Copy link
Member

lesteve commented Feb 16, 2017

For future reference here are the example links for the stable doc, dev doc and this PR doc.

@@ -12,12 +12,13 @@
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm

from sklearn.datasets import make_classification
Copy link
Member

Choose a reason for hiding this comment

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

You should probably not change the data unless you have a very good reason to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lesteve under the Issue #8364 , @amueller point out it good to use make_classification for data generation.

Copy link
Member

Choose a reason for hiding this comment

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

Ah OK I missed that, thanks.

@rishikksh20 rishikksh20 changed the title [WIP] Modify SVM example for matplotlib v2 [WIP] Modify Sklearn examples for matplotlib v2 Feb 16, 2017
@rishikksh20
Copy link
Contributor Author

rishikksh20 commented Feb 16, 2017

I modified the title of this PR and description because I am also go through some more examples which needed to change due to matplotlib up-gradation. Matplotlib v2.0 by default support edgecolors: none which makes many more plots ugly mostly scatter plots. Soon add more files in this PR.

@lesteve
Copy link
Member

lesteve commented Feb 16, 2017

Soon add more files in this PR.

Small PRs are way easier to review and merge. Unless the change is a search-and-replace kind of thing (which I don't think it is and on top of it each example will require visual inspection to make sure that everything works fine), I would be in favour of doing it one example at a time.

@rishikksh20
Copy link
Contributor Author

@lesteve yeah you are right, I do like that . Thanks

X = np.r_[np.random.randn(20, 2) - [2, 2], np.random.randn(20, 2) + [2, 2]]
Y = [0] * 20 + [1] * 20

#X = np.r_[np.random.randn(20, 2) - [2, 2], np.random.randn(20, 2) + [2, 2]]
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this

@lesteve lesteve changed the title [WIP] Modify Sklearn examples for matplotlib v2 [WIP] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 Feb 16, 2017
@codecov
Copy link

codecov bot commented Feb 16, 2017

Codecov Report

Merging #8369 into master will increase coverage by 0.72%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #8369      +/-   ##
==========================================
+ Coverage   94.75%   95.48%   +0.72%     
==========================================
  Files         342      342              
  Lines       60809    60913     +104     
==========================================
+ Hits        57617    58160     +543     
+ Misses       3192     2753     -439
Impacted Files Coverage Δ
sklearn/linear_model/coordinate_descent.py 96.94% <0%> (ø)
sklearn/ensemble/gradient_boosting.py 95.79% <0%> (ø)
sklearn/utils/tests/test_class_weight.py 100% <0%> (ø)
sklearn/ensemble/tests/test_weight_boosting.py 100% <0%> (ø)
sklearn/tree/tree.py 98.41% <0%> (ø)
sklearn/neighbors/tests/test_kde.py 98.85% <0%> (ø)
sklearn/ensemble/forest.py 98.16% <0%> (ø)
sklearn/cluster/dbscan_.py 100% <0%> (ø)
sklearn/linear_model/tests/test_randomized_l1.py 100% <0%> (ø)
sklearn/cluster/tests/test_dbscan.py 100% <0%> (ø)
... and 55 more

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 676e863...73b7442. Read the comment docs.

@rishikksh20 rishikksh20 changed the title [WIP] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 [MRG] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 Feb 17, 2017
Correct SVM hyperplane plot example for matplotlib v2

Issue: #8364
Removed unnecessary comment line to remove flake8 error

Issue: #8364
@rishikksh20 rishikksh20 changed the title [MRG] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 [WIP] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 Mar 4, 2017
Plot using contour levels on decision functions
@rishikksh20 rishikksh20 changed the title [WIP] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 [MRG] Modify svm/plot_separating_hyperplane.py example for matplotlib v2 Mar 4, 2017
ylim = ax.get_ylim()

# create grid to evaluate model
x = np.linspace(xlim[0], xlim[1], 30)
Copy link
Member

Choose a reason for hiding this comment

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

We should really have a function for this but that's another issue #6338

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not merge yet.


X, Y = make_classification(n_features=2, n_redundant=0, n_informative=1,
Copy link
Member

Choose a reason for hiding this comment

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

You should use y here. The scikit-learn convention is that variable names starting with a capital letter should be reserved for 2d arrays.

Copy link
Member

Choose a reason for hiding this comment

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

Can you use a random_state argument otherwise the plot will change each time you run the example.

plt.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1],
s=80, facecolors='none')
plt.scatter(X[:, 0], X[:, 1], c=Y, cmap=plt.cm.Paired)
plt.scatter(X[:, 0], X[:, 1], c=Y, s=50, cmap='autumn', edgecolors='k')
Copy link
Member

Choose a reason for hiding this comment

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

Do not change something unless there is a very good reason to. In this case, I would keep the plt.cm.Paired colormap.

@agramfort
Copy link
Member

this is now taking care of in more recent PRs

see eg #9030 and #9029

@agramfort agramfort closed this Jun 8, 2017
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.

5 participants