当前位置:网站首页>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()
边栏推荐
- Pix2pix: image to image conversion using conditional countermeasure networks
- 04. Project blog log
- 2022半年总结
- Talking about the type and function of lens filter
- Summary of deep learning tuning tricks
- Game push image / table /cv/nlp, multi-threaded start
- 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
- Solution of QT TCP packet sticking
- [Tang Laoshi] C -- encapsulation: classes and objects
- Huawei od computer test question 2
猜你喜欢

Summary of deep learning tuning tricks

pix2pix:使用条件对抗网络的图像到图像转换

Vulhub vulnerability recurrence 67_ Supervisor
![[JVM] [Chapter 17] [garbage collector]](/img/f4/e6ff0e3edccf23399ec12b7913749a.jpg)
[JVM] [Chapter 17] [garbage collector]

27io stream, byte output stream, OutputStream writes data to file

Review of double pointer problems

Modbus协议通信异常

Vulhub vulnerability recurrence 69_ Tiki Wiki

Steady, 35K, byte business data analysis post

Pointer classic written test questions
随机推荐
趋势前沿 | 达摩院语音 AI 最新技术大全
毕业设计游戏商城
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
图数据库ONgDB Release v-1.0.3
巨杉数据库再次亮相金交会,共建数字经济新时代
Improve jpopup to realize dynamic control disable
[imgui] unity MenuItem shortcut key
How to get list length
JDBC calls the stored procedure with call and reports an error
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
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
[leetcode] 18. Sum of four numbers
Web Security (VI) the use of session and the difference between session and cookie
[machine learning notes] univariate linear regression principle, formula and code implementation
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
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
Detailed summary of SQL injection
Huawei od computer test question 2
jdbc使用call调用存储过程报错