当前位置:网站首页>Station B, Mr. Liu Er - multiple logistic regression, structure 7
Station B, Mr. Liu Er - multiple logistic regression, structure 7
2022-07-06 05:42:00 【Ning Ranye】
Series articles :
import torch
import matplotlib.pyplot as plt
import numpy as np
class LogisticRegressionModel(torch.nn.Module):
def __init__(self):
super(LogisticRegressionModel, self).__init__()
# Input dimensions 8 Output dimension 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)
# Reading data
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):
# Minimum batch processing is not used
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()
边栏推荐
- Installation de la Bibliothèque de processus PDK - csmc
- 数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
- Vulhub vulnerability recurrence 72_ uWSGI
- Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
- [email protected]树莓派
- SQLite add index
- 29io stream, byte output stream continue write line feed
- Vulhub vulnerability recurrence 67_ Supervisor
- Deep learning -yolov5 introduction to actual combat click data set training
- B站刘二大人-多元逻辑回归 Lecture 7
猜你喜欢
Vulhub vulnerability recurrence 69_ Tiki Wiki
Installation de la Bibliothèque de processus PDK - csmc
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
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
YYGH-11-定时统计
PDK工艺库安装-CSMC
Safe mode on Windows
Analysis of grammar elements in turtle Library
Vulhub vulnerability recurrence 67_ Supervisor
随机推荐
指针经典笔试题
js Array 列表 实战使用总结
Web Security (VI) the use of session and the difference between session and cookie
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
Vulhub vulnerability recurrence 69_ Tiki Wiki
JDBC calls the stored procedure with call and reports an error
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
Promotion hung up! The leader said it wasn't my poor skills
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
59. Spiral matrix
LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
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
算法-- 爬楼梯(Kotlin)
Redis message queue
PDK process library installation -csmc
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
Easy to understand IIC protocol explanation
Sword finger offer II 039 Maximum rectangular area of histogram
[cloud native] 3.1 kubernetes platform installation kubespher