当前位置:网站首页>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()
边栏推荐
- 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
- Jvxetable用slot植入j-popup
- Yyds dry inventory SSH Remote Connection introduction
- Vulhub vulnerability recurrence 72_ uWSGI
- Select knowledge points of structure
- 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
- jdbc使用call调用存储过程报错
- 【华为机试真题详解】检查是否存在满足条件的数字组合
- Easy to understand IIC protocol explanation
- Notes, continuation, escape and other symbols
猜你喜欢
PDK process library installation -csmc
Review of double pointer problems
Vulhub vulnerability recurrence 68_ ThinkPHP
pix2pix:使用条件对抗网络的图像到图像转换
Text classification still stays at Bert? The dual contrast learning framework is too strong
Please wait while Jenkins is getting ready to work
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
03. Login of development blog project
Pointer classic written test questions
Huawei equipment is configured with OSPF and BFD linkage
随机推荐
04. Project blog log
February 12 relativelayout
26file filter anonymous inner class and lambda optimization
Please wait while Jenkins is getting ready to work
Summary of redis basic knowledge points
【LeetCode】18、四数之和
Notes, continuation, escape and other symbols
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
趋势前沿 | 达摩院语音 AI 最新技术大全
Questions d'examen écrit classiques du pointeur
Safe mode on Windows
HAC集群修改管理员用户密码
Codeforces Round #804 (Div. 2) Editorial(A-B)
02. Develop data storage of blog project
Pickle and savez_ Compressed compressed volume comparison
Anti shake and throttling are easy to understand
Configuration file converted from Excel to Lua
初识CDN
[effective Objective-C] - memory management
Codeforces Round #804 (Div. 2) Editorial(A-B)