数据可视化漫游(五)
来源:互联网 发布:如何用丝巾缠包带 知乎 编辑:程序博客网 时间:2024/04/28 10:38
声明:版权所有,转载请联系作者并注明出处 http://blog.csdn.net/u013719780?viewmode=contents
博主简介:风雪夜归子(Allen),机器学习算法攻城狮,喜爱钻研Meachine Learning的黑科技,对Deep Learning和Artificial Intelligence充满兴趣,经常关注Kaggle数据挖掘竞赛平台,对数据、Machine Learning和Artificial Intelligence有兴趣的童鞋可以一起探讨哦,个人CSDN博客:http://blog.csdn.net/u013719780?viewmode=contents
数据可视化有助于理解数据,在机器学习项目特征工程阶段也会起到很重要的作用,因此,数据可视化是一个很有必要掌握的武器。本系列博文就对数据可视化进行一些简单的探讨。本文使用Python的Altair对数据进行可视化。
In [2]:
%matplotlib inlineimport matplotlib.pyplot as pltimport pandas as pdimport numpy as npimport seaborn as snssns.set()sns.set_context('notebook', font_scale=1.5)cp = sns.color_palette()
In [3]:
from altair import *
In [55]:
ts = pd.read_csv('data/ts.csv')ts = ts.assign(dt = pd.to_datetime(ts.dt))ts.head()
Out[55]:
In [56]:
dfp = ts.pivot(index='dt', columns='kind', values='value')dfp.head()
Out[56]:
In [6]:
c = Chart(ts).mark_line().encode( x='dt', y='value', color='kind')c
In [57]:
c = Chart(ts).mark_line().encode( x='dt', y='value', color=Color('kind', scale=Scale(range=cp.as_hex())))c
In [7]:
df = pd.read_csv('data/iris.csv')df.head()
Out[7]:
In [8]:
c = Chart(df).mark_point(filled=True).encode( x='petalLength', y='petalWidth', color='species')c
In [9]:
c = Chart(ts).mark_line().encode( x='dt', y='value', color='kind', column='kind')c.configure_cell(height=200, width=200)
In [10]:
c = Chart(df).mark_point().encode( x='petalLength', y='petalWidth', color='species', column=Column('species', title='Petal Width v. Length by Species'))c.configure_cell(height=300, width=300)
In [11]:
tmp_n = df.shape[0] - df.shape[0]/2df['random_factor'] = (np.\ random.\ permutation(['A'] * tmp_n + ['B'] * (df.shape[0] - tmp_n)))df.head()
Out[11]:
In [12]:
c = Chart(df).mark_point().encode( x='petalLength', y='petalWidth', color='species', column=Column('species', title='Petal Width v. Length by Species'), row='random_factor')c.configure_cell(height=200, width=200)
In [49]:
# please note: this code is super speculative -- I'm# assuming there's a better way to do this and I just# don't know itc = Chart(df).mark_point(opacity=.5).encode( x='species', y='petalWidth')c25 = Chart(df).mark_tick(tickThickness=3.0, tickSize=20.0, color='r').encode( x='species', y='q1(petalWidth)')c50 = Chart(df).mark_tick(tickThickness=3.0, tickSize=20.0, color='r').encode( x='species', y='median(petalWidth)')c75 = Chart(df).mark_tick(tickThickness=3.0, tickSize=20.0, color='r').encode( x='species', y='q3(petalWidth)')LayeredChart(data=df, layers=[c, c25, c50, c75])
In [50]:
c = Chart(df).mark_bar(opacity=.75).encode( x=X('petalWidth', bin=Bin(maxbins=30)), y='count(*)', color=Color('species', scale=Scale(range=cp.as_hex())))c
In [51]:
df = pd.read_csv('data/titanic.csv')df.head()
Out[51]:
In [52]:
dfg = df.groupby(['survived', 'pclass']).agg({'fare': 'mean'})dfg
Out[52]:
In [53]:
died = dfg.loc[0, :]survived = dfg.loc[1, :]
In [54]:
c = Chart(df).mark_bar().encode( x='survived:N', y='mean(fare)', color='survived:N', column='class')c.configure( facet=FacetConfig(cell=CellConfig(strokeWidth=0, height=250)))
1 0
- 数据可视化漫游(五)
- 前端数据可视化插件(五)立体图
- Python高级数据处理与可视化(五)---数据存取
- 【D3.js数据可视化系列教程】--(五)用层画条形图
- 【D3.V3.js数据可视化系列教程】--(五)用层画条形图
- 用D3.js进行医疗数据可视化 (五) 饼图 (Pie Chart)
- 基于PetShop的数据可视化网站(五):关于登录的理解
- 基于hadoop生态圈的数据仓库实践 —— OLAP与数据可视化(五)
- 你会用吗?Linux五大数据可视化工具
- 数据可视化常用的五种方式及案例分析
- 五分钟学GIS | 时空数据可视化表达
- 五分钟学GIS | 空间数据可视化渲染技术
- R可视化学习代码(五)
- python学习(五)——可视化
- Matlab数据可视化(5):二维数据可视化 I
- 数据可视化二:Matlab数据可视化(一)
- 数据可视化三:Matlab数据可视化(二)
- 数据可视化四:Matlab数据可视化(三)
- 免费手机号码归属地API查询接口
- [推荐] Git的权限控制
- RC 脉冲分压器
- CentOS7安装GitLib
- Google已正式结束对Eclipse Android开发工具的支持
- 数据可视化漫游(五)
- Android应用程序资源管理器(Asset Manager)的创建过程分析
- 对数组进行malloc动态分配的一些总结
- ajax请求回来的数据是string将其转化成json对象
- Java中由substring方法引发的内存泄漏
- 深入理解C语言指针的奥秘
- 远程登录相关命令
- Python基础
- 程序员必须知道的几个Git代码托管平台