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)[source]#
生成用于聚类的各向同性高斯斑点。
在用户指南中阅读更多内容。
- 参数:
- n_samplesint or array-like, default=100
如果是 int,则是均匀分布在所有簇中的总点数。如果是 array-like,序列中的每个元素表示每个簇的样本数。
v0.20 版本更改: 现在可以将 array-like 传递给
n_samples参数。- n_featuresint, default=2
每个样本的特征数。
- centersint or array-like of shape (n_centers, n_features), default=None
要生成的中心数,或固定的中心位置。如果 n_samples 是 int 且 centers 是 None,则生成 3 个中心。如果 n_samples 是 array-like,则 centers 必须是 None 或长度等于 n_samples 长度的数组。
- cluster_stdfloat or array-like of float, default=1.0
簇的标准差。
- center_boxtuple of float (min, max), default=(-10.0, 10.0)
当随机生成中心时,每个簇中心的边界框。
- shufflebool, default=True
打乱样本。
- random_stateint, RandomState instance or None, default=None
确定数据集创建的随机数生成。传递一个 int 值以在多次函数调用中获得可重现的输出。请参阅词汇表。
- return_centersbool, default=False
如果为 True,则返回每个簇的中心。
0.23 版本新增。
- 返回:
- Xndarray of shape (n_samples, n_features)
生成的样本。
- yndarray of shape (n_samples,)
每个样本的簇成员资格的整数标签。
- centersndarray of shape (n_centers, n_features)
每个簇的中心。仅当
return_centers=True时返回。
另请参阅
make_classification一个更复杂的变体。
示例
>>> 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])