Road 2 AI-可视化视图

对于机器学习的整个建模过程,有:
在这里插入图片描述
其中在数据预处理和结果后处理阶段需要我们对数据和结果做可视化处理,而对于不同的数据,需要不同的可视化方法:

  1. 比较:展示事物的排列顺序,比如条形图
  2. 联系:查看两个变量之间的关系,比如气泡图
  3. 构成:每个部分所占整体的百分比,比如饼图
  4. 分布:关心各数值范围包含哪些项目,比如柱状图
    在这里插入图片描述
    在Python有两种常用的可视化工具:
  • Matplotlib
import matplotlib.pyplot as plt
  • seaborn
import seaborn as sns

对于不同的数据呈现,我们需要使用不同的试图:

  1. 散点图
N = 500
x = np.random.randn(N)
y = np.random.randn(N)
#用matplotlib画散点图
plt.scatter(x,y,marker = 'x')
plt.show()
#用seaborn画散点图
df = pd.DataFrame({'x':x,'y':y})
sns.jointplot(x = 'x',y = 'y',data = df,kind = 'scatter')
plt.show()

在这里插入图片描述
在这里插入图片描述

2.折线图

x = [1900,1901,1902,1903,1904,1905,1906,1907,1908,1909,1910]
y = [256,323,136,220,305,350,419,450,560,720,830]
#用matplotlib画折线图
plt.plot(x,y)
plt.show()
#用seaborn画折线图
df = pd.DataFrame({'x':x,'y':y})
sns.lineplot(x = 'x',y = 'y',data = df)
plt.show()

在这里插入图片描述
3.条形图

x = ['c1','c2','c3','c4']
y = [15,18,5,26]
#用matplotlib画条形图
plt.bar(x,y)
plt.show()
#用seaborn画条形图
sns.barplot(x,y)
plt.show()

在这里插入图片描述
在这里插入图片描述
4.箱线图

#生成0-1之间的20*4维度的数据
data = np.random.normal(size = (10,4))
labels = ['A','B','C','D']
#用matplotlib画箱线图
plt.boxplot(data,labels = labels)
plt.show()
#用seaborn画箱线图
df = pd.DataFrame(data,columns = labels)
sns.boxplot(data = df)
plt.show()

在这里插入图片描述
在这里插入图片描述
5.饼图

nums = [25,33,37]
labels = ['ADC','APC','Tk']
#用matplotlib画饼图
plt.pie(x = nunms,labels = labels)
plt.show()

在这里插入图片描述
6.数据热力图

np.random.seed(2021)
data = np.random.rand(3,3)
heatmap = sns.heatmap(data)
plt.show()

在这里插入图片描述
7.二元分布变量

#导出数据,不同年份对应的乘机人员数量
flights = sns.load_dataset('flights')
#用seaborn画二元变量(散点图、核密度图、Hexbin图)
sns.jointplot(x = 'year',y = 'passengers',data = 'flights',kind = 'scatter')
sns.jointplot(x = 'year',y = 'passengers',data = 'flights',kind = 'kde')
sns.jointplot(x = 'year',y = 'passengers',data = 'flights',kind = 'hex')
plt.show()
#查看passengers的分布情况(一元分布)
sns.kdeplot(flights['passengers'],color = 'red',shade = True)
plt.show()

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
8.subplot的使用

  • 在matplotlib下,一个figure对象可以绘制多个子图
subplot(numrows,numcols,plotnum)

图表的整个区域被划分为numrows行,numcols列,然后按照从左到右,从上到下的顺序一次进行绘制,左上区域的子图编号从1开始,plotnum表示绘制的图指定在哪个区域。

def f(t):
	return np.exp(-t)*np.cos(2*np.pi*t)
t1 = np.arange(0,5,0.1)
t2 = np.arange(0,5,0.02)
plt.figure()
plt.subplot(2,2,1)
plt.plot(t1,f(t1),'r--')
plt.subplot(2,2,2)
plt.plot(t2,np.cos(2*np.pi*t2),'r--')
plt.subplot(2,1,2)
plt.plot([1,2,3,4],[1,4,9,16])
plt.show()

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.Wiggles

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值