numpy 归一化_NumPy 数据归一化、可视化

仅使用 NumPy,下载数据,归一化,使用 seaborn 展示数据分布。

下载数据

import numpy as np

url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
wid = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[1])

仅提取 iris 数据集的第二列 usecols = [1]

展示数据

array([3.5, 3. , 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3. ,
3. , 4. , 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3. ,
3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.1, 3. ,
3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3. , 3.8, 3.2, 3.7, 3.3, 3.2, 3.2,
3.1, 2.3, 2.8, 2.8, 3.3, 2.4, 2.9, 2.7, 2. , 3. , 2.2, 2.9, 2.9,
3.1, 3. , 2.7, 2.2, 2.5, 3.2, 2.8, 2.5, 2.8, 2.9, 3. , 2.8, 3. ,
2.9, 2.6, 2.4, 2.4, 2.7, 2.7, 3. , 3.4, 3.1, 2.3, 3. , 2.5, 2.6,
3. , 2.6, 2.3, 2.7, 3. , 2.9, 2.9, 2.5, 2.8, 3.3, 2.7, 3. , 2.9,
3. , 3. , 2.5, 2.9, 2.5, 3.6, 3.2, 2.7, 3. , 2.5, 2.8, 3.2, 3. ,
3.8, 2.6, 2.2, 3.2, 2.8, 2.8, 2.7, 3.3, 3.2, 2.8, 3. , 2.8, 3. ,
2.8, 3.8, 2.8, 2.8, 2.6, 3. , 3.4, 3.1, 3. , 3.1, 3.1, 3.1, 2.7,
3.2, 3.3, 3. , 2.5, 3. , 3.4, 3. ])

这是单变量(univariate)长度为 150 的一维 NumPy 数组。

归一化

求出最大值、最小值

smax = np.max(wid)
smin = np.min(wid)

In [51]: smax,smin
Out[51]: (4.4, 2.0)

归一化公式:

s = (wid - smin) / (smax - smin)

只打印小数点后三位设置:

np.set_printoptions(precision=3)

归一化结果:

array([0.625, 0.417, 0.5  , 0.458, 0.667, 0.792, 0.583, 0.583, 0.375,
0.458, 0.708, 0.583, 0.417, 0.417, 0.833, 1. , 0.792, 0.625,
0.75 , 0.75 , 0.583, 0.708, 0.667, 0.542, 0.583, 0.417, 0.583,
0.625, 0.583, 0.5 , 0.458, 0.583, 0.875, 0.917, 0.458, 0.5 ,
0.625, 0.458, 0.417, 0.583, 0.625, 0.125, 0.5 , 0.625, 0.75 ,
0.417, 0.75 , 0.5 , 0.708, 0.542, 0.5 , 0.5 , 0.458, 0.125,
0.333, 0.333, 0.542, 0.167, 0.375, 0.292, 0. , 0.417, 0.083,
0.375, 0.375, 0.458, 0.417, 0.292, 0.083, 0.208, 0.5 , 0.333,
0.208, 0.333, 0.375, 0.417, 0.333, 0.417, 0.375, 0.25 , 0.167,
0.167, 0.292, 0.292, 0.417, 0.583, 0.458, 0.125, 0.417, 0.208,
0.25 , 0.417, 0.25 , 0.125, 0.292, 0.417, 0.375, 0.375, 0.208,
0.333, 0.542, 0.292, 0.417, 0.375, 0.417, 0.417, 0.208, 0.375,
0.208, 0.667, 0.5 , 0.292, 0.417, 0.208, 0.333, 0.5 , 0.417,
0.75 , 0.25 , 0.083, 0.5 , 0.333, 0.333, 0.292, 0.542, 0.5 ,
0.333, 0.417, 0.333, 0.417, 0.333, 0.75 , 0.333, 0.333, 0.25 ,
0.417, 0.583, 0.458, 0.417, 0.458, 0.458, 0.458, 0.292, 0.5 ,
0.542, 0.417, 0.208, 0.417, 0.583, 0.417])

分布可视化

import seaborn as sns
sns.distplot(s,kde=False,rug=True)

频率分布直方图:

3238a13fd8fa77ae1ac044918dd35059.png
sns.distplot(s,hist=True,kde=True,rug=True)

带高斯密度核函数的直方图:

eb5b93a20a7597e28c87d11da97b0801.png

分布 fit 图

gamma 分布去 fit :

from scipy import stats
sns.distplot(s, kde=False, fit = stats.gamma)
48bc50e62fc5c170fc01ae42c961b01a.png

拿双 gamma 去 fit:

from scipy import stats
sns.distplot(s, kde=False, fit = stats.dgamma)
236218c3a179ffce167bf78e80804876.png此类文章,可关注下面《Python小例子》:

00f115705b04005ff3addc11b260cdd5.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542523.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java虚拟机规范阅读(三)异常

Java虚拟机里面的异常使用Throwable或其子类的实例来表示,抛异常的本质实际上是程序控制权的一种即时的、非局部(Nonlocal)的转换——从异常抛出的地方转换至处理异常的地方。绝大多数的异常的产生都是由于当前线程执行的某个操作所导致的&am…

puppeteer api_使用Node.js和puppeteer API从URL创建PDF文件

puppeteer apiWe will continue using Node.js and puppeteer which is a node library. As we saw in our last article, Puppeteer is a Node library developed by Google and provides a high-level API for developers. 我们将继续使用Node.js和puppeteer(这是一个节点库)…

python线程同步锁_[python] 线程间同步之Lock RLock

为什么需要同步 同样举之前的例子,两个线程分别对同一个全局变量进行加减,得不到预期结果,代码如下: total 0 def add(): global total for i in range(1000000): total 1 def desc(): global total for i in range(1000000): t…

servlet的由来

2019独角兽企业重金招聘Python工程师标准>>> 动静态网页技术 首先说下访问网页的大概过程: 你在浏览器中输入网址,按下enter键,此时浏览器代你做了很多事,简要说为:将你输入的这个网址作为目的地参数&#…

php header 文件大小,php获取远程文件大小及信息的函数(head_php

php获取远程文件大小及信息的函数(header头信息获取)阿里西西Alixixi.com开发团队在做一个客户系统时,需要做远程下载的功能,并实时显示进度条效果。所以,需要预先读取远程文件的大小信息,然后做为实时下载进度条的参数。功能函数…

Java ObjectInputStream readUnsignedShort()方法(带示例)

ObjectInputStream类readUnsignedShort()方法 (ObjectInputStream Class readUnsignedShort() method) readUnsignedShort() method is available in java.io package. readUnsignedShort()方法在java.io包中可用。 readUnsignedShort() method is used to read 2 bytes (i.e. …

python中info的用法_Python pandas.DataFrame.info函数方法的使用

DataFrame.info(self, verboseNone, bufNone, max_colsNone, memory_usageNone, null_countsNone) [source] 打印DataFrame的简要摘要。 此方法显示有关DataFrame的信息,包括索引dtype和列dtype,非空值和内存使用情况。 参数:verbose &#x…

第四次作业 孙保平034 李路平029

用C编写一个学生成绩管理系统 1、可以实现以下功能&#xff1a; cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 1.增加学生成绩 ☆ ★〓〓〓〓〓〓〓〓〓"<<endl; 2、用链表存储信息 * 程序头部的注释结束 3、约定的规范&#xff1a; 1界面设计简介&#xff0c;人性化…

php serialize error at offset,PHP Notice: unserialize(): Error at offset XX of XX bytes

之前同事在本地开发的时候&#xff0c;出现一个错误&#xff0c;如下图所示&#xff1a;字面意思就是反序列化错误&#xff0c;由此bug引申出来序列化和反序列化得应用&#xff0c;以及php array当key为string类型的数字值时&#xff0c;会发生什么情形。先来看序列化$str [1 …

Java ClassLoader setClassAssertionStatus()方法与示例

ClassLoader类setClassAssertionStatus()方法 (ClassLoader Class setClassAssertionStatus() method) setClassAssertionStatus() method is available in java.lang package. setClassAssertionStatus()方法在java.lang包中可用。 setClassAssertionStatus() method is used …

python怎么变各种颜色_python – 如何淡化颜色

有很多方法可以做到这一点.您如何选择这取决于您是否重视速度和简单性或感知均匀性.如果你需要它是真正统一的,你需要用颜色配置文件定义RGB颜色,你需要配置文件的原色,这样你就可以转换为XYZ,然后转换到LAB,你可以操作L通道. 大多数情况下,您不需要这样做,而是可以使用像Photo…

informatica中元数据管理

摘自&#xff1a; http://blog.itpub.net/28690368/viewspace-766528/ informaica是一个很强大的ETL工具&#xff0c;WORKFLOW MANAGER负责对ETL调度流程进行设计与管理和执行&#xff0c;informatica在资料库中提供以下表来存储调动流程的相关信息&#xff0c;以便WORKFLOW …

yii+php+当前目录,Yii应用的目录结构和入口脚本

以下是一个通过高级模版安装后典型的Yii应用的目录结构&#xff1a;~~~.├── backend├── common├── console├── environments├── frontend├── nbproject├── tests├── vendor├── composer.json├── composer.lock├── init├── init.bat├── …

8086 寻址方式_8086微处理器的不同寻址模式

8086 寻址方式Introduction: 介绍&#xff1a; Addressing mode tells us what is the type of the operand and the way they are accessed from the memory for execution of an instruction and how to fetch particular instruction from the memory. There are mainly 8 …

决策树的value是什么意思_从零开始的机器学习实用指南(六):决策树

类似SVM&#xff0c;决策树也是非常多功能的机器学习算法&#xff0c;可以分类&#xff0c;回归&#xff0c;甚至可以完成多输出的任务&#xff0c;能够拟合复杂的数据集&#xff08;比如第二章的房价预测例子&#xff0c;虽然是过拟合了。&#xff09;决策树也是很多集成学习的…

Hive中生成随机唯一标识ID的方法

2019独角兽企业重金招聘Python工程师标准>>> HIVE中处理的数据往往比较多&#xff0c;在处理数据的时候希望给处理得到的数据一个ID标识&#xff0c;这时候可以用到UUID。 UUID的算法的核心思想是结合机器的网卡、当地时间、一个随即数来生成UUID。从理论上讲&#…

php从网页获得数据,php根据URL获得网页内容

php 中根据url来获得网页内容非常的方便&#xff0c;可以通过系统内置函数file_get_contents(),传入url,即可返回网页的内容&#xff0c;比如获得百度首页的内容代码为&#xff1a;$html file_get_contents(http://www.baidu.com/);echo $html;就可以显示出百度首页的内容&…

2020知道python语言应用答案_2020知到Python语言应用答案章节期末答案

组合管理理论最早由哈维马科维兹于1962年系统的提出&#xff0c;他开创了对投资进行整体管理的先 公司型基金和契约型基金的区别&#xff0c;下列不包括&#xff08;&#xff09;。 A&#xff0e;资金的性质B&#xff0e;基金的营运依据C&#xff0e;基 我国&#xff08;&#…

如何在Bootstrap中使用Jumbotron和页面标头类?

Introduction 介绍 In the previous article, we have learned how Responsive column, Nesting Columns and offset Columns work and how to use them? I hope now, you all are comfortable with the grid system; what is it, how to use it and how we can use it for c…

python中的数字类型格式与运算,python数字数据类型

python数字数据类型1. 数字在我们很小的时候&#xff0c;父母便开始教我们数数&#xff0c;从1数到10&#xff0c;聪明的孩子可以数的更多。python支持3中数值类型整型(int)&#xff0c;通常称之为整型或整数&#xff0c;这个概念与我们小学时学过的整数是相同的&#xff0c;py…