设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 运营中心 > 建站资源 > 经验 > 正文

PyTorch的4分钟教程,手把手教你完成线性回归(3)

发布时间:2019-07-29 00:20 所属栏目:19 来源:大数据文摘
导读:运行结果: MSELoss参考网站:https://pytorch.org/docs/stable/_modules/torch/nn/modules/loss.html SGD参考网站:https://pytorch.org/docs/stable/_modules/torch/optim/sgd.html 第四步: 现在训练已经完成,

运行结果:

PyTorch的4分钟教程,手把手教你完成线性回归

  • MSELoss参考网站:https://pytorch.org/docs/stable/_modules/torch/nn/modules/loss.html
  • SGD参考网站:https://pytorch.org/docs/stable/_modules/torch/optim/sgd.html

第四步:

现在训练已经完成,让我们直观地检查我们的模型:

  1. #Step 4:Display model and confirm 
  2. import matplotlib.pyplot as plt 
  3. plt.figure(figsize=(4,4)) 
  4. plt.title("Model and Dataset") 
  5. plt.xlabel("X");plt.ylabel("Y") 
  6. plt.grid() 
  7. plt.plot(x,y,"ro",label="DataSet",marker="x",markersize=4) 
  8. plt.plot(x,model.model.weight.item()*x+model.model.bias.item(),label="Regression Model") 
  9. plt.legend();plt.show() 

运行结果:

PyTorch的4分钟教程,手把手教你完成线性回归

现在你已经完成了PyTorch的第一个线性回归例子的编程了,对于后续希望百尺竿头,更进一步的读者来说,可以参考PyTorch的官方文档链接,完成大部分的编码应用。

相关链接:

https://medium.com/towards-artificial-intelligence/pytorch-in-2-minutes-9e18875990fd

【本文是51CTO专栏机构大数据文摘的原创译文,微信公众号“大数据文摘( id: BigDataDigest)”】

     大数据文摘二维码

戳这里,看该作者更多好文

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读