IT小牛的IT见解 2019-06-27

- 为数据提供一种关系或一个关联后,数据就成了信息,这种关联通过提供数据背景来完成
- 知识包括做出适当决策的能力和执行时所需的技能
- 如何获取观点: 基于已有数据信息得到最佳或现实的决策,我们可以通过数据分析
信息是可量化的、可测度的、有形式的,可被访问、生成、存储、分发、搜索、压缩和复制。
信息可以通过数量或信息量进行量化。,信息可转换为知识,知识要比信息更量化。在某些领域,知识持续经历一个不断发展周期。当数据发生变化时,这种演变过程随之发生。
通过离散算法
- 数据的种类不同,包括表现数据, 实验数据,基准数据
可视化的整个过程需要不用技能和专业领域的人。
数据工人努力收集数据并完成分析
数学家和统计学家理解可视化设计原则,并用这些原则完成数据交流
设计师和艺术家和开发者具备可视化转换的技能
业务分析员等找寻行为模式,离群点或突发趋势
整个过程额步骤是:
数据转换:将数据缩放到一个较小的区间,从而提高处理和可视化的精确性和效率
-
这里我们会使用下面几种绘图工具
地理数据引擎更强的可视化工具库图形公司创造并提供免费使用,我们可以在离线模式下创建无限图表,在线模式下最多可以创建25个图表
当然,找更多工具戳这里
数据的可视化是表达信息的过程,在可视化化过程我们要思考:
这里有个学生数据:http://www.knapdata.com/pytho... 
# -*- coding:utf-8 -*-
# usr/bin/python 3.5+
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
students = pd.read_csv("data/ucdavis.csv")
g = sns.FacetGrid(students, hue="gender", palette="Set1", size=6)
g.map(plt.scatter, "gpa", "computer", s=250, linewidth= 0.65, edgecolor="white")
g.add_legend()
plt.show()seaborn: http://seaborn.pydata.org/api...
- 用于对数据子集中的一个变量的分布或者多个变量关系进行可视化
import numpy as np
import matplotlib.pyplot as plt
N = 7
winnersplot = (142.6, 125.3, 62.0, 81.0, 145.6, 319.4, 178.1 )
ind = np.arange(N)
width = 0.35
fig, ax = plt.subplots()
winners = ax.bar(ind, winnersplot, width, color='#ffad00')
print(winners)
nomineesplot = (109.4, 94.8, 60.7, 44.6, 116.9,262.5,102.0)
nominees = ax.bar(ind + width, nomineesplot, width, color='#9b3c38')
# add some text for labels ,title and axes ticks
ax.set_xticks(ind+width)
ax.set_xticklabels(('小明', '小红', '小凡', '小钱', '小刘', '小赵', '小文'))
ax.legend((winners[0], nominees[0]),('奥斯卡金奖得住','奥斯卡得住提名'))
def autolabel(rects):
# attach some text labels
for rect in rects:
height = rect.get_height()
hcap = "$" + str(height) + "M"
ax.text(rect.get_x() + rect.get_width()/2. ,height, hcap,ha = 'center',va='bottom',rotation='horizontal')
autolabel(winners)
autolabel(nominees)
plt.show()
import matplotlib.pyplot as plt
labels = 'Computer Science', 'Foreign Languges','Analytical Chemistry', 'Education', 'Humanities', 'Physics', 'Biology', 'Math and Statistics', 'Engineering'
sizes = [21, 4, 7, 7, 8, 9, 10, 15, 19]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral','red', 'purple', '#f280de', 'orange', 'green']
explode = (0,0,0,0,0,0,0,0,0.1)
plt.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',colors=colors)
plt.axis('equal')
plt.show()散点图是同一组研究对象的两个变量间关系的可视化
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
students = pd.read_csv("data/ucdavis.csv")
g = sns.FacetGrid(students, palette="Set10",size=7)
g.map(plt.scatter, "momheight", "height",s=140, linewidth=.7,edgecolor = "#ffad40",color="#ff8000")
g.set_axis_labels("Mothers Heilsght", "Students Height")
plt.show()
散点图最适合研究不同变量之间的关系:
另外我们还要考虑:
气泡图展示了数据的三个维度,每个数据点有三重维度(a, b , c), xy轴的坐标表示两个维度变量,气泡的大小表示第三个维度的定量测度结果
直方图(Histogram)又称质量分布图。是一种统计报告图,由一系列高度不等的纵向条纹或线段表示数据分布的情况。 一般用横轴表示数据类型,纵轴表示分布情况。
import numpy as np import pandas as pd from scipy import stats, integrate import matplotlib.pyplot as plt #导入 import seaborn as sns sns.set(color_codes=True)#导入seaborn包设定颜色 np.random.seed(sum(map(ord, "distributions"))) x = np.random.normal(size=100) sns.distplot(x, kde=False, rug=True);#kde=False关闭核密度分布,rug表示在x轴上每个观测上生成的小细条(边际毛毯) plt.show()

当绘制直方图时,你最需要确定的参数是矩形条的数目以及如何放置它们。利用bins可以方便设置矩形条的数量。如下所示:
sns.distplot(x, bins=20, kde=False, rug=True);#设置了20个矩形条

核密度估计(Kernel Density Estimation, KDE)是一种用来估计概率密度函数的非参数方法。可以通过观测到的数据点取平均实现平滑逼近。
核密度估计是在概率论中用来估计未知的密度函数,属于非参数检验方法之一。.由于核密度估计方法不利用有关数据分布的先验知识,对数据分布不附加任何假定,是一种从数据样本本身出发研究数据分布特征的方法,因而,在统计学理论和应用领域均受到高度的重视。
核密度函数与直方图密切相关,但有时能够通过核概念用平滑性或连续性赋予实际含义。
概率密度函数(Probablity Density Function,PDF)的核是PDF的形式。这种形式不考虑非变量函数因素。
这里我们用一个鸢尾花数据集和seaborn包展示KDE图
使用seaborn 和matplotlib演示KDE图
This function combines the matplotlib hist function (with automatic calculation of a good default bin size) with the seaborn kdeplot() and rugplot() functions. It can also fit scipy.stats distributions and plot the estimated PDF over the data.
seaborn的displot()集合了matplotlib的hist()与核函数估计kdeplot的功能,增加了rugplot分布观测条显示与利用scipy库fit拟合参数分布的新颖用途。具体用法如下:
seaborn入门(一):distplot与kdeplot
seaborn.kdeplot
distplot 函数默认同时绘制直方图和KDE(核密度图)
from numpy.random import randn
import matplotlib as mpl
import seaborn as sns
import matplotlib.pyplot as plt
#引入鸢尾花数据集
df_iris = sns.load_dataset("iris")
fig, axes = plt.subplots(1,2)
# print(df_iris['petal_length'])
# print(axes[0])
# distplot 函数默认同时绘制直方图和KDE(核密度图),开启rug细条
sns.distplot(df_iris['petal_length'], ax= axes[0], rug = True)
# shade 阴影
sns.kdeplot(df_iris['petal_length'], ax = axes[1], shade = True)
plt.show()如果不需要核密度图,可以将kde参数设置成False。
sns.distplot(df_iris['petal_length'], ax= axes[0], kde = False, rug = True)

如果不需要核密度图,可以将hist参数设置成False。
sns.distplot(df_iris['petal_length'], ax= axes[0], hist = False, rug = True)

# Fitting parametric distributions拟合参数分布
# 可以利用distplot() 把数据拟合成参数分布的图形并且观察它们之间的差距,再运用fit来进行参数控制。
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="white", palette="muted", color_codes=True)
rs = np.random.RandomState(10)
# Set up the matplotlib figure
f, axes = plt.subplots(2, 2, figsize=(7, 7), sharex=True)
sns.despine(left=True)
#引入鸢尾花数据集
df_iris = sns.load_dataset("iris")
# Plot a simple histogram with binsize determined automatically
sns.distplot(df_iris['petal_length'], ax= axes[0, 0], kde = False, color="b")
# Plot a kernel density estimate and rug plot
sns.distplot(df_iris['petal_length'], ax= axes[0, 1], kde = False, color="r", rug=True)
# Plot a filled kernel density estimate
sns.distplot(df_iris['petal_length'], ax= axes[1, 0], hist = False, color="g", kde_kws={"shade": True})
# Plot a historgram and kernel density estimate
sns.distplot(df_iris['petal_length'], color="m", ax=axes[1, 1])
plt.setp(axes, yticks=[])
plt.tight_layout()
plt.show()
使用Scipy和Numpy演示KDE图
from scipy.stats.kde import gaussian_kde
from scipy.stats import norm
from numpy import linspace, hstack
import matplotlib.pyplot as plt
from matplotlib.pylab import plot,show, hist
sample1 = norm.rvs(loc=-0.1,scale=1,size=320)
sample2 = norm.rvs(loc=2.0,scale=0.6,size=130)
sample = hstack([sample1,sample2])
probDensityFun = gaussian_kde(sample)
plt.title("KDE Demonstration using Scipy and Numpy",fontsize=20)
x = linspace(-5,5,200)
plot(x,probDensityFun(x),'r')
hist(sample,normed=1,alpha=0.45,color='purple')
show()
利用kdeplot探索某大学学生消费习惯与助学金获得关系
数据集如下所示:
更多内容可好看白鲸鱼的另一个学习记录:
可视化技术栈及学习计划
数据可视化
Python数据可视化-seaborn
matplotlib 绘图可视化知识点整理
10分钟python图表绘制 | seaborn入门(一):distplot与kdeplot
Python mpl_toolkits画3D图
matplotlib basemap toolkit
matplotlib教程: http://nbviewer.jupyter.org/g...
python学习教程notes-python: http://nbviewer.jupyter.org/g...
9102年,该放弃matplotlib画图了
Pycon 2017: Python可视化库大全
Python中除了matplotlib外还有哪些数据可视化的库?
10 Useful Python Data Visualization Libraries for Any Discipline
Python Data Visualization: Comparing 7 tools
Dashboard API in Python
Bokeh Applications
pyecharts + notebook,真的不需要PPT了耶
三个步骤学习python可视化
一张图看懂如何选择正确的图表类型