sklearn 中 make_blobs模块使用
sklearn.datasets.make_blobs(n_samples=100, n_features=2, centers=3, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, random_state=None)
属性含义:
n_samples: int, optional (default=100)
The total number of points equally divided among clusters.
待生成的样本的总数。
n_features: int, optional (default=2)
The number of features for each sample.
每个样本的特征数。
centers: int or array of shape [n_centers, n_features], optional (default=3)
The number of centers to generate, or the fixed center locations.
要生成的样本中心(类别)数,或者是确定的中心点。
cluster_std: float or sequence of floats, optional (default=1.0)
The standard deviation of the clusters.
每个类别的方差,例如我们希望生成2类数据,其中一类比另一类具有更大的方差,可以将cluster_std设置为[1.0,3.0]。
center_box: pair of floats (min, max), optional (default=(-10.0, 10.0))
The bounding box for each cluster center when centers are generated at random.
shuffle: boolean, optional (default=True)
Shuffle the samples.
random_state: int, RandomState instance or None, optional (default=None)
If int, random_state is the seed used by the random number generator; If
RandomState instance, random_state is the random number generator; If
None, the random number generator is the RandomState instance used by
np.random.
返回值
X : array of shape [n_samples, n_features]
The generated samples.
生成的样本数据集。
y : array of shape [n_samples]
The integer labels for cluster membership of each sample.
样本数据集的标签。
from sklearn.datasets import make_blobs import matplotlib.pyplot as plt if __name__ == '__main__': N = 400 centers = 4 data, y = make_blobs(n_samples=N, n_features=2, centers=centers) plt.scatter(data[:, 0], data[:, 1], c=y) plt.show()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)