当前位置: 首页 > news >正文

北京电子商务app网站建设大兴app充值网站开发

北京电子商务app网站建设大兴,app充值网站开发,石家庄免费建站模板,中文网站建设公司借助 PyTorch 实现深度神经网络 - 线性回归 - 第 2 周 | Coursera 线性回归预测 用PyTorch实现线性回归模块 创建自定义模块#xff08;内含一个线性回归#xff09; 训练线性回归模型 对于线性回归#xff0c;特定类型的噪声是高斯噪声 平均损失均方误差函数#xff1a…借助 PyTorch 实现深度神经网络 - 线性回归 - 第 2 周 | Coursera 线性回归预测 用PyTorch实现线性回归模块 创建自定义模块内含一个线性回归 训练线性回归模型 对于线性回归特定类型的噪声是高斯噪声 平均损失均方误差函数 loss求解导数0 梯度下降 表示学习率 学习率过高可能错过参数的最佳值 学习率过低需要大量的迭代才能获得最小值 Batch Gradient Descent使用整个训练集来更新模型的参数  用Pytorch实现线性回归--梯度 每个epoch就是一个iteration 画图版 import torch wtorch.tensor(-10.0,requires_gradTrue) Xtorch.arange(-3,3,0.1).view(-1,1) f-3*X # The class for plottingclass plot_diagram():# Constructordef __init__(self, X, Y, w, stop, go False):start w.dataself.error []self.parameter []print(type(X.numpy()))self.X X.numpy()self.Y Y.numpy()self.parameter_values torch.arange(start, stop)self.Loss_function [criterion(forward(X), Y) for w.data in self.parameter_values] w.data start# Executordef __call__(self, Yhat, w, error, n):self.error.append(error)self.parameter.append(w.data)plt.subplot(212)plt.plot(self.X, Yhat.detach().numpy())plt.plot(self.X, self.Y,ro)plt.xlabel(A)plt.ylim(-20, 20)plt.subplot(211)plt.title(Data Space (top) Estimated Line (bottom) Iteration str(n))# Convert lists to PyTorch tensorsparameter_values_tensor torch.tensor(self.parameter_values)loss_function_tensor torch.tensor(self.Loss_function)# Plot using the tensorsplt.plot(parameter_values_tensor.numpy(), loss_function_tensor.numpy())plt.plot(self.parameter, self.error, ro)plt.xlabel(B)plt.figure()# Destructordef __del__(self):plt.close(all) gradient_plot plot_diagram(X, Y, w, stop 5) # Define a function for train the modeldef train_model(iter):LOSS[]for epoch in range (iter):# make the prediction as we learned in the last labYhat forward(X)# calculate the iterationloss criterion(Yhat,Y)# plot the diagram for us to have a better ideagradient_plot(Yhat, w, loss.item(), epoch)# store the loss into listLOSS.append(loss.item())# backward pass: compute gradient of the loss with respect to all the learnable parametersloss.backward()# updata parametersw.data w.data - lr * w.grad.data# zero the gradients before running the backward passw.grad.data.zero_() train_model(4) 用Pytorch实现线性回归--训练 与上文类似只是多加了个b 梯度 画函数图 # The class for plot the diagramclass plot_error_surfaces(object):# Constructordef __init__(self, w_range, b_range, X, Y, n_samples 30, go True):W np.linspace(-w_range, w_range, n_samples)B np.linspace(-b_range, b_range, n_samples)w, b np.meshgrid(W, B) Z np.zeros((30,30))count1 0self.y Y.numpy()self.x X.numpy()for w1, b1 in zip(w, b):count2 0for w2, b2 in zip(w1, b1):Z[count1, count2] np.mean((self.y - w2 * self.x b2) ** 2)count2 1count1 1self.Z Zself.w wself.b bself.W []self.B []self.LOSS []self.n 0if go True:plt.figure()plt.figure(figsize (7.5, 5))plt.axes(projection3d).plot_surface(self.w, self.b, self.Z, rstride 1, cstride 1,cmap viridis, edgecolor none)plt.title(Cost/Total Loss Surface)plt.xlabel(w)plt.ylabel(b)plt.show()plt.figure()plt.title(Cost/Total Loss Surface Contour)plt.xlabel(w)plt.ylabel(b)plt.contour(self.w, self.b, self.Z)plt.show()# Setterdef set_para_loss(self, W, B, loss):self.n self.n 1self.W.append(W)self.B.append(B)self.LOSS.append(loss)# Plot diagramdef final_plot(self): ax plt.axes(projection 3d)ax.plot_wireframe(self.w, self.b, self.Z)ax.scatter(self.W,self.B, self.LOSS, c r, marker x, s 200, alpha 1)plt.figure()plt.contour(self.w,self.b, self.Z)plt.scatter(self.W, self.B, c r, marker x)plt.xlabel(w)plt.ylabel(b)plt.show()# Plot diagramdef plot_ps(self):plt.subplot(121)plt.ylimplt.plot(self.x, self.y, ro, labeltraining points)plt.plot(self.x, self.W[-1] * self.x self.B[-1], label estimated line)plt.xlabel(x)plt.ylabel(y)plt.ylim((-10, 15))plt.title(Data Space Iteration: str(self.n))plt.subplot(122)plt.contour(self.w, self.b, self.Z)plt.scatter(self.W, self.B, c r, marker x)plt.title(Total Loss Surface Contour Iteration str(self.n))plt.xlabel(w)plt.ylabel(b)plt.show()
http://www.w-s-a.com/news/386221/

相关文章:

  • 深圳建设局网站深业中城绿化项目营销型网站开发流程包括
  • 找销售的网站九江市建设项目服务中心
  • 东原ARC网站建设公司合肥seo网站推广外包
  • 那个网站是做房产中介的网站制作软件小学
  • 做网页怎么建站点视频解析网站
  • 做网站的系统设计网站设计论文前言
  • 做外贸网站多久更新汕头市建设局网站首页
  • 如何建设专业化的网站手机管理网站模板
  • 花生壳做网站如何用腾讯云做网站
  • 搭建集团网站开发app需要哪些软件
  • 网站建设 中企动力福州阀门wordpress 多说评论
  • php网站集成支付宝接口下载免费网络软件
  • 卡盟网站是怎么建设的用花生壳做网站速度可以吗
  • 杭州物联网前十名公司优秀seo平台
  • 网新中英企业网站管理系统wordpress 登录 缓存
  • wordpress模板建站教程wordpress添加广告位手机自适应
  • h5游戏平台入口优化是什么梗
  • 建设银行对公网站打不开网络推广活动方案主题和思路
  • 茶叶网站开发目的和意义网页设计需要考什么证
  • 高端企业网站建设公司怎么做实用性建设网站都需要哪些
  • 网站备案必须要幕布吗易企秀网站怎么做轮播图
  • 南昌网站排名优化四线城市网站建设方向及营利点
  • 做网站需要钱吗unity 做网站
  • 呼伦贝尔市规划建设局网站wordpress怎么考别人的
  • 免备案自助建站网站成都神速建站
  • 怎样编写app软件快速刷排名seo软件
  • 江苏做家纺的公司网站宣传型企业网站
  • 网站网上商城建设外国一些做环保袋的网站
  • 做空气开关那个网站推广比较好建站技术有哪些
  • 做网站前需要做什么准备wordpress图片云储存