@@ -585,7 +585,8 @@ def make_circles(n_samples=100, shuffle=True, noise=None, random_state=None,
585
585
Parameters
586
586
----------
587
587
n_samples : int, optional (default=100)
588
- The total number of points generated.
588
+ The total number of points generated. If odd, the inner circle will
589
+ have one point more than the outer circle.
589
590
590
591
shuffle : bool, optional (default=True)
591
592
Whether to shuffle the samples.
@@ -599,7 +600,7 @@ def make_circles(n_samples=100, shuffle=True, noise=None, random_state=None,
599
600
If None, the random number generator is the RandomState instance used
600
601
by `np.random`.
601
602
602
- factor : double < 1 (default=.8)
603
+ factor : 0 < double < 1 (default=.8)
603
604
Scale factor between inner and outer circle.
604
605
605
606
Returns
@@ -611,22 +612,25 @@ def make_circles(n_samples=100, shuffle=True, noise=None, random_state=None,
611
612
The integer labels (0 or 1) for class membership of each sample.
612
613
"""
613
614
614
- if factor > 1 or factor < 0 :
615
+ if factor >= 1 or factor < 0 :
615
616
raise ValueError ("'factor' has to be between 0 and 1." )
616
617
618
+ n_samples_out = n_samples // 2
619
+ n_samples_in = n_samples - n_samples_out
620
+
617
621
generator = check_random_state (random_state )
618
- # so as not to have the first point = last point, we add one and then
619
- # remove it.
620
- linspace = np .linspace (0 , 2 * np .pi , n_samples // 2 + 1 )[: - 1 ]
621
- outer_circ_x = np .cos (linspace )
622
- outer_circ_y = np .sin (linspace )
623
- inner_circ_x = outer_circ_x * factor
624
- inner_circ_y = outer_circ_y * factor
622
+ # so as not to have the first point = last point, we set endpoint=False
623
+ linspace_out = np . linspace ( 0 , 2 * np . pi , n_samples_out , endpoint = False )
624
+ linspace_in = np .linspace (0 , 2 * np .pi , n_samples_in , endpoint = False )
625
+ outer_circ_x = np .cos (linspace_out )
626
+ outer_circ_y = np .sin (linspace_out )
627
+ inner_circ_x = np . cos ( linspace_in ) * factor
628
+ inner_circ_y = np . sin ( linspace_in ) * factor
625
629
626
630
X = np .vstack ((np .append (outer_circ_x , inner_circ_x ),
627
631
np .append (outer_circ_y , inner_circ_y ))).T
628
- y = np .hstack ([np .zeros (n_samples // 2 , dtype = np .intp ),
629
- np .ones (n_samples // 2 , dtype = np .intp )])
632
+ y = np .hstack ([np .zeros (n_samples_out , dtype = np .intp ),
633
+ np .ones (n_samples_in , dtype = np .intp )])
630
634
if shuffle :
631
635
X , y = util_shuffle (X , y , random_state = generator )
632
636
0 commit comments