@@ -855,6 +855,18 @@ def make_moons(n_samples=100, *, shuffle=True, noise=None, random_state=None):
855
855
return X , y
856
856
857
857
858
+ @validate_params (
859
+ {
860
+ "n_samples" : [Interval (Integral , 1 , None , closed = "left" ), "array-like" ],
861
+ "n_features" : [Interval (Integral , 1 , None , closed = "left" )],
862
+ "centers" : [Interval (Integral , 1 , None , closed = "left" ), "array-like" , None ],
863
+ "cluster_std" : [Interval (Real , 0 , None , closed = "left" ), "array-like" ],
864
+ "center_box" : [tuple ],
865
+ "shuffle" : ["boolean" ],
866
+ "random_state" : ["random_state" ],
867
+ "return_centers" : ["boolean" ],
868
+ }
869
+ )
858
870
def make_blobs (
859
871
n_samples = 100 ,
860
872
n_features = 2 ,
@@ -884,7 +896,7 @@ def make_blobs(
884
896
n_features : int, default=2
885
897
The number of features for each sample.
886
898
887
- centers : int or ndarray of shape (n_centers, n_features), default=None
899
+ centers : int or array-like of shape (n_centers, n_features), default=None
888
900
The number of centers to generate, or the fixed center locations.
889
901
If n_samples is an int and centers is None, 3 centers are generated.
890
902
If n_samples is array-like, centers must be
@@ -967,22 +979,19 @@ def make_blobs(
967
979
centers = generator .uniform (
968
980
center_box [0 ], center_box [1 ], size = (n_centers , n_features )
969
981
)
970
- try :
971
- assert len (centers ) == n_centers
972
- except TypeError as e :
982
+ if not isinstance (centers , Iterable ):
973
983
raise ValueError (
974
984
"Parameter `centers` must be array-like. Got {!r} instead" .format (
975
985
centers
976
986
)
977
- ) from e
978
- except AssertionError as e :
987
+ )
988
+ if len ( centers ) != n_centers :
979
989
raise ValueError (
980
990
"Length of `n_samples` not consistent with number of "
981
991
f"centers. Got n_samples = { n_samples } and centers = { centers } "
982
- ) from e
983
- else :
984
- centers = check_array (centers )
985
- n_features = centers .shape [1 ]
992
+ )
993
+ centers = check_array (centers )
994
+ n_features = centers .shape [1 ]
986
995
987
996
# stds: if cluster_std is given as list, it must be consistent
988
997
# with the n_centers
0 commit comments