大数据处理时的python和R语言

本文涉及的产品
实时数仓Hologres,5000CU*H 100GB 3个月
智能开放搜索 OpenSearch行业算法版,1GB 20LCU 1个月
实时计算 Flink 版,5000CU*H 3个月
简介: 【5月更文挑战第5天】本文讨论了在语言Python 和R中数据处理时的框架,比如Python中的 OpenCV, Matplotlib, NumPy, Pandas, 和Seaborn。

1 数据处理中的概率

由于python在计算领域是高度精确的,同时也有大量的数据处理库用于人工智能,日常处理等等。

撕裂的宇宙3.png

仅仅是开源在python中就有大量的库用于处理,比如opencv,matplotlib,numpy,pandas,也有直接提供界面UI交互的seaborn框架。

常用的工具包括 python 和 R 语言都提供了完整的支持。

数据处理离不开概率,在很多场合都可能用到,比如python内置的 随机变量发生器。

    random.shuffle(x, [, random])

该函数将x 随机放入队列sequence,打乱成伪随机的状态,属于经典的数学方法。

random 随机变量发生器函数

    uniform within range    分布均匀 

支持的分布函数(不完整)

    uniform            # 均匀分布
    triangular        # 三角函数相关
    lognormal        # 对数相关分布
    gamma            # 伽马相关分布
    beta            # beta 相关分布
    pareto            # 帕累托相关分布
    weibull            # 威布尔相关分布 

distributions on the circle # 圆上的分布

    circular uniform     # 圆形分布
    von mises        # 冯·米斯

曾经在某个巧合的场景使用了某些类型的库,这里做些简单对比,并不全面,希望各个阵营的大佬多指正。

这里不重复相关书籍的概率公理,它们可以容易在图书馆或网上书城找到。

2 概率密度函数简单对比

2.1 R 语言

R中的pt()(用于求已知t值和df的t分布累计概率值,等同于EXCEL中的TDIST())、qt()(用于求已知p值和df的t分布的t区间值,等同于EXCEL中的TINV()。

r语言几个函数:dt,pt,qt,rt分别与dnorm,rnorm,pnorm,qnorm和rnorm对应 > * dt() 的返回值是正态分布概率密度函数(density)。

指令的函数和参数介绍:

> * pt()返回值是正态分布的分布函数(probability)
> * 函数qt()的返回值是给定概率p后的下百分位数(quantitle)
> * rt()的返回值是n个正态分布随机 
  • x, q: 矢量的量。
  • p 矢量的概率。

  • n : 观察的次数,如果长度大于1,则被认为是符合需求的。

  • df : 自由度,如果大于0,也可能非整型,df 为 Inf 对象是允许的(概率统计对象。)

  • ncp : 非中心分布必须的参数,当前期望为 rt(), 仅仅在绝对值 abs(ncp) <= 37.62 使用。如果省略该参数,使用默认的中心极限T分布。

  • log, log.p logical; 如果为 TRUE, 概率p 被以 log(p) 提供。 if TRUE, probabilities p are given as log(p).

  • logical; 如果为默认的 TRUE (default), 概率为 P[X ≤ x], 否则概率为:P[X > x].

2.2 Python基于matplotlib的高级框架

Seaborn是基于matplotlib的Python数据可视化库。它提供了用于绘制引人入胜且内容丰富的统计图形的高级界面。

如下为常用函数功能,用于将关系图绘制到FacetGrid上的图形级界面。

2.2.0 Relational plots 关系图

relplot(,x, y, hue, size, style, data...)        
        Figure-level interface for drawing relational plots onto a FacetGrid. 

绘制一个散点图,可能会出现多个语义分组

scatterplot(* [,x,y,hue,style, size...]) 
        Draw a scater plot with possibility of several semantic groupings.

lineplot(*, [,x,y,hue,size,style,data ...])
        Draw a line plot with possibility of serveral semantic groupings

2.2.1 绘图库分布图,分类图,回归图,矩阵图,其他

  • Distribution plots 分布图

  • 用于将分布图绘制到FacetGrid上的图形级界面。

    displot([data, x,y,hue, row, col ...])    
        Figure-level interface for drawing distribution plots onto a FaceGrid
    
  • 绘制单变量或双变量直方图以显示数据集的分布。

    histplot([data, x,y,hue, weights, stat,...])
        Plot univeriate or bivariate histograms to show distributions of datasets.
    
  • 使用核密度估计图绘制单变量或双变量分布

    kdeplot([x,y,shade,vertical,kernel, bw, ...])
        Plot univariate or bivariate distributions using kernel density estimation.
    
  • 绘制经验累积分布函数。

    ecdfplot([data, x,y,hue,weights, stat,...])
        Plot empirical cumulative distribution functions.
    
  • 通过沿x和y轴绘制刻度线来绘制边际分布图

    rugplot([x,height,axis, ax,data,y,hue,...])
        Plot marginal distributions by drawing ticks along the x and y axes.
    
  • 已弃用:灵活地绘制观测值的统一分布。

    distplot([a,bins,hist,kde,rug,fit,...])
        DEPRECATED:Flexibly plot a univeriate distribution of observations.
    
* Categorical plots    分类图

图形级界面,用于将分类图绘制到。

    catplot(* [,x,y,hue,data, row,col,...])
        Figure-level interface for drawing categorical plots onto a facetfrid

绘制一个散点图,其中一个变量是分类的。

    stripplot(* [, x,y,hue,data,order,...])
        Draw a scatterplot where one variable is categorical

绘制一个具有非重叠点的分类散点图。

    swarmplot(* [,x,y,hue,data,order,...])
        Draw a categorical scatterplot with non-overlapping points.

为更大的数据集绘制增强的箱形图

    boxplot(* [, x,y,hue,data,order,...])
        Draw an enhanced box plot for larger datasets.

使用散点图字形显示点估计和置信区间。

    pointplot(* [,x,y,hue,data,order,...])
        Show point estimates and confidence intervals using scatter plot glyphs.

将点估计和置信区间显示为矩形条。

    barplot(* [, x,y, hue, data,order,...])
         Show point estimates and confidence intervals as rectangular bars.

用条形图显示每个分类箱中的观测值。

     countplot(* [, x,y,hue,data,order,...])
         Show the counts of observations in each categorical bin using bars.
  • Regression plots 回归图

    绘制 数据和回归模型 以适合FacetGrid

    implot(* [,x,y,data,hue,col,row, ...])
            Plot data and regression model fits across a FacetGrid
    

    绘制数据并拟合线性回归模型

    regplot(* [,x,y,data,x_estimator,...])
            Plot data and a linear regression model fit
    

    求线性回归的残差

    residplot(* [,x,y,lowess,...])
            PLot the residuals of a linear regression
    
  • Matrix plots 矩阵图

    绘制矩形数据作为颜色编码矩阵

    heatmap(data, * [, vmin, vmax, cmap, center,...])

           Plot rectangular data as a color-encoded matrix
    

    将矩阵数据集绘制为分层聚类的热图。

    clustermap(data, * [, pivot_kws, method,...])

           Plot a matrix dataset as a hierarchically-clustered heatmap.
    
  • Multi-plot grids 多图网格

    Facet grids 多面网格

    用于绘制条件关系的多图网格。

    FaceGrid(data, * [,row, col, hue, ...])
        Multi-plot grid for plotting conditional relationships.
    

    应用绘图条件关系

    FaceGrid.map(self,func, *args, **kwargs)
        Apply a plotting conditional relationships
    

    类似 .map ,但是此函数将args作为字符串传递并将数据插入kwargs。

    FaceGrid.map_dataframe(self, func, *args,...)
       Like .map but passes args as strings and inserts data in kwargs.
    
    • 成对网格 pair grids

    在数据集中绘制成对关系

       pairplot(data, * [, hue, hue_order, palette, ...])
           Plot pairwise relationshops in a dataset.
    

    子图网格,用于绘制数据集中的成对关系

       PairGrid(data, * [, hue, hue_order, palette, ...])
           Subplot grid for plotting pairwise relationships in a dataaset
    

    在每个子图中 绘制具有相同功能的图。

       PairGrid.map(self, func, ** kwargs)
           Plot with the same function in every subplot.
    

    在每个对角线子图上使用单变量函数绘制。

       PairGrid.map_diag(self, func, ** kwargs)
           Plot with a univariate function on each diagonal subplot.
    

    在非对角子图上具有二元函数的图

       PairGrid.map_offdiag(self, func, ** kwargs)
           Plot with a bivariate function on the off-diagonal subplots
    

    在下对角线子图上使用双变量函数绘制

    PariGrid.map_lower(self, func, ** kwargs)
        Plot with a bivariate function on the lower diagonal subplots
    

    在上对角线子图上使用双变量函数绘制

    PairGrid.map_upper(self, func, ** kwargs)
        Plot with a bivariate function on the upper diagonal subplots
    
  • 联合网格 Joint grids

    用双变量和单变量图绘制两个变量的图。

    jointplot(* [, x, y, data, kind, color, …])
            Draw a plot of two variables with bivariate and univariate graphs.
    

    用于绘制带有边际单变量图的二元图的网格。

    JointGrid(* [, x, y, data, height, ratio, …])
            Grid for drawing a bivariate plot with marginal univariate plots.
    

    通过传递关节轴和边缘轴的函数来绘制图。

    JointGrid.plot(self, joint_func, …)
            Draw the plot by passing functions for joint and marginal axes.
    

    在网格的关节轴上绘制一个双变量图。

    JointGrid.plot_joint(self, func, ** kwargs)
            Draw a bivariate plot on the joint axes of the grid.
    

    在每个边缘轴上绘制单变量图。

    JointGrid.plot_marginals(self, func, ** kwargs)
            Draw univariate plots on each marginal axes.
    

2.3 其他主题

  • Themes 主题

    一次性设置多个主题参数

    set_theme([context, style, palette, font, …])
            Set multiple theme parameters in one step.
    

    返回图的 易于阅读的美学风格的参数字典。

    axes_style([style, rc])
            Return a parameter dict for the aesthetic style of the plots.
    

    设置绘图的美学风格

    set_style([style, rc])
            Set the aesthetic style of the plots.
    

    返回参数dict以缩放图形元素。

    plotting_context([context, font_scale, rc])
            Return a parameter dict to scale elements of the figure.
    

    设置绘图上下文参数。

    set_context([context, font_scale, rc])
            Set the plotting context parameters.
    

    更改matplotlib颜色速记的解释方式。

    set_color_codes([palette])
            Change how matplotlib color shorthands are interpreted.
    

    将所有RC参数恢复为默认设置。

    reset_defaults()
            Restore all RC params to default settings.
    

    将所有RC参数恢复为原始设置(尊重自定义rc)

    reset_orig()
            Restore all RC params to original settings (respects custom rc).
    

    set_theme()的别名,这是首选接口。

    set(* args, ** kwargs)
            Alias for set_theme(), which is the preferred interface.
    
  • 调色板 Color palettes

    使用深浅的调色板设置matplotlib颜色周期

    set_palette(palette[, n_colors, desat, …])

          Set the matplotlib color cycle using a seaborn palette.
    

    返回定义调色板的颜色列表或连续颜色图。

    color_palette([palette, n_colors, desat, …])

          Return a list of colors or continuous colormap defining a palette.
    

    在HUSL色相空间中获得一组均匀分布的颜色。

    husl_palette([n_colors, h, s, l, as_cmap])

          Get a set of evenly spaced colors in HUSL hue space.
    

    在HLS色相空间中获得一组均匀分布的颜色。

    hls_palette([n_colors, h, l, s, as_cmap])

          Get a set of evenly spaced colors in HLS hue space.
    

    从cubehelix系统制作顺序调色板。

    cubehelix_palette([n_colors, start, rot, …])

          Make a sequential palette from the cubehelix system.
    

    制作从深色到彩色混合的顺序调色板。

    dark_palette(color[, n_colors, reverse, …])

          Make a sequential palette that blends from dark to color.
    

    制作从浅色到彩色混合的顺序调色板。

    light_palette(color[, n_colors, reverse, …])

          Make a sequential palette that blends from light to color.
    

    在两种HUSL颜色之间创建一个发散的调色板。

    diverging_palette(h_neg, h_pos[, s, l, sep, …])

          Make a diverging palette between two HUSL colors.
    

    制作一个在一系列颜色之间混合的调色板。

    blend_palette(colors[, n_colors, as_cmap, input])

          Make a palette that blends between a list of colors.
    

    使用xkcd颜色调查中的颜色名称制作调色板。

    xkcd_palette(colors)

          Make a palette with color names from the xkcd color survey.
    

    使用Crayola蜡笔的颜色名称制作调色板。

    crayon_palette(colors)

          Make a palette with color names from Crayola crayons.
    

    从matplotlib调色板返回不连续的颜色。

    mpl_palette(name[, n_colors, as_cmap])

          Return discrete colors from a matplotlib palette.
    
  • 面板小部件 Palette widgets

    从ColorBrewer集中选择一个调色板。

     choose_colorbrewer_palette(data_type[, as_cmap])
    
             Select a palette from the ColorBrewer set.
    

    启动一个交互式窗口小部件,以创建一个顺序的cubehelix调色板。

     choose_cubehelix_palette([as_cmap])
    
             Launch an interactive widget to create a sequential cubehelix palette.
    

    启动一个交互式小部件以创建一个浅色顺序调色板。

     choose_light_palette([input, as_cmap])
    
             Launch an interactive widget to create a light sequential palette.
    

    启动一个交互式小部件以创建一个黑暗的顺序调色板。

     choose_dark_palette([input, as_cmap])
    
             Launch an interactive widget to create a dark sequential palette.
    

    启动交互式小部件以选择不同的调色板

     choose_diverging_palette([as_cmap])
    
             Launch an interactive widget to choose a diverging color palette
    
  • 其他实用功能 Utility functions

    从在线存储库中加载示例数据集(需要Internet)

         load_dataset(name[, cache, data_home])
    
                 Load an example dataset from the online repository (requires internet).
    

    报告可用的示例数据集,对于报告问题很有用。

         get_dataset_names()
    
                 Report available example datasets, useful for reporting issues.
    

    返回示例数据集的高速缓存目录的路径。

         get_data_home([data_home])
    
                 Return a path to the cache directory for example datasets.
    

    从情节中删除顶部和右侧的。

         despine([fig, ax, top, right, left, bottom, …])
    
                 Remove the top and right spines from plot(s).
    

    将颜色的饱和度通道减少一些百分比。

         desaturate(color, prop)
    
                 Decrease the saturation channel of a color by some percent.
    

    返回具有相同色调的完全饱和的颜色。

         saturate(color)
    
                 Return a fully saturated color with the same hue.
    

    独立操纵颜色的h,l或s通道。

         set_hls_values(color[, h, l, s])
    
                 Independently manipulate the h, l, or s channels of a color.                
    

3 小结

R语言在教学中使用较多,对各种经典的概率函数和分布都可以直接生成图形。

该py框架只要有一些概率基础都可以使用,上手较快,文档和实例也较多。
其框架中的其他内容的使用,多偏向前端。

配合交互式绘图库 plotly, Bokeh,之类的交互式web 图形 python库,可以满足中小项目的使用需求。

Bokeh是一个针对现代人的Python交互式可视化库,支持Web浏览器进行演示。

其目标是为各种图形提供优雅,简洁的结构, 并通过大型交互提供高性能的交互性或流数据集。

可以帮助任何想要快速和轻松创建交互式绘图,仪表板和数据应用程序。

这里做个简单的记录。

参考资源。

https://www.pydata.org
相关实践学习
基于MaxCompute的热门话题分析
本实验围绕社交用户发布的文章做了详尽的分析,通过分析能得到用户群体年龄分布,性别分布,地理位置分布,以及热门话题的热度。
SaaS 模式云数据仓库必修课
本课程由阿里云开发者社区和阿里云大数据团队共同出品,是SaaS模式云原生数据仓库领导者MaxCompute核心课程。本课程由阿里云资深产品和技术专家们从概念到方法,从场景到实践,体系化的将阿里巴巴飞天大数据平台10多年的经过验证的方法与实践深入浅出的讲给开发者们。帮助大数据开发者快速了解并掌握SaaS模式的云原生的数据仓库,助力开发者学习了解先进的技术栈,并能在实际业务中敏捷的进行大数据分析,赋能企业业务。 通过本课程可以了解SaaS模式云原生数据仓库领导者MaxCompute核心功能及典型适用场景,可应用MaxCompute实现数仓搭建,快速进行大数据分析。适合大数据工程师、大数据分析师 大量数据需要处理、存储和管理,需要搭建数据仓库?学它! 没有足够人员和经验来运维大数据平台,不想自建IDC买机器,需要免运维的大数据平台?会SQL就等于会大数据?学它! 想知道大数据用得对不对,想用更少的钱得到持续演进的数仓能力?获得极致弹性的计算资源和更好的性能,以及持续保护数据安全的生产环境?学它! 想要获得灵活的分析能力,快速洞察数据规律特征?想要兼得数据湖的灵活性与数据仓库的成长性?学它! 出品人:阿里云大数据产品及研发团队专家 产品 MaxCompute 官网 https://www.aliyun.com/product/odps&nbsp;
目录
相关文章
|
2月前
|
存储 算法 数据挖掘
【2023年中国高校大数据挑战赛 】赛题 B DNA 存储中的序列聚类与比对 Python实现
本文介绍了2023年中国高校大数据挑战赛赛题B的Python实现方法,该赛题涉及DNA存储技术中的序列聚类与比对问题,包括错误率分析、序列聚类、拷贝数分布图的绘制以及比对模型的开发。
55 1
【2023年中国高校大数据挑战赛 】赛题 B DNA 存储中的序列聚类与比对 Python实现
|
1天前
|
机器学习/深度学习 算法 搜索推荐
从理论到实践,Python算法复杂度分析一站式教程,助你轻松驾驭大数据挑战!
【10月更文挑战第4天】在大数据时代,算法效率至关重要。本文从理论入手,介绍时间复杂度和空间复杂度两个核心概念,并通过冒泡排序和快速排序的Python实现详细分析其复杂度。冒泡排序的时间复杂度为O(n^2),空间复杂度为O(1);快速排序平均时间复杂度为O(n log n),空间复杂度为O(log n)。文章还介绍了算法选择、分而治之及空间换时间等优化策略,帮助你在大数据挑战中游刃有余。
13 4
|
4天前
|
机器学习/深度学习 数据可视化 大数据
驾驭股市大数据:Python实战指南
【10月更文挑战第1天】随着信息技术的发展,投资者现在能够访问到前所未有的海量金融数据。本文将指导您如何利用Python来抓取当前股市行情的大数据,并通过分析这些数据为自己提供决策支持。我们将介绍从数据获取到处理、分析以及可视化整个流程的技术方法。
13 2
|
20天前
|
存储 大数据 索引
解锁Python隐藏技能:构建高效后缀树Suffix Tree,处理大数据游刃有余!
通过构建高效的后缀树,Python程序在处理大规模字符串数据时能够游刃有余,显著提升性能和效率。无论是学术研究还是工业应用,Suffix Tree都是不可或缺的强大工具。
32 6
|
26天前
|
机器学习/深度学习 数据挖掘 大数据
大数据时代的“淘金术”:Python数据分析+深度学习框架实战指南
在大数据时代,数据被视为新财富源泉,而从海量信息中提取价值成为企业竞争的核心。本文通过对比方式探讨如何运用Python数据分析与深度学习框架实现这一目标。Python凭借其强大的数据处理能力及丰富库支持,已成为数据科学家首选工具;而TensorFlow和PyTorch等深度学习框架则为复杂模型构建提供强有力的技术支撑。通过融合Python数据分析与深度学习技术,我们能在各领域中发掘数据的无限潜力。无论是商业分析还是医疗健康,掌握这些技能都将为企业和社会带来巨大价值。
44 6
|
2天前
|
大数据 关系型数据库 数据库
python 批量处理大数据写入数据库
python 批量处理大数据写入数据库
10 0
|
2月前
|
大数据 机器人 数据挖掘
这个云ETL工具配合Python轻松实现大数据集分析,附案例
这个云ETL工具配合Python轻松实现大数据集分析,附案例
|
2月前
|
关系型数据库 MySQL 大数据
教你使用Python玩转MySQL数据库,大数据导入不再是难题!
教你使用Python玩转MySQL数据库,大数据导入不再是难题!
|
2月前
|
分布式计算 大数据 API
|
2月前
|
数据采集 数据可视化 大数据
【优秀python大屏案例】基于python flask的前程无忧大数据岗位分析可视化大屏设计与实现
本文介绍了一个基于Python Flask框架的前程无忧大数据岗位分析可视化大屏系统,该系统通过爬虫技术采集招聘数据,利用机器学习算法进行分析,并以可视化大屏展示,旨在提高招聘市场数据分析的效率和准确性,为企业提供招聘决策支持和求职者职业规划参考。

相关产品

  • 云原生大数据计算服务 MaxCompute