np.meshgrid & plt.contourf

  • 吴恩达机器学习作业
    • np.meshgrid && plt.contourf
    • plt.contourf

吴恩达机器学习作业

https://blog.csdn.net/u013733326/article/details/79847918

np.meshgrid && plt.contourf

np.meshgrid 生成网格点坐标
二维坐标系中,X轴可以取三个值1,2,3, Y轴可以取三个值4,5,
(1,4)(2,4)(3,4)
(1,5)(2,5)(3,5)
返回list,有两个元素,第一个元素是X轴的取值,第二个元素是Y轴的取值

返回结果: [array([ [1,2,3] [1,2,3] ]), array([ [4,4,4] [5,5,5] ])]
     xx, yy= np.meshgrid(a,b)"""xx [1 2 3 1 2 3]yy [4 4 4 5 5 5]z [[1 4][2 4][3 4][1 5][2 5][3 5]]"""
def plot_decision_boundary(model,x,y):x_min, x_max = x[0,:].min() - 1, x[0,:].max() +1  # 第一个数据中最大最小值y_min, y_max = x[1,:].min() - 1, x[1,:].max() +1  # 第二个数据中最大最小值h = 0.01xx,yy = np.meshgrid(np.arange(x_min,x_max,h),np.arange(y_min,y_max,h))z = model(np.c_[xx.ravel(),yy.raverl()])z = z.reshape(xx.shape)plt.contourf(xx, yy, z,cmap=plt.cm.Spectral)plt.ylabel('x2')plt.xlabel('x1')plt.scatter(x[0, :], x[1, :], c=np.squeeze(y), cmap=plt.cm.Spectral)plt.show()

plt.contourf

https://blog.csdn.net/lens___/article/details/83960810
绘制等高线的,contour和contourf都是画三维等高线图的,不同点在于contour() 是绘制轮廓线,
contourf()会填充轮廓。除非另有说明,否则两个版本的函数是相同的。
参数: X,Y:类似数组,可选为Z中的坐标值
当 X,Y,Z 都是 2 维数组时,它们的形状必须相同。如果都是 1 维数组时,
len(X)是 Z 的列数,而 len(Y) 是 Z 中的行数。(例如,经由创建numpy.meshgrid())
Z:类似矩阵绘制轮廓的高度值
levels:int或类似数组,可选确定轮廓线/区域的数量和位置
其他参数: aalpha:float ,可选
alpha混合值,介于0(透明)和1(不透明)之间。
cmap:str或colormap ,可选
Colormap用于将数据值(浮点数)从间隔转换为相应Colormap表示的RGBA颜 色。用于将数据缩放到间隔中看 。

        x = np.array([1,2,3])y = np.array([4,5])xx,yy = np.meshgrid(x,y)z =  xx**3 + yy**3# z.reshape(xx.shape)print('xx',xx.ravel())print('yy',yy.ravel())print('z',z)plt.contourf(xx, yy, z)plt.show()

绘制预测和实际不同的图像

def print_mislabeled_images(classes, X, Y, p):"""绘制预测和实际不同的图像:param classes: 种类:param X: 数据集:param Y: 标签:param p: 预测:return:"""a = p + Y  # 预测 和 实际 概率 累加  ,其中预测错的和为1print("a.shape", a.shape)mislabeled_indices = np.asarray(np.where(a == 1))print("mislabeled_indices", mislabeled_indices)# mislabeled_indices# [[ 0  0  0  0  0  0  0  0  0  0  0]# [ 5  6 13 19 28 29 34 44 45 46 48]]# 原矩阵a是个一维矩阵(行数只有一行)# 第一行的[ 0 0 0 0 0 0 0 0 0 0 0]代表的是对应点的行下标# 第二行的[ 5 6 13 19 28 29 34 44 45 46 48]代表的是列下标print("mislabeled_indices.shape", mislabeled_indices.shape)plt.rcParams['figure.figsize'] = (40.0, 40.0)  # set default size of plotsnum_images = len(mislabeled_indices[0])# print("mislabeled_indices.shape[0]")for i in range(num_images):index = mislabeled_indices[1][i]print('index', index)plt.subplot(2, num_images, i + 1)plt.imshow(X[:, index].reshape(64, 64, 3), interpolation='nearest')plt.axis('off')plt.title('Prediction:' + classes[int(p[0, index])].decode('utf-8') + '\n Class' + classes[Y[0, index]].decode('utf-8'))plt.show()

np.meshgrid plt.contourf相关推荐

  1. np.meshgrid, ravel(), np.c_, plt.contourf()函数的用法,以及决策边界的画法。

    前言: 楼主最近在学机器学习时碰到的一些函数,用来画决策边界.记录现在的想法. 1: np.meshgrid的用法: X,Y = np.meshgrid(x,y)是将x中的每个点与y中的每个点连起来成 ...

  2. meshgrid()+plt.contourf()用法

    这次在matplotlib画图时遇到了这两个函数,感觉有必要看看怎么用,就自己尝试找找文档稍微记一下关键使用 np.meshgrid() numpy.meshgrid(*xi, copy=True, ...

  3. 【解决报错原因分析】画图plt.contourf(X,Y,Z)报错TypeError: unhashable type: ‘numpy.ndarray‘(含详细示例讲解)

    今天简化画图代码的时候发现了很奇怪的报错现象,经过一系列尝试找到了根源,希望帮助后来人,主要问题出现在如下语句中(为了体现问题.方便比对,特意在这改变了x为xx,如果你不想看这冗长的示例,可以直接按照 ...

  4. python matplotlib二维平面等高线的绘制, plt.contour 与 plt.contourf, plt.clabel和plt.colorbar, plt.xticks([])

    引用文章1 https://blog.csdn.net/lanchunhui/article/details/70495353 引用文章2 https://blog.csdn.net/qq_33506 ...

  5. python matplotlib绘制等高线,plt.contour(),ax3.contour()和plt.contourf(),ax3.contour(), 同名函数

    引用文章 https://blog.csdn.net/lanchunhui/article/details/70495353 首先这是由不同对象调用的函数,ax3指3D Figure对象即<cl ...

  6. matplotlib 等高线的绘制 —— plt.contour 与 plt.contourf

    contour:轮廓,等高线. 为等高线上注明等高线的含义: cs = plt.contour(x, y, z) plt.clabel(cs, inline=1, fontsize=10) plt.c ...

  7. 决策边界绘制函数plot_decision_boundary()和plt.contourf函数详解

    在做吴恩达老师的深度学习课程作业时,发现决策边界函数不好理解plot_decision_boundary(model , X , y).将此函数理解记录下: 作业地址:https://blog.csd ...

  8. np.meshgrid()

    目录 1.meshgrid函数介绍 2.meshgrid函数官方说明 1.meshgrid函数介绍 参数: *xi,也就是x1,x2,-,xn :表示网格坐标的一维数组. copy:默认为True,如 ...

  9. python contourf色阶_matplotlib:plt.contourf(画等高线)

    import numpy as np import matplotlib matplotlib.use("TkAgg") import matplotlib.pyplot as p ...

最新文章

  1. OpenUI5 - SAP开源中的移动大战略
  2. Java反射:框架设计的灵魂
  3. python动态生成html报表_Python应用phy模块生成html表格
  4. 【类】变量复用,函数复用
  5. 程序路径查找 找到指定程序所在的目录
  6. day63-webservice 08.在web项目中配置带有接口的webservice服务
  7. AtomicBoolean介绍与使用
  8. qt实现对话框选择文件路径并保存(简易版)
  9. 家庭网络,怎么给每个房间装一个无线路由器?
  10. Python闭包装饰器笔记
  11. 海康GB28181协议服务器怎么配置,GB/T28181国标流媒体服务器在海康平台上进行级联配置步骤总结...
  12. vue项目实现富文本编辑器(实践用过)
  13. gulp-sass 使用报错Error:gulp-sass no longer has a default Sass compiler; please set one yourself
  14. EXCEL【数据处理之数据清洗——缺失数据处理】
  15. 看雪CTF-MISC类型题之巍然不动
  16. 课上认真听讲,课后马上忘记怎么办?
  17. 电脑怎么写入便签并同步到手机版便签上?
  18. 三合一剪弦器怎么用_吉他换弦时多余的弦用什么工具剪掉?
  19. 兰伯特(Lambert)方程的求解算法1
  20. mongodb数据库优缺点分析(扫盲)

热门文章

  1. 使用百度地图时如何隐藏百度地图logo
  2. 昆明:推进智慧交通 缓解交通拥堵
  3. 电脑wifi可以登录qq,但是不可以上网,怎么办?
  4. 相机成像---世界坐标系、相机坐标系、图像坐标系和像素坐标系之间的转换关系
  5. 2018中国科幻产业报告
  6. 消防人员实操训练模拟培训虚拟仿真实训系统软件
  7. java 手电筒_Android实现简单手电筒功能
  8. 参考 | Windows安装cython-bbox
  9. fit函数 model_tensorflow中model.fit()用法
  10. java fuoco2_音乐术语《piu mosso con fuoco》是什么意思