Python3入门机器学习 - 数据可视化基础matplotlib

先上张图
img_e020b49531867bce3936cc4556a86c19.png

折线图

plt.plot(x,siny,label="sin(x)")
plt.plot(x,cosy,color="red",linestyle="--",label="cos(x)")
plt.axis([-2,12,-2,2]) //设置横纵坐标范围,也可以使用 plt.xlim(-2,12) plt.ylim(-2,2)来设置
plt.xlabel("x axis")
plt.ylabel("y value")
plt.legend()
plt.title("Hello Machine Learning!")
plt.show()
img_f6138cafead5f65df1120d3909889376.png

散点图

散点图一般用于绘制二维特征,即横纵两个轴都是特征

x = np.random.normal(0,1,10000)
y = np.random.normal(0,1,10000)
plt.scatter(x,y,alpha=0.3)
plt.show()
img_f3999a96fb778c2470fc3122f6f89740.png

鸢尾花数据集散点特征

import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets

iris = datasets.load_iris()
iris.keys()
data = iris['data']
target = iris['target']

plt.scatter(data[target==0,0],data[target==0,1],color="red")
plt.scatter(data[target==1,0],data[target==1,1],color="green",marker='+')
plt.scatter(data[target==2,0],data[target==2,1],color="blue",marker='x')
plt.show()
img_abc5566efb3b75c684d2f62d7fa4eeb5.png
以鸢尾花数据集前两列特征绘制特征图
plt.scatter(data[target==0,2],data[target==0,3],color="red")
plt.scatter(data[target==1,2],data[target==1,3],color="green",marker='+')
plt.scatter(data[target==2,2],data[target==2,3],color="blue",marker='x')
plt.show()
img_95153bc16abeb63c32d0a61a840b1fdf.png
以鸢尾花数据集后两列特征绘制特征图
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值