当前位置:网站首页>B站刘二大人-多元逻辑回归 Lecture 7
B站刘二大人-多元逻辑回归 Lecture 7
2022-07-06 05:33:00 【宁然也】
系列文章:
import torch
import matplotlib.pyplot as plt
import numpy as np
class LogisticRegressionModel(torch.nn.Module):
def __init__(self):
super(LogisticRegressionModel, self).__init__()
# 输入维度8输出维度6
self.lay1 = torch.nn.Linear(8,6)
self.lay2 = torch.nn.Linear(6,4)
self.lay3 = torch.nn.Linear(4,1)
self.sigmod = torch.nn.Sigmoid()
def forward(self,x):
x = self.sigmod(self.lay1(x))
x = self.sigmod(self.lay2(x))
x = self.sigmod(self.lay3(x))
return x
model = LogisticRegressionModel()
criterion = torch.nn.BCELoss(reduction='mean')
optimizer = torch.optim.SGD(model.parameters(), lr=0.005)
# 读取数据
xy = np.loadtxt('./datasets/diabetes.csv.gz', delimiter=',', dtype=np.float32)
x_data = torch.from_numpy(xy[:,:-1])
y_data = torch.from_numpy(xy[:,[-1]])
epoch_list = []
loss_list = []
for epoch in range(1000):
# 没有用到最小批处理
y_pred = model(x_data)
loss = criterion(y_pred, y_data)
loss_list.append(loss.item())
epoch_list.append(epoch)
optimizer.zero_grad()
loss.backward()
optimizer.step()
plt.plot(epoch_list, loss_list)
plt.xlabel("epoch")
plt.ylabel("loss")
plt.show()
边栏推荐
- Vulhub vulnerability recurrence 67_ Supervisor
- 04. Project blog log
- Sword finger offer II 039 Maximum rectangular area of histogram
- 【torch】|torch. nn. utils. clip_ grad_ norm_
- Promise summary
- LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
- Game push image / table /cv/nlp, multi-threaded start
- JDBC calls the stored procedure with call and reports an error
- pix2pix:使用条件对抗网络的图像到图像转换
- Questions d'examen écrit classiques du pointeur
猜你喜欢

05. 博客项目之安全

PDK工艺库安装-CSMC

C进阶-数据的存储(上)

Check the useful photo lossless magnification software on Apple computer

Vulhub vulnerability recurrence 67_ Supervisor

Implementing fuzzy query with dataframe

Vulhub vulnerability recurrence 71_ Unomi

剑指 Offer II 039. 直方图最大矩形面积

毕业设计游戏商城

Vulhub vulnerability recurrence 69_ Tiki Wiki
随机推荐
【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
04. 项目博客之日志
[mask requirements of OSPF and Isis in multi access network]
04. Project blog log
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
JS array list actual use summary
C进阶-数据的存储(上)
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
How to get list length
Fluent implements a loadingbutton with loading animation
Easy to understand I2C protocol
Pix2pix: image to image conversion using conditional countermeasure networks
Promotion hung up! The leader said it wasn't my poor skills
Hyperledger Fabric2. Some basic concepts of X (1)
HAC cluster modifying administrator user password
Sword finger offer II 039 Maximum rectangular area of histogram
Detailed summary of SQL injection
Nacos TC setup of highly available Seata (02)
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
Vulhub vulnerability recurrence 72_ uWSGI