当前位置:网站首页>Station B Liu Erden linear regression pytoch
Station B Liu Erden linear regression pytoch
2022-07-06 05:41:00 【Ning Ranye】
Series articles :
List of articles
Linear regression Pytorch
import matplotlib.pyplot as plt
import torch
x_data = torch.Tensor([[1.0, 2.0, 3.0]])
y_data = torch.Tensor([[2.0, 4.0, 6.0]])
class LinearModel(torch.nn.Module):
# Member method __init__ And forward Must be realized
def __init__(self):
super(LinearModel, self).__init__()
# 1,1, For weight weight And offset b Of size
self.linear = torch.nn.Linear(3, 1)
def forward(self, x):
y_pred = self.linear(x)
return y_pred
model = LinearModel()
# Loss function calculation one batch All in loss The average of
criterion = torch.nn.MSELoss(size_average=False)
optimizer = torch.optim.SGD(model.parameters(), lr=0.0005)
loss_list = []
epoch_list = []
for epoch in range(200):
y_pred = model(x_data)
loss = criterion(y_pred, y_data)
print(epoch, loss.item())
loss_list.append(loss.item())
epoch_list.append(epoch)
# The gradient will be backward Hourly accumulation , So in backward Must be reset before
optimizer.zero_grad()
loss.backward()
# update
optimizer.step()
plt.plot(epoch_list, loss_list)
plt.xlabel("epoch")
plt.ylabel("loss")
plt.show()
边栏推荐
- MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
- What preparations should be made for website server migration?
- First acquaintance with CDN
- Modbus protocol communication exception
- Unity gets the width and height of Sprite
- B站刘二大人-反向传播
- SQLite add index
- Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- Text classification still stays at Bert? The dual contrast learning framework is too strong
猜你喜欢
YYGH-11-定时统计
Garbage collector with serial, throughput priority and response time priority
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
ArcGIS应用基础4 专题图的制作
27io stream, byte output stream, OutputStream writes data to file
How can large websites choose better virtual machine service providers?
Notes, continuation, escape and other symbols
Pointer classic written test questions
【云原生】3.1 Kubernetes平台安装KubeSpher
What preparations should be made for website server migration?
随机推荐
Vulhub vulnerability recurrence 69_ Tiki Wiki
[experience] install Visio on win11
Using stopwatch to count code time
嵌入式面试题(四、常见算法)
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[cloud native] 3.1 kubernetes platform installation kubespher
Pointer classic written test questions
UCF (2022 summer team competition I)
Vulhub vulnerability recurrence 71_ Unomi
[detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
05. Security of blog project
注释、接续、转义等符号
Promise summary
[JVM] [Chapter 17] [garbage collector]
Huawei od computer test question 2
Vulhub vulnerability recurrence 73_ Webmin
[string] palindrome string of codeup
初识数据库