make_blobs#
- sklearn.datasets.make_blobs(n_samples=100, n_features=2, *, centers=None, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, random_state=None, return_centers=False)#
生成用于聚类的各向同性高斯斑点。
有关使用示例,请参见 绘制随机生成的分类数据集 。
更多信息请参阅 用户指南 。
- Parameters:
- n_samplesint 或 array-like, 默认=100
如果是 int,它是均匀分布在各簇中的总点数。 如果是 array-like,序列中的每个元素表示每个簇的样本数。
Changed in version v0.20: 现在可以将 array-like 传递给
n_samples
参数- n_featuresint, 默认=2
每个样本的特征数量。
- centersint 或 array-like of shape (n_centers, n_features), 默认=None
要生成的中心数量,或固定的中心位置。 如果 n_samples 是 int 且 centers 是 None,则生成 3 个中心。 如果 n_samples 是 array-like,centers 必须是 None 或长度等于 n_samples 的数组。
- cluster_stdfloat 或 array-like of float, 默认=1.0
簇的标准差。
- center_boxtuple of float (min, max), 默认=(-10.0, 10.0)
当中心随机生成时,每个簇中心的边界框。
- shufflebool, 默认=True
打乱样本。
- random_stateint, RandomState 实例或 None, 默认=None
确定用于数据集创建的随机数生成。传递一个 int 以在多次函数调用中获得可重复的输出。 请参阅 术语表 。
- return_centersbool, 默认=False
如果为 True,则返回每个簇的中心。
Added in version 0.23.
- Returns:
- Xndarray of shape (n_samples, n_features)
生成的样本。
- yndarray of shape (n_samples,)
每个样本的簇成员资格的整数标签。
- centersndarray of shape (n_centers, n_features)
每个簇的中心。仅当
return_centers=True
时返回。
See also
make_classification
更复杂的变体。
Examples
>>> from sklearn.datasets import make_blobs >>> X, y = make_blobs(n_samples=10, centers=3, n_features=2, ... random_state=0) >>> print(X.shape) (10, 2) >>> y array([0, 0, 1, 0, 2, 2, 2, 1, 1, 0]) >>> X, y = make_blobs(n_samples=[3, 3, 4], centers=None, n_features=2, ... random_state=0) >>> print(X.shape) (10, 2) >>> y array([0, 1, 2, 0, 2, 2, 2, 1, 1, 0])