函数原型:

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.
样本数据集的标签。

实战代码1:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.datasets.samples_generator import make_blobs
# X为样本特征,Y为样本簇类别, 共1000个样本,每个样本3个特征,共4个簇
X, y = make_blobs(n_samples=10000, n_features=3, centers=[[3,3, 3], [0,0,0], [1,1,1], [2,2,2]], cluster_std=[0.2, 0.1, 0.2, 0.2], random_state =9)
fig = plt.figure()
ax = Axes3D(fig, rect=[0, 0, 1, 1], elev=30, azim=20)
plt.scatter(X[:, 0], X[:, 1], X[:, 2],marker='o')
plt.show()

输出:

实战代码2:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_blobsX, y = make_blobs(n_samples=100, n_features=2, centers=4)plt.scatter(X[:, 0], X[:, 1], c='b')
plt.show()

输出:

【Python学习】 - sklearn - 用于生成数据的make_blobs模块相关推荐

  1. 用Python做数据分析之生成数据表

    第一部分是生成数据表,常见的生成方法有两种,第一种是导入外部数据,第二种是直接写入数据. Excel 中的文件菜单中提供了获取外部数据的功能,支持数据库和文本文件和页面的多种数据源导入. 获取外部数据 ...

  2. python 数据去重_科学网—python学习——根据条件提取数据,并去重 - 李立的博文...

    [Python字符串提取] 摘要:根据要求进行字符串的提取,并去重 导入分析所需的库import pandas as pd 构造数据集 as1 = pd.DataFrame({'a':[1,2,3,4 ...

  3. python函数复用_【python学习-4】可复用函数与模块

    1.自定义函数 自定义函数格式如下: def (参数列表):return #!/usr/bin/python#定义函数,打印数字1~5 defprintNum5():#range函数,生成列表集合,有 ...

  4. python 连接数据库并批量生成数据

    自己在电脑上搭建了一个数据库,并用Python连接了一下,因为是刚搭建的,没有数据,就通过py生成了一些数据,写的比较粗糙.勿喷!废话不多说上代码! import pymysql # 导入mysql库 ...

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

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

  6. python学习笔记(生成xml)

    想着给框架加些功能 首先想到的是生成测试报告 这里就涉及到了生成什么格式的文件 我这边就准备生成 xml 格式的文件 自己先学习了整理了下 代码如下: 1 #!/usr/bin/env python ...

  7. Head First Python学习笔记4——处理数据

    有这么几组数据需要你处理: James 2-34,3:21,2.34,2.45,3.01,2:01,2:01,3:10,2-22 Julia 2.59,2.11,2:11,2:23,3-10,2-23 ...

  8. Python学习笔记(四)—生成随机数

    函数randint(a,b)可以产生区间(a,b)中的随机数.但是要加import random: 比如说: import random number1 = random.randint(0,9) n ...

  9. 【Python学习】——读取HDF数据

    Hierarchical Data Format (HDF)--分层数据格式,通常包含多维数据,许多水文气象相关的数 据格式都是HDF.本文旨在利用python语言实现数据的快速读取,数据来自GLAS ...

最新文章

  1. rabbitmq利用死信队列+TTL 实现延迟队列
  2. C#使用事件方式Winform窗体之间传值
  3. springboot配置对jsp页面的解析支持
  4. vue的列表交错过渡
  5. 三层架构项目如何发布_链客Talk | 优盾首席架构师Alex Yang:如何从0开发区块链项目?...
  6. linux服务器时间乱码问题解决
  7. JavaScript的事件执行机制及异步
  8. pb dw graph增加series_如何快速增加tiktok视频的播放量
  9. stm32 上电初始化串口输出一个字节FF问题
  10. 李宏毅机器学习——课后作业1
  11. java 获取身份证前两位对应省份
  12. matlab跟踪控制程序,机器人轨迹跟踪控制方法研究(含MATLAB程序)
  13. 制作u盘winpe启动盘_U盘PE启动盘制作方法
  14. 企业云服务器的选择与配置指南
  15. 易语言运行 (c:内部.exe, 假, ),易语言没法运行exe程序,怎么办?
  16. 【BDTC 2016】蚂蚁金服人工智能部技术总监李小龙:人工智能驱动金融生活
  17. 微信小程序-全局数据共享
  18. Failed to load the JNI shared library 的解决方法
  19. 英语长难句之非谓语动词作状语与独立主格-学习笔记
  20. Stanford NER CRF FAQ

热门文章

  1. [Leedcode][JAVA][第460题][LFU]
  2. 力扣:组合总和 II DFS剪枝
  3. java gb13000 ucs2_采用GB 13000的UCS-2进行存储的文件怎么转换
  4. webpack最新版本_webpack小结-开发环境构建优化
  5. cat命令详解_好程序员Python培训之详解eval好与坏
  6. git ssh配置文件 服务器_git登录ssh服务器
  7. 计算机入门在线阅读,电脑入门基础教程..doc
  8. SliceProceduralMesh的使用
  9. CTL_CODE说明
  10. linux arp 文件,LINUX 下ARP 的查找