array(2) { ["docs"]=> array(10) { [0]=> array(10) { ["id"]=> string(3) "428" ["text"]=> string(77) "Visual Studio 2017 单独启动MSDN帮助(Microsoft Help Viewer)的方法" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(8) "DonetRen" ["tagsname"]=> string(55) "Visual Studio 2017|MSDN帮助|C#程序|.NET|Help Viewer" ["tagsid"]=> string(23) "[401,402,403,"300",404]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400964" ["_id"]=> string(3) "428" } [1]=> array(10) { ["id"]=> string(3) "427" ["text"]=> string(42) "npm -v;报错 cannot find module "wrapp"" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "zzty" ["tagsname"]=> string(50) "node.js|npm|cannot find module "wrapp“|node" ["tagsid"]=> string(19) "[398,"239",399,400]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400760" ["_id"]=> string(3) "427" } [2]=> array(10) { ["id"]=> string(3) "426" ["text"]=> string(54) "说说css中pt、px、em、rem都扮演了什么角色" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(12) "zhengqiaoyin" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400640" ["_id"]=> string(3) "426" } [3]=> array(10) { ["id"]=> string(3) "425" ["text"]=> string(83) "深入学习JS执行--创建执行上下文(变量对象,作用域链,this)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "Ry-yuan" ["tagsname"]=> string(33) "Javascript|Javascript执行过程" ["tagsid"]=> string(13) "["169","191"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511399901" ["_id"]=> string(3) "425" } [4]=> array(10) { ["id"]=> string(3) "424" ["text"]=> string(30) "C# 排序技术研究与对比" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "vveiliang" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(8) ".Net Dev" ["catesid"]=> string(5) "[199]" ["createtime"]=> string(10) "1511399150" ["_id"]=> string(3) "424" } [5]=> array(10) { ["id"]=> string(3) "423" ["text"]=> string(72) "【算法】小白的算法笔记:快速排序算法的编码和优化" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "penghuwan" ["tagsname"]=> string(6) "算法" ["tagsid"]=> string(7) "["344"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511398109" ["_id"]=> string(3) "423" } [6]=> array(10) { ["id"]=> string(3) "422" ["text"]=> string(64) "JavaScript数据可视化编程学习(二)Flotr2,雷达图" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "chengxs" ["tagsname"]=> string(28) "数据可视化|前端学习" ["tagsid"]=> string(9) "[396,397]" ["catesname"]=> string(18) "前端基本知识" ["catesid"]=> string(5) "[198]" ["createtime"]=> string(10) "1511397800" ["_id"]=> string(3) "422" } [7]=> array(10) { ["id"]=> string(3) "421" ["text"]=> string(36) "C#表达式目录树(Expression)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "wwym" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(4) ".NET" ["catesid"]=> string(7) "["119"]" ["createtime"]=> string(10) "1511397474" ["_id"]=> string(3) "421" } [8]=> array(10) { ["id"]=> string(3) "420" ["text"]=> string(47) "数据结构 队列_队列实例:事件处理" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "idreamo" ["tagsname"]=> string(40) "C语言|数据结构|队列|事件处理" ["tagsid"]=> string(23) "["246","247","248",395]" ["catesname"]=> string(12) "数据结构" ["catesid"]=> string(7) "["133"]" ["createtime"]=> string(10) "1511397279" ["_id"]=> string(3) "420" } [9]=> array(10) { ["id"]=> string(3) "419" ["text"]=> string(47) "久等了,博客园官方Android客户端发布" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(3) "cmt" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511396549" ["_id"]=> string(3) "419" } } ["count"]=> int(200) } 222 EDA cheat sheet - 爱码网

%config InlineBackend.figure_format = 'svg'

在jupyter notebook中使用这个命令绘制更清晰的图像,注意百分号后不能有空格。

单变量分析每次查看一个特征。当我们独立地分析一个特征时,我们通常最感兴趣的是它的值的分布。

1.1 数量特征

数量特征取有序的数值。这些值可以是离散的,像整数,或者是连续的,像实数,通常表达计数或者度量的含义。

使用 Histograms and density plots

# method in pandas
df['feature'].hist()
df['feature'].plot(kind='density')
# pandas的绘图函数中可以通过传入 subplot=True & layout=(m,n)来自定义绘制的多个子图的布局

# method in seaborn
sns.displot(df[feature])
# seaborn中的displot会同时绘制直方图和密度图

使用 Box plot and Violin plot

关于 Box plot 的很好的图视化解释参考 箱形图。Box plot中的离群值需要特别关注。

# method in pandas,不知道是缺少相关参数的问题还是什么,没有画出离群点,seaborn中有画
df['feature'].plot(kind = 'box')
df['feature'].plot.box()

# method in seaborn
sns.boxplot(data=df['feature'])
sns.violinplot(data=df['feature'])

1.2 类别特征和二元特征

类别特征取固定数目的值。二元特征是类别特征只有两种取值时的一个特例情况。如果在类别特征上的值可以是无序的也可以是由顺序的。

使用频率表

df['feature'].value_counts()
# 默认结果中的 entry 按照最大频率到最小频率排列

使用 Bar plot

Bar plot 是频率表的图形化展示。

# method in pandas
df['feature'].value_counts().plot.bar()

# method in seaborn
sns.countplot(x='feature', data=df) # 至少传两个参数

seaborn中的barplot() 利用矩阵条的高度反映数值变量的集中趋势,这个barplot并不是我们在此处想要使用的barplot。一定要记住,seaborn中的barplot展示的是某种变量分布的平均值 ,当需要精确观察每类数值变量(数值变量在类别变量上做groupby)的分布趋势,boxplot与violinplot往往是更好的选择。

Tips: 将多幅图对比绘制的方法

figure, axes = plt.subplots(nrows=m, ncols=n,figsize=(m*x_length,n*y_length))
sns.plot(..., ax=axes[0])
df.plot(..., ax=axes[1])
figure.show()

总结:

  1. 直方图表示数值变量的分布情况,而条形图表示类别变量的频率的分布情况。
  2. 直方图的x轴是连续的,条形图的x轴是离散的;二者的y轴都是连续的。

2. Multivariate visualization

多变量图表允许我们去看两个或多个变量(注意:可以通过技巧在二维平面上绘制三个变量之间的某些关系) 之间的关系。

2.1 数量 vs 数量

使用 Correlation matrix and heatmap

# method : {‘pearson’, ‘kendall’, ‘spearman’}
corr_matrix = df[num_features].corr()
sns.heatmap(corr_matrix)

使用 Scatter plot

# method in matplotlib
plt.scatter(df['num_x'], df['num_y'])

# method in pandas
df.plot.scatter(x='num_x', y= 'num_y')

# method in seaborn
sns.jointplot(x='num_x', y='num_y', data = df, kind='scatter')

# this is the smoothed version of bivariate distribution
sns.jointplot('num_x', 'num_y', data=df, kink='kde')

使用 Scatterplot matrix

# method in pandas 
pd.scatter_matrix(df['num_features'])

# method in seaborn
sns.pairplot(df['num_features'])

2.2 数量 vs 类别

前面我们提到过可以在二维平面展示三个变量之间的关系,这种技巧就是利用pandas或者seaborn的语义映射能力,将第三个变量(只能是类别)用不同颜色区分开来。下面是一个例子:

sns.scatter('num_x', 'num_y', data=df, hue='cate_third_var')

使用 Box plot and Violin plot

一般是观察一个数值变量在不同类别下的分布情况

sns.boxplot(x='..._feat', y='..._feat', orient='v')
# orient 默认为'v',这时传给x类别特征,传给y数值特征;当x,y的特征类型反着传时,必须把 orient设置为'h'才能正确绘图。orient可以看作时数值特征轴的方向。

# sns.violinplot()类似

使用 sns.catplot()

当我们想要一次在两个类别变量维度来分析一个数值变量时,在seaborn中有一个非常适合的函数叫做catplot()。

sns.catplot(x='cate_feature1', y='num_feature', col='cate_feature2', data=df, kind='box', col_wrap=n, height=m, aspect=.8)

上面的代码将会画m*n个子图,每个子图中是一个sns.boxplot(x='cate_feature1', y='num_feature', data=df), 但是每个子图中的数据df是cate_feature2取某个类别时的子集。

2.3 类别 vs 类别

原理是通过条形图来描述类别的分布,并且通过颜色语义映射的方法来加入第二个类别变量。注意,这种方法研究的主要对象仍然是第一个类别变量,语义映射只是把第二个类别变量对其的影响表示出来,语义映射的变量相当于辅助变量。

sns.countplot(x='cate_feature1', hue='cate_feature2', data=df)

使用 Contingency table

除了使用图形的方式来分析类别变量,还有一个来自统计学的传统工具:列联表(contingency table)也叫做交叉表(cross tabulation)。它将多个类别变量的频率分布用一张表格来表示。特别的是,它允许我们通过沿着一行或是沿着一列来查看一个变量在其他变量某些条件下的分布。

pd.crosstab(df['cate_feautre1'], df['cate_feature2'])

3. Whole dataset

3.1 Naive approach

最简单的方法就是使用前面介绍的分析一个,两个或者是三个变量的方法逐个地探索完整个数据集。也可以使用sns.pairplot()或者pd.scatter_matrix()一次完成。

3.2 Dimensional reduction

使用 t-SNE

from sklearn.manifold import TSNE
from sklearn.preprocessing import StandardScaler

# step1 对数值变量做归一化处理
# step2 对两类变量用LabelEncoder()
tsne = TSNE(random_state=17)
tsne_repr = tsne.fit_transform(X_scaled)

plt.scatter(tsne_repr[:,0], tsne_repr[:,1], alpha =.5)

相关文章: