def show_scatter_surface(X,Y,forward_propgation): if type(forward_propgation) == Sequential: show_scatter_surface_with_model(X,Y,forward_propgation) return x = X[:,0] z = X[:,1] y = Y fig = plt.figure() ax = Axes3D(fig) ax.scatter(x, z, y) x = np.arange(np.min(x),np.max(x),0.1) z = np.arange(np.min(z),np.max(z),0.1) x,z = np.meshgrid(x,z) X = np.column_stack((x[0],z[0])) for j in range(z.shape[0]): if j == 0: continue X = np.vstack((X,np.column_stack((x[0],z[j])))) r = forward_propgation(X) y = r[0] if type(r) == np.ndarray: y = r y = np.array([y]) y = y.reshape(x.shape[0],z.shape[1]) ax.plot_surface(x, z, y, cmap='rainbow') plt.show()
理解问题def show_scatter_surface(X,Y,forward_propgation): if type(forward_propgation) == Sequential: show_scatter_surface_with_model(X,Y,forward_propgation) return x = X[:,0] z = X[:,1] y = Y fig = plt.figure() ax = Axes3D(fig) ax.scatter(x, z, y) x = np.arange(np.min(x),np.max(x),0.1) z = np.arange(np.min(z),np.max(z),0.1) x,z = np.meshgrid(x,z) X = np.column_stack((x[0],z[0])) for j in range(z.shape[0]): if j == 0: continue X = np.vstack((X,np.column_stack((x[0],z[j])))) r = forward_propgation(X) y = r[0] if type(r) == np.ndarray: y = r y = np.array([y]) y = y.reshape(x.shape[0],z.shape[1]) ax.plot_surface(x, z, y, cmap='rainbow') plt.show()
已完成理解「def show_scatter_surface(X,Y,forward_propgation): if type(forward_propgation) == Sequential: show_scatter_surface_with_model(X,Y,forward_propgation) return x = X[:,0] z = X[:,1] y = Y fig = plt.figure() ax = Axes3D(fig) ax.scatter(x, z, y) x = np.arange(np.min(x),np.max(x),0.1) z = np.arange(np.min(z),np.max(z),0.1) x,z = np.meshgrid(x,z) X = np.column_stack((x[0],z[0])) for j in range(z.shape[0]): if j == 0: continue X = np.vstack((X,np.column_stack((x[0],z[j])))) r = forward_propgation(X) y = r[0] if type(r) == np.ndarray: y = r y = np.array([y]) y = y.reshape(x.shape[0],z.shape[1]) ax.plot_surface(x, z, y, cmap='rainbow') plt.show()」
展开阅读网页
- 绘制3D散点图和曲面图的Python函数。
函数功能概述
- 定义函数:
show_scatter_surface
用于绘制3D散点图和曲面图。 - 参数检查:检查
forward_propgation
是否为Sequential
类型,如果是,则调用另一个函数处理。 - 数据准备:从输入参数
X
和Y
中提取x, z, y数据,并创建散点图。 - 生成网格:创建x和z的值的网格,用于曲面图的绘制。
- 模型预测:使用
forward_propgation
对生成的网格数据进行预测,获取曲面数据。 - 绘制曲面:使用
plot_surface
绘制3D曲面图,并展示结果。