当前位置:网站首页>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()
边栏推荐
- Configuration file converted from Excel to Lua
- Huawei od computer test question 2
- pix2pix:使用条件对抗网络的图像到图像转换
- HAC cluster modifying administrator user password
- Solution of QT TCP packet sticking
- jdbc使用call调用存储过程报错
- 2022半年总结
- Promotion hung up! The leader said it wasn't my poor skills
- js Array 列表 实战使用总结
- CUDA11.1在线安装
猜你喜欢

04. Project blog log
![[Tang Laoshi] C -- encapsulation: classes and objects](/img/4e/30d2d4652ea2d4cd5fa7cbbb795863.jpg)
[Tang Laoshi] C -- encapsulation: classes and objects

RustDesk 搭建一个自己的远程桌面中继服务器

Summary of deep learning tuning tricks

PDK工藝庫安裝-CSMC

05. Security of blog project

Figure database ongdb release v-1.0.3

移植InfoNES到STM32

Check the useful photo lossless magnification software on Apple computer

初识CDN
随机推荐
February 12 relativelayout
指针经典笔试题
【华为机试真题详解】统计射击比赛成绩
Vulhub vulnerability recurrence 68_ ThinkPHP
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
C Advanced - data storage (Part 1)
SQLite queries the maximum value and returns the whole row of data
nacos-高可用seata之TC搭建(02)
26file filter anonymous inner class and lambda optimization
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
29io stream, byte output stream continue write line feed
[effective Objective-C] - memory management
SequoiaDB湖仓一体分布式数据库2022.6月刊
flutter 实现一个有加载动画的按钮(loadingButton)
Questions d'examen écrit classiques du pointeur
[imgui] unity MenuItem shortcut key
[untitled]
[Tang Laoshi] C -- encapsulation: classes and objects