8000 [MRG+1] Fixes #8198 - error in datasets.make_moons (#8199) · scikit-learn/scikit-learn@aea6462 · GitHub
[go: up one dir, main page]

Skip to content

Commit aea6462

Browse files
levy5674jnothman
authored andcommitted
[MRG+1] Fixes #8198 - error in datasets.make_moons (#8199)
1 parent 0eb33ad commit aea6462

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

doc/whats_new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ Enhancements
140140
Bug fixes
141141
.........
142142

143+
- Fixed a bug where :func:`sklearn.datasets.make_moons` gives an
144+
incorrect result when ``n_samples`` is odd.
145+
:issue:`8198` by :user:`Josh Levy <levy5674>`.
146+
143147
- Fixed a bug where :class:`sklearn.linear_model.LassoLars` does not give
144148
the same result as the LassoLars implementation available
145149
in R (lars library). :issue:`7849` by :user:`Jair Montoya Martinez <jmontoyam>`

sklearn/datasets/samples_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ def make_moons(n_samples=100, shuffle=True, noise=None, random_state=None):
665665

666666
X = np.vstack((np.append(outer_circ_x, inner_circ_x),
667667
np.append(outer_circ_y, inner_circ_y))).T
668-
y = np.hstack([np.zeros(n_samples_in, dtype=np.intp),
669-
np.ones(n_samples_out, dtype=np.intp)])
668+
y = np.hstack([np.zeros(n_samples_out, dtype=np.intp),
669+
np.ones(n_samples_in, dtype=np.intp)])
670670

671671
if shuffle:
672672
X, y = util_shuffle(X, y, random_state=generator)
< C8C4 /div>

sklearn/datasets/tests/test_samples_generator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from sklearn.datasets import make_friedman2
2525
from sklearn.datasets import make_friedman3
2626
from sklearn.datasets import make_low_rank_matrix
27+
from sklearn.datasets import make_moons
2728
from sklearn.datasets import make_sparse_coded_signal
2829
from sklearn.datasets import make_sparse_uncorrelated
2930
from sklearn.datasets import make_spd_matrix
@@ -360,3 +361,12 @@ def test_make_checkerboard():
360361
X2, _, _ = make_checkerboard(shape=(100, 100), n_clusters=2,
361362
shuffle=True, random_state=0)
362363
assert_array_equal(X1, X2)
364+
365+
366+
def test_make_moons():
367+
X, y = make_moons(3, shuffle=False)
368+
for x, label in zip(X, y):
369+
center = [0.0, 0.0] if label == 0 else [1.0, 0.5]
370+
dist_sqr = ((x - center) ** 2).sum()
371+
assert_almost_equal(dist_sqr, 1.0,
372+
err_msg="Point is not on expected unit circle")

0 commit comments

Comments
 (0)
0