当前位置:网站首页>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()
边栏推荐
- Jvxetable用slot植入j-popup
- Imperial cms7.5 imitation "D9 download station" software application download website source code
- [detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
- Promise summary
- jdbc使用call调用存储过程报错
- Vulhub vulnerability recurrence 73_ Webmin
- 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
- Algorithm -- climbing stairs (kotlin)
- Deep learning -yolov5 introduction to actual combat click data set training
猜你喜欢
Imperial cms7.5 imitation "D9 download station" software application download website source code
Yyds dry inventory SSH Remote Connection introduction
【torch】|torch. nn. utils. clip_ grad_ norm_
Nacos - TC Construction of High available seata (02)
Modbus协议通信异常
[effective Objective-C] - memory management
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
[force buckle]43 String multiplication
[JVM] [Chapter 17] [garbage collector]
随机推荐
Improve jpopup to realize dynamic control disable
指針經典筆試題
Installation de la Bibliothèque de processus PDK - csmc
Pix2pix: image to image conversion using conditional countermeasure networks
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
算法-- 爬楼梯(Kotlin)
2022半年总结
Game push: image / table /cv/nlp, multi-threaded start!
Huawei od computer test question 2
Deep learning -yolov5 introduction to actual combat click data set training
04. Project blog log
巨杉数据库再次亮相金交会,共建数字经济新时代
【LeetCode】18、四数之和
Easy to understand I2C protocol
趋势前沿 | 达摩院语音 AI 最新技术大全
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
[leetcode16] the sum of the nearest three numbers (double pointer)
First acquaintance with CDN
Select knowledge points of structure
js Array 列表 实战使用总结