Python 数据可视化高级应用指南

【交互式数据可视化神器】Bokeh完全指南:10种高级图表+实战案例 | Python开发必备技能 Bokeh 是一个针对现代 Web 浏览器的交互式可视化库,专注于为大型数据集提供优雅、简洁的呈现。与 Matplotlib 和 Seaborn 等传统静态可视化库不同,Bokeh 生成的是在浏览器中渲染的交互式图表,具有缩放、平移、悬停等丰富的互动功能。 Bokeh 的核心理念是创建面向 Web 的可视化工具,它使用现代 Web 技术(如 HTML5 Canvas 和 WebGL)实现高性能图形渲染,无需依赖 JavaScript 编程即可在 Python 中构建复杂的可视化项目。 阅读详情

Python 数据可视化高级应用指南

1. 数据可视化基础

Python 的数据可视化主要通过 Matplotlib、Seaborn 和 Plotly 等库实现。

import matplotlib.pyplot as plt

# 简单的折线图
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.plot(x, y)
plt.title("Simple Line Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

2. Matplotlib 高级应用

2.1 子图

import matplotlib.pyplot as plt
import numpy as np

# 创建子图
fig, axes = plt.subplots(2, 2, figsize=(10, 8))

# 第一个子图
x = np.linspace(0, 10, 100)
y = np.sin(x)
axes[0, 0].plot(x, y)
axes[0, 0].set_title("Sine Wave")

# 第二个子图
y = np.cos(x)
axes[0, 1].plot(x, y)
axes[0, 1].set_title("Cosine Wave")

# 第三个子图
y = np.tan(x)
axes[1, 0].plot(x, y)
axes[1, 0].set_title("Tangent Wave")

# 第四个子图
y = np.exp(x)
axes[1, 1].plot(x, y)
axes[1, 1].set_title("Exponential Function")

plt.tight_layout()
plt.show()

2.2 样式定制

import matplotlib.pyplot as plt
import numpy as np

# 自定义样式
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

plt.plot(x, y1, color='red', linestyle='--', linewidth=2, marker='o', markersize=5, label='Sin')
plt.plot(x, y2, color='blue', linestyle='-', linewidth=2, marker='s', markersize=5, label='Cos')

plt.title("Customized Plot", fontsize=16, fontweight='bold')
plt.xlabel("X-axis", fontsize=14)
plt.ylabel("Y-axis", fontsize=14)
plt.legend(fontsize=12, loc='upper right')
plt.grid(True, linestyle='--', alpha=0.7)

plt.show()

2.3 3D 图表

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

# 创建 3D 图表
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')

# 生成数据
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
x, y = np.meshgrid(x, y)
z = np.sin(np.sqrt(x**2 + y**2))

# 绘制表面图
ax.plot_surface(x, y, z, cmap='viridis')

ax.set_title("3D Surface Plot")
ax.set_xlabel("X-axis")
ax.set_ylabel("Y-axis")
ax.set_zlabel("Z-axis")

plt.show()

3. Seaborn 高级应用

3.1 统计图表

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# 生成数据
np.random.seed(42)
data = np.random.normal(size=1000)

# 直方图
plt.figure(figsize=(10, 6))
sns.histplot(data, bins=30, kde=True)
plt.title("Histogram with KDE")
plt.show()

# 箱线图
data = [np.random.normal(size=100) for _ in range(3)]
plt.figure(figsize=(10, 6))
sns.boxplot(data=data)
plt.title("Box Plot")
plt.show()

# 小提琴图
plt.figure(figsize=(10, 6))
sns.violinplot(data=data)
plt.title("Violin Plot")
plt.show()

3.2 分类图表

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# 生成数据
data = pd.DataFrame({
    'category': ['A', 'B', 'C', 'D'] * 25,
    'value': np.random.randn(100)
})

# 条形图
plt.figure(figsize=(10, 6))
sns.barplot(x='category', y='value', data=data)
plt.title("Bar Plot")
plt.show()

# 计数图
plt.figure(figsize=(10, 6))
sns.countplot(x='category', data=data)
plt.title("Count Plot")
plt.show()

# 点图
plt.figure(figsize=(10, 6))
sns.pointplot(x='category', y='value', data=data)
plt.title("Point Plot")
plt.show()

3.3 相关性分析

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# 生成数据
np.random.seed(42)
data = pd.DataFrame({
    'x': np.random.randn(100),
    'y': np.random.randn(100),
    'z': np.random.randn(100)
})

# 散点图
plt.figure(figsize=(10, 6))
sns.scatterplot(x='x', y='y', data=data)
plt.title("Scatter Plot")
plt.show()

# 相关性热图
plt.figure(figsize=(10, 6))
corr = data.corr()
sns.heatmap(corr, annot=True, cmap='coolwarm')
plt.title("Correlation Heatmap")
plt.show()

# 配对图
plt.figure(figsize=(10, 6))
sns.pairplot(data)
plt.title("Pair Plot")
plt.show()

4. Plotly 高级应用

4.1 交互式图表

import plotly.express as px
import pandas as pd
import numpy as np

# 生成数据
np.random.seed(42)
data = pd.DataFrame({
    'x': np.linspace(0, 10, 100),
    'y': np.sin(np.linspace(0, 10, 100)),
    'z': np.cos(np.linspace(0, 10, 100))
})

# 交互式折线图
fig = px.line(data, x='x', y=['y', 'z'], title='Interactive Line Plot')
fig.show()

# 交互式散点图
fig = px.scatter(data, x='x', y='y', size='z', color='z', title='Interactive Scatter Plot')
fig.show()

# 交互式 3D 散点图
fig = px.scatter_3d(data, x='x', y='y', z='z', color='z', title='Interactive 3D Scatter Plot')
fig.show()

4.2 地理图表

import plotly.express as px

# 加载内置数据集
df = px.data.gapminder()

# 地理散点图
fig = px.scatter_geo(df[df['year'] == 2007], 
                     locations="iso_alpha", 
                     size="pop", 
                     color="continent", 
                     hover_name="country",
                     projection="natural earth",
                     title="World Population by Country (2007)")
fig.show()

#  choropleth 地图
fig = px.choropleth(df[df['year'] == 2007], 
                    locations="iso_alpha", 
                    color="lifeExp", 
                    hover_name="country",
                    color_continuous_scale=px.colors.sequential.Plasma,
                    title="Life Expectancy by Country (2007)")
fig.show()

4.3 仪表板

import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np

# 创建子图
fig = make_subplots(rows=2, cols=2, subplot_titles=('Line Plot', 'Bar Plot', 'Histogram', 'Scatter Plot'))

# 生成数据
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# 添加图表
fig.add_trace(go.Scatter(x=x, y=y1, name='Sin'), row=1, col=1)
fig.add_trace(go.Bar(x=[1, 2, 3, 4, 5], y=[10, 20, 30, 40, 50], name='Bar'), row=1, col=2)
fig.add_trace(go.Histogram(x=np.random.randn(1000), name='Histogram'), row=2, col=1)
fig.add_trace(go.Scatter(x=np.random.randn(100), y=np.random.randn(100), mode='markers', name='Scatter'), row=2, col=2)

# 更新布局
fig.update_layout(height=600, width=800, title_text="Dashboard")
fig.show()

5. 实际应用场景

5.1 股票分析

import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
import seaborn as sns

# 下载股票数据
ticker = "AAPL"
data = yf.download(ticker, start="2023-01-01", end="2023-12-31")

# 绘制收盘价
plt.figure(figsize=(12, 6))
plt.plot(data['Close'])
plt.title(f"{ticker} Closing Price")
plt.xlabel("Date")
plt.ylabel("Price")
plt.grid(True)
plt.show()

# 绘制成交量
plt.figure(figsize=(12, 6))
plt.bar(data.index, data['Volume'])
plt.title(f"{ticker} Volume")
plt.xlabel("Date")
plt.ylabel("Volume")
plt.grid(True)
plt.show()

# 绘制移动平均线
data['MA50'] = data['Close'].rolling(window=50).mean()
data['MA200'] = data['Close'].rolling(window=200).mean()

plt.figure(figsize=(12, 6))
plt.plot(data['Close'], label='Close')
plt.plot(data['MA50'], label='MA50')
plt.plot(data['MA200'], label='MA200')
plt.title(f"{ticker} Moving Averages")
plt.xlabel("Date")
plt.ylabel("Price")
plt.legend()
plt.grid(True)
plt.show()

5.2 销售数据分析

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

# 生成销售数据
np.random.seed(42)
dates = pd.date_range('2023-01-01', '2023-12-31', freq='D')
sales = np.random.randn(365) * 100 + 1000
products = ['A', 'B', 'C'] * 121 + ['A'] * 2

 data = pd.DataFrame({
    'date': dates,
    'sales': sales,
    'product': products
})

# 按月份汇总
 data['month'] = data['date'].dt.month
monthly_sales = data.groupby('month')['sales'].sum().reset_index()

# 绘制月度销售
plt.figure(figsize=(12, 6))
sns.barplot(x='month', y='sales', data=monthly_sales)
plt.title("Monthly Sales")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.show()

# 按产品汇总
product_sales = data.groupby('product')['sales'].sum().reset_index()

# 绘制产品销售
plt.figure(figsize=(12, 6))
sns.pie(x='sales', y='product', data=product_sales, autopct='%1.1f%%')
plt.title("Product Sales Distribution")
plt.show()

# 绘制销售趋势
plt.figure(figsize=(12, 6))
sns.lineplot(x='date', y='sales', hue='product', data=data)
plt.title("Sales Trend by Product")
plt.xlabel("Date")
plt.ylabel("Sales")
plt.show()

5.3 数据科学分析

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import load_iris

# 加载数据集
iris = load_iris()
data = pd.DataFrame(data=iris.data, columns=iris.feature_names)
data['target'] = iris.target
data['target_name'] = data['target'].map({0: 'setosa', 1: 'versicolor', 2: 'virginica'})

# 绘制配对图
plt.figure(figsize=(12, 10))
sns.pairplot(data, hue='target_name')
plt.title("Iris Dataset Pair Plot")
plt.show()

# 绘制相关性热图
plt.figure(figsize=(10, 8))
corr = data.corr()
sns.heatmap(corr, annot=True, cmap='coolwarm')
plt.title("Iris Dataset Correlation Heatmap")
plt.show()

# 绘制箱线图
plt.figure(figsize=(12, 6))
sns.boxplot(data=data, orient='h')
plt.title("Iris Dataset Box Plot")
plt.show()

6. 最佳实践

  1. 选择合适的图表类型:根据数据类型和分析目的选择合适的图表类型。
  2. 数据预处理:在可视化之前对数据进行清洗和预处理。
  3. 图表定制:根据需要定制图表的样式、颜色、标签等。
  4. 交互性:对于复杂数据,使用交互式图表提高用户体验。
  5. 性能优化:对于大型数据集,使用适当的方法提高可视化性能。
  6. 文档化:为图表添加标题、标签和图例,提高可读性。
  7. 导出和分享:将图表导出为适当的格式,方便分享和展示。

7. 总结

Python 的数据可视化库提供了丰富的功能,从基本的折线图、柱状图到复杂的 3D 图表和交互式仪表板。通过掌握这些高级应用,我们可以更有效地分析和展示数据。

在实际应用中,数据可视化可以用于股票分析、销售数据分析、数据科学分析等多种场景,帮助我们更好地理解数据,做出更明智的决策。

希望本文对你理解和应用 Python 数据可视化有所帮助!

Python数据可视化全攻略:主流图表库详解与实战案例 本文全面介绍了Python中主要的数据可视化库,包括Matplotlib、Seaborn、Plotly和PyG2Plot。Matplotlib作为基础绘图库,提供了高度定制化的图表功能;Seaborn简化了统计图形的创建过程;Plotly支持丰富的交互式可视化;PyG2Plot则提供企业级图表解决方案。文章通过代码示例展示了各库的核心特点和应用场景,如绘制K线图、多变量分析、交互式时间序列等,为数据科学工作者提供了全面的可视化工具参考。这些库各有侧重,能满足从基础到高级的不同可视化需求。 阅读详情

相关推荐

【交互式数据可视化】Plotly完全指南:10种高级图表+实战案例 | Python数据分析必备技能

Plotly 以其强大的交互式可视化能力和现代的美学设计,成为 Python 数据可视化领域的重要工具。原生交互功能:提供丰富的用户交互选项美观的默认样式:符合现代设计审美多样的图表类型:支持从简单到复杂的各类可视化需求Web 兼容性:轻松集成到 Web 应用程序中与 Dash 框架集成:快速构建数据仪表板。

熵数实验室 2652

Python常用可视化实例集

目录 1、介绍 2、单变量可视化 2.1 直方图@数值特征 2.1.1 DataFrame的hist()方法 2.1.2 seaborn的distploy()实现 2.1.3 matplotlib的dist()方法 2.2 密度图@数值特征 2.2.1 DataFrame的plot()实现 2.2.2 seaborn的distploy()实现 2.3 箱型图@数值特征-sns.boxplot() ​2.4 提琴形图@数值特征-sns.violinplot() 2.5 条形图...

独木不林的博客 4396

Python数据可视化实战应用万字长文从入门到高端(建议收藏)

前言 以下是我为大家准备的几个精品专栏,喜欢的小伙伴可自行订阅,你的支持就是我不断更新的动力哟! MATLAB-30天带你从入门到精通 MATLAB深入理解高级教程(附源码) tableau可视化数据分析高级教程 python快速学习实战应用系列课程 基础篇 1首先,要知道我们用哪些库来画图? matplotlib python中最基本的作图库就是matplotlib,是一个最基础的Python可视化库,一般都是从matplotlib上手Python数据可视化,然后开始做纵向与横向

wenyusuran的专栏 1198

Python实战:5分钟搞定高斯核函数可视化(附完整代码)

本文通过Python实战,详细演示了如何利用NumPy和Matplotlib快速实现高斯核函数的可视化。文章从一维基函数绘制入手,逐步扩展到二维核函数的3D曲面与热度图展示,并直观解释了γ参数对模型的影响。通过可视化案例,帮助读者直观理解高斯核函数如何度量数据相似度,并成为处理机器学习中非线性问题的关键工具。

gpu4optimizer的博客 654

Matplotlib与Seaborn:高级数据可视化技术

本篇博客深入探讨了使用matplotlib和seaborn库在Python中实现高级数据可视化的技术。文章从饼图的高级技巧开始,逐步介绍如何为饼图添加阴影、百分比标签以及如何使用pandas数据框来直接绘制饼图。此外,还涵盖了如何绘制等高线图、极坐标图和三维图形,包括三维表面、散点图和条形图。文章提供了丰富的代码示例和图示,让读者能够快速掌握这些高级数据可视化的实现方法。

weixin_36288992的博客 540

Python数据可视化指南:从基础到高级

简介:数据可视化是将复杂数据转化为直观图形的过程,对数据分析至关重要。Python凭借其强大的库生态,如Matplotlib、Seaborn和Plotly,为数据可视化提供了便捷的手段。本主题深入探讨如何利用这些工具,在Jupyter Notebook中通过具体的案例学习如何创建各类图表。同时,还涉及数据预处理、美化图表和提升数据可视化效果的技巧。学习这些方法能够帮助我们有效地展示数据分析结果,从而让复杂信息变得易懂,无论对于初学者还是资深开发者,都是宝贵的资源。

weixin_32925455的博客 428

基础python超级常用的四种可视化函数库

交互性:Plotly 和 PyEcharts 更侧重于生成交互式图表,而Matplotlib和Altair则更注重静态图表的生成。易用性:Altair 和 PyEcharts 在API设计上更注重易用性,而Matplotlib虽然功能强大但API较复杂。输出形式:Matplotlib 和 Altair 更多地用于生成静态图表或图像文件,而Plotly 和 PyEcharts 则更适合生成可以直接嵌入Web页面的交互式图表。社区支持。

m0_64031432的博客 2430

手把手教你用周立功USBCANFD-200U和ZCANPRO软件,从驱动安装到UDS诊断一条龙搞定

本文详细介绍了如何使用周立功USBCANFD-200U硬件和ZCANPRO软件,从驱动安装到UDS诊断的全流程操作指南。涵盖硬件连接、软件配置、CAN通信测试及UDS诊断实战,帮助汽车电子爱好者和工程师快速掌握CAN总线通信技术,实现专业的车辆诊断功能。

weixin_30752699的博客 580

Python数据可视化:PathPatch路径补丁高级应用指南

在数据可视化领域,贝塞尔曲线是实现复杂图形绘制的数学基础,其通过控制点高效描述平滑曲线的特性,使其成为工程制图和艺术设计的核心技术。路径补丁(PathPatch)作为matplotlib中的高级图形元素,基于这一原理实现了任意封闭形状的创建,在GIS地理信息绘制、流体力学模拟等场景中展现出独特优势。通过顶点参数化与布尔运算等技巧,开发者可以构建齿轮轮廓等参数化图形,或实现复杂剪切效果。结合shapely等第三方库进行几何操作后转换,能显著提升大规模地理数据处理效率。对于需要高性能渲染的场景,采用PathCo

weixin_29758911的博客 290

Unity动态创建Avatar骨骼映射

Unity Avatar骨骼映射动态创建,适配Unity通用动画,无需经过第三方建模软件,可运行时创建

Nbin_Newby的博客 1万+

保姆级教程:用Verilog手把手实现一个MIPI CSI-2 D-PHY接收器(附PPI接口时序详解)

本文提供了一份详细的Verilog实现MIPI CSI-2 D-PHY接收器的教程,重点解析了PPI接口时序和deskew数据对齐技术。通过模块划分、时钟域处理、状态机设计和错误恢复机制等实战内容,帮助开发者掌握高速数据接收的核心技术,适用于嵌入式视觉系统开发。

weixin_30619101的博客 515

Python数据可视化教程

│ 1.1 python 数据可视化概述.mp4 │ 1.2 Matplotlib绘图介绍.mp4 │ 1.3 Matplotlib散点图绘制.mp4 │ 1.4 Matplotlib绘制折线图.mp4 │ 1.5 Matplotlib绘制柱状图.mp4 │ 1.6 Matplotlib绘制饼图.mp4 │ 2.1 Matplotlib例子的背景介绍.mp4 │ 2.2 Matpl...

qq_38472425的博客 489

Viobot使用教程总贴

使用教程总贴

weixin_66666206的博客 1411

Bokeh数据可视化:数据源与数据处理完全指南

在数据可视化项目中,数据源管理和数据处理是决定项目成功的关键因素。你是否曾经遇到过以下痛点: - 数据量庞大导致页面加载缓慢? - 实时数据更新需求难以满足? - 复杂的数据转换和过滤逻辑难以实现? - 多数据源协同工作困难? Bokeh作为Python生态中强大的交互式可视化库,提供了完整的数据源管理和数据处理解决方案。本文将深入解析Bokeh的数据源体系,帮助你掌握高效数据处理的核心技术。...

gitblog_00935的博客 351

get_ccopt系列命令介绍

get_ccopt_property:用来获取cts阶段,clock tree上所有的参数信息,可以通过get_ccopt_property –help *获取所有参数。get_ccopt_skew_group_delay:用来获取skew group的相关信息,可以通过筛选出特定条件下skew_group的参数,如skew_group下latency最长是多少;get_ccopt_clock_tree_source_groups:获取clock tree的source group名字;

芯冰乐 283

ADS1115 0-10V高精度ADC模块原理图设计,已量产

在水质监测、智能气象站、环境感知等领域,0-10V 电压输出的传感器占据了重要地位。这类传感器输出信号稳定、抗干扰能力强,但对数据采集模块的精度、线性度和易用性提出了严苛要求。本文将深度解析一款专为 0-10V 传感器设计的高精度 ADC 模块,从硬件架构、性能指标到工程化实践,全面呈现其设计思路与核心价值。

不脱发的程序猿 283

Pygfx入门指南:如何在Python中快速创建你的第一个3D可视化应用

Pygfx 是一个强大的 Python 3D 图形库,专为科学可视化和交互式应用设计。🚀 这个终极指南将带你快速上手 Pygfx,让你在几分钟内创建出令人惊艳的 3D 可视化效果!无论你是数据分析师、科研人员还是 Python 开发者,Pygfx 都能为你提供简单易用的 3D 图形渲染能力。 ## 📦 快速安装指南 安装 Pygfx 非常简单,只需要一条命令: ```bash pip i

gitblog_01163的博客 462

173、NPU的编译器开发:开源社区贡献指南

本文分享了在NPU编译器开源社区贡献的经验心得。作者通过实际案例(如卷积维度错误、NaN输出等)阐述了NPU编译器开发的特殊性:硬件迭代快、边界条件复杂、厂商代码不可全信。提出有价值的贡献应聚焦硬件适配测试、性能剖析工具和反模式文档三类内容。强调用实测数据沟通、主动承担维护责任、保持代码通用性等社区协作技巧,并建议通过RFC提前沟通、附硬件实测数据等方式提高PR通过率。最后指出,NPU编译器开发是与聪明人共同填坑的过程,鼓励开发者提交"有诚意的代码"而非完美代码。

m0_50546716的博客 38

Python Training:面向业务分析师与交易员的 Python 数值计算与数据可视化实战指南

本指南基于 JPMorgan python-training 开源仓库,系统解读一套专为**业务分析师(business analysts)与交易员(traders)**设计的 Python 入门培训课程:它以数值计算(numerical computing)与数据可视化(data visualization)为核心,用 Jupyter Notebook 为载体,从零基础语法一路推进到期权定价、信

gitblog_00427的博客 216

S7-200SMART通过表格指令实现模拟量信号滑动平均值滤波的具体方法

S7-200SMART通过表格指令实现模拟量信号滑动平均值滤波的具体方法

Robot_PLC_HMI_Automation 6729

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Python开发从入门到精通:数据可视化进阶与Matplotlib高级应用

本文介绍了Python数据可视化进阶技巧与Matplotlib高级应用。主要内容包括:数据可视化概述及其重要性,常见工具如Matplotlib、Seaborn等;图表样式自定义(标题、标签、网格、图例);多图表组合(子图、嵌套);交互式图表(Plotly、Bokeh);3D图表(折线图、散点图);最后通过实战案例展示数据可视化分析应用开发流程,涵盖数据读取、预处理、多种图表绘制及保存功能。文章提供了丰富的代码示例,帮助读者掌握高级数据可视化技能。

编程世界如山海,探索不止。 2万+

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Excel数据可视化:从基础到高级技巧

数据可视化是将数据转换为图形或图表的过程,以便更直观地理解数据模式、趋势和关系。Excel作为常用的电子表格软件,提供了丰富的数据可视化工具和功能。本文将介绍Excel数据可视化的基础到高级技巧,帮助读者更好地理解和应用数据可视化。

极客代码 6379

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Python开发从入门到精通:数据可视化高级应用

本文摘要: 《Python数据可视化高级应用》系统介绍了Python中主流可视化工具的高级功能。内容涵盖Matplotlib的子图布局、高级样式和动画制作;Seaborn库的热力图、直方图等高级图表;Plotly的交互式可视化;Bokeh的Web应用集成。通过销售数据分析实战案例,展示了如何综合运用这些工具进行趋势分析、分类分析和交互式可视化。文章提供了大量代码示例,帮助开发者掌握创建复杂图表、实现交互效果和处理大数据可视化的技能,提升数据展示效果和可读性。(150字)

编程世界如山海,探索不止。 7683

Matplotlib Mastery: 从基础到高级的数据可视化指南

Matplotlib允许你通过自定义颜色映射,为图表添加更多的信息。# 数据# 自定义颜色映射# 创建图表# 添加颜色条# 显示图表plt.show()通过颜色映射,我们可以在图表中加入更多维度的信息。Matplotlib作为Python中最流行的数据可视化库之一,提供了丰富的功能和灵活的定制选项。通过学习这些高级功能和技巧,你可以更好地运用Matplotlib,创造出更具表现力和复杂性的数据可视化作品。

一键难忘的博客 1542
上一篇: Python 数据科学高级应用指南
下一篇: Python 多线程和多进程高级应用指南
第一程序员
博客等级 码龄1年 1万+粉丝 1822原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值