-
-
Notifications
You must be signed in to change notification settings - Fork 26k
Fix plot_svm_margin example plots #8051
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
Conversation
Thanks @jligo. |
margin = 1 / np.sqrt(np.sum(clf.coef_ ** 2)) | ||
yy_down = yy + a * margin | ||
yy_up = yy - a * margin | ||
yy_down = yy - np.sqrt(1+a**2) * margin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pep8 : Add space before/after + and **
Wouldn't it be easier to just add or subtract |
There are two figures generated (order: original, revised). PDF's are a bit higher quality. Figure 1: original_1.pdf,revised_1.pdf Figure 2: original_2.pdf,revised_2.pdf |
yeah that makes a lot more sense. Btw, you can also directly embed PNGs into github comments which makes them much easier to see. |
You just have to shift x and y so that |y shift - slope * x shift | = margin * sqrt(1+slope^2) = 1/w[1] where w is coef_. So, we could replace np.sqrt(1 + a ** 2) * margin with 1/w[1], but I'm not sure which one is clearer for an example (since the margin doesn't come into play explicitly in the code at all, then). Or introduce a set of variables xx_down and xx_up, and shift both x and y (but the shifts won't just be by coef_). |
Another alternative is the approach in this example (which is basically the same example, without colors), but you're relying on the support vectors to appear in some order (which I don't think is guaranteed for different data realizations). |
I think this is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM but travis complains |
* Corrected shift of separating hyperplane that passes through the support vectors * Fixed signs on yy_down and yy_up * PEP 8 spacing correction * Fixed spaces at end of comment for Travis
* Corrected shift of separating hyperplane that passes through the support vectors * Fixed signs on yy_down and yy_up * PEP 8 spacing correction * Fixed spaces at end of comment for Travis
* Corrected shift of separating hyperplane that passes through the support vectors * Fixed signs on yy_down and yy_up * PEP 8 spacing correction * Fixed spaces at end of comment for Travis
* Corrected shift of separating hyperplane that passes through the support vectors * Fixed signs on yy_down and yy_up * PEP 8 spacing correction * Fixed spaces at end of comment for Travis
* Corrected shift of separating hyperplane that passes through the support vectors * Fixed signs on yy_down and yy_up * PEP 8 spacing correction * Fixed spaces at end of comment for Travis
Reference Issue
The dashed lines which are "margin" away from the separating hyperplane do not pass through the support vectors when they are supposed to.
What does this implement/fix? Explain your changes.
The dashed lines are calculated by shifting of the separating hyperplane to margin distance away by adding and subtracting margin*sqrt(1+(slope of separating hyperplane)^2) in the y-direction. This follows from the fact that the absolute value of the difference of intercepts of two parallel lines is the (distance apart) * sqrt(1+slope^2), where the distance apart is measured perpendicular to the lines.
Any other comments?
None.