-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG+2] make_circles() now works with odd number of samples, test added #10045
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
jnothman
merged 14 commits into
scikit-learn:master
from
christianbraune79:make_circles
Nov 11, 2017
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7576278
fixes #10037
cbrauneovgude effc6c2
tests for #10037, tests for odd number of samples and whether generat…
cbrauneovgude 0a101a1
Merge branch 'make_circles' of https://github.com/christianbraune79/s…
cbrauneovgude 18ee5d8
nasty doubled lines of code removed
cbrauneovgude 32b2ffb
changes according to comments in PR
cbrauneovgude 4c99154
assert_equal obviously has a different signature.
cbrauneovgude 8a86067
Adjusted documentation for make_circles
cbrauneovgude 9ce24e4
added entry under "Decomposition, ..." as another datasets-related bu…
cbrauneovgude 0f1321a
removed wrong entry
cbrauneovgude ad1af5d
all tests for odd and even case
cbrauneovgude ad07946
added final comment
cbrauneovgude 6126a5c
'107 > 79' fixed
cbrauneovgude 2a62edc
refactoring f into factor
cbrauneovgude e19cecc
pep8
cbrauneovgude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -585,7 +585,8 @@ def make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, | |
Parameters | ||
---------- | ||
n_samples : int, optional (default=100) | ||
The total number of points generated. | ||
The total number of points generated. If odd, the inner circle will | ||
have one point more than the outer circle. | ||
|
||
shuffle : bool, optional (default=True) | ||
Whether to shuffle the samples. | ||
|
@@ -599,7 +600,7 @@ def make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, | |
If None, the random number generator is the RandomState instance used | ||
by `np.random`. | ||
|
||
factor : double < 1 (default=.8) | ||
factor : 0 < double < 1 (default=.8) | ||
Scale factor between inner and outer circle. | ||
|
||
Returns | ||
|
@@ -611,22 +612,25 @@ def make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, | |
The integer labels (0 or 1) for class membership of each sample. | ||
""" | ||
|
||
if factor > 1 or factor < 0: | ||
if factor >= 1 or factor < 0: | ||
raise ValueError("'factor' has to be between 0 and 1.") | ||
|
||
n_samples_out = n_samples // 2 | ||
n_samples_in = n_samples - n_samples_out | ||
|
||
generator = check_random_state(random_state) | ||
# so as not to have the first point = last point, we add one and then | ||
# remove it. | ||
linspace = np.linspace(0, 2 * np.pi, n_samples // 2 + 1)[:-1] | ||
outer_circ_x = np.cos(linspace) | ||
outer_circ_y = np.sin(linspace) | ||
inner_circ_x = outer_circ_x * factor | ||
inner_circ_y = outer_circ_y * factor | ||
# so as not to have the first point = last point, we set endpoint=False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're so much smarter than me.... |
||
linspace_out = np.linspace(0, 2 * np.pi, n_samples_out, endpoint=False) | ||
linspace_in = np.linspace(0, 2 * np.pi, n_samples_in, endpoint=False) | ||
outer_circ_x = np.cos(linspace_out) | ||
outer_circ_y = np.sin(linspace_out) | ||
inner_circ_x = np.cos(linspace_in) * factor | ||
inner_circ_y = np.sin(linspace_in) * factor | ||
|
||
X = np.vstack((np.append(outer_circ_x, inner_circ_x), | ||
np.append(outer_circ_y, inner_circ_y))).T | ||
y = np.hstack([np.zeros(n_samples // 2, dtype=np.intp), | ||
np.ones(n_samples // 2, dtype=np.intp)]) | ||
y = np.hstack([np.zeros(n_samples_out, dtype=np.intp), | ||
np.ones(n_samples_in, dtype=np.intp)]) | ||
if shuffle: | ||
X, y = util_shuffle(X, y, random_state=generator) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Personally, I'm with you. But this latest source code change is not reviewed by anyone else. So need to confirm with core devs to see whether we need factor=1 in extreme case.
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.
Yes, definitely. If it was a typo in the docs then I'll revert the change and adjust the documentation. :)
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.
I this is fine.