sklearn.datasets.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

# 创建仿真聚类数据集
X, y = make_blobs(n_samples=150,
n_features=2,
centers=3,
cluster_std=0.5,
shuffle=True,
random_state=0)

# 绘制散点图
plt.figure('百里希文', facecolor='lightyellow')
plt.scatter(X[:, 0], X[:, 1], c='w', edgecolor='k', marker='o', s=50)
plt.grid()
plt.show()

推荐参考:

https://cloud.tencent.com/developer/article/1406348

scikit-leanr 库中的 make_blobs() 函数的更多相关文章

  1. numpy函数库中一些常用函数的记录

    ##numpy函数库中一些常用函数的记录 最近才开始接触Python,python中为我们提供了大量的库,不太熟悉,因此在<机器学习实战>的学习中,对遇到的一些函数的用法进行记录. (1) ...

  2. 查找库中的某个函数,grep命令的用法。

    程序中调用了某个库中的函数,我想知道这个函数具体的作用,就必须去看这个库的源代码. 那么问题来了:如何从库中众多的.h文件中,得知我想要的函数在哪个文件里? 最后用grep命令成功解决. 具体用法:先 ...

  3. STL库中的正态分布函数

    在设计抽奖一类程序中,有时会需要一种概率“有较大可能获得一个普通结果,有较小可能获得一个糟糕或极好的结果”,这就可以用正态分布函数来获得这样一个结果. STL中已经提供了一系列随机分布的函数,包括正态 ...

  4. jquery.rotate.js库中的rotate函数怎么用。

    rotate是jQuery旋转rotate插件,支持Internet Explorer 6.0+ .Firefox 2.0 .Safari 3 .Opera 9 .Google Chrome,高级浏览 ...

  5. 机器学习之numpy库中常用的函数介绍(一)

    1. mat() mat()与array的区别: mat是矩阵,数据必须是2维的,是array的子集,包含array的所有特性,所做的运算都是针对矩阵来进行的. array是数组,数据可以是多维的,所 ...

  6. Python标准库中的生成器函数

    一.用于过滤的生成器函数 - 从输入的可迭代对象中产出元素的子集,而不修改元素本身 import itertools l1 = [1,2,3,4,5] l2 = [True,False,True,Fa ...

  7. lua的table库中的常用函数总结

    table是Lua语言中的一种重要的数据类型, table 的一些特性简单列举如下: (1).table 是一个“关联数组”,数组的索引可以是数字或者是字符串; (2).table 的默认初始索引一般 ...

  8. python 生成器(四):生成器基础(四)标准库中的生成器函数

    os.walk 这个函数在遍历目录树的过程中产出文件名,因此递归搜索文件系统像for 循环那样简单. 用于过滤的生成器函数 模块  函数  说明 itertools  compress(it,sele ...

  9. Python初探——sklearn库中数据预处理函数fit_transform()和transform()的区别

    敲<Python机器学习及实践>上的code的时候,对于数据预处理中涉及到的fit_transform()函数和transform()函数之间的区别很模糊,查阅了很多资料,这里整理一下: ...

随机推荐

  1. Linux权限及归属管理 磁盘管理 文件系统 LVM管理

    第五六七章   alias 查看系统别名   67 chmod 设置文件或目录的权限 -R表示以递归的方式设置目录及目录下的所有子目录及文件的权限 u:属主 g:属组 o:其他人 a:所有人 +:添加 ...

  2. 8.22 NOIP模拟测试29(B) 爬山+学数数+七十和十七

    T1 爬山 二分最高高度,$O(1)$判断是否可行. #include<iostream> #include<cstdio> #define ll long long usin ...

  3. [LeetCode] 287. Find the Duplicate Number 寻找重复数

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...

  4. [LeetCode] 35. Search Insert Position 搜索插入位置

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  5. 阅读java编程思想之一切都是对象

    温故而知新--- 1. 用句柄操作对象 现实生活中,我们可以把遥控器当作句柄,电视机当作对象.当我们拿到句柄(遥控器)的时候,我们是可以控制对象的(电视机).比如说调节音量大小,色彩等.那么在程序里, ...

  6. zlib: 不同语言,比如go, php, python 压缩的结果可能不同

    1.这个是实际工作中发现的问题,一边用了go语言对一个文件进行了zlib压缩,然后我用 php 写了个脚本对同一个文件进行zlib压缩,但是生成的两个文件不同,当时一直以为是压缩参数选择错了,后来经过 ...

  7. 书籍推荐-An introduction to Data Science

    为什么要读这本书? 该书是由我们老师推荐的,通过学习此数,可以了解R语言的使用,也可以知道基本的数据分析方法. 看到Creating a Data Set in R -- 24页面

  8. 以Integer类型传参值不变来理解Java值传参

    最近在写代码的时候出了一个错误,由于对值引用理解的不深,将Integer传入方法中修改,以为传入后直接修改Integer中的值就不用写返回值接收了,虽然很快发现了问题,但还是来总结一下 首先是代码: ...

  9. history路由模式下的nginx配置

    路由模式 众所周知,浏览器下的单页面应用的路由模式有下面两种: hash 模式和 history 模式.hash 模式通用性好,而且不依赖服务器的配置,省心省力,但是缺点是不够优雅.相比于 hash ...

  10. app 崩溃测试 (转:CSDN 我去热饭)

    首先,崩溃有几种情况: 闪退 提示停止运行 无响应 ( 不同情况虽然没有严格意义上区分开引起原因,但是都有侧重.在之后的工作中,我会实时补充统计.) 1.接口返回值 [直接原因]:app无法解析接口返 ...