当前位置:网站首页>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()
边栏推荐
- A master in the field of software architecture -- Reading Notes of the beauty of Architecture
- [cloud native] 3.1 kubernetes platform installation kubespher
- MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
- 备忘一下jvxetable的各种数据集获取方法
- 剑指 Offer II 039. 直方图最大矩形面积
- 应用安全系列之三十七:日志注入
- Detailed summary of SQL injection
- 数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
- Graduation design game mall
- Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
猜你喜欢
[SQL Server fast track] - authentication and establishment and management of user accounts

C进阶-数据的存储(上)

Redis message queue

03. Login of development blog project

网站进行服务器迁移前应做好哪些准备?

Application Security Series 37: log injection

How to download GB files from Google cloud hard disk

Installation de la Bibliothèque de processus PDK - csmc

02. 开发博客项目之数据存储

What is independent IP and how about independent IP host?
随机推荐
Codeforces Round #804 (Div. 2) Editorial(A-B)
注释、接续、转义等符号
HAC cluster modifying administrator user password
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
Improve jpopup to realize dynamic control disable
Anti shake and throttling are easy to understand
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
进程和线程
[imgui] unity MenuItem shortcut key
【经验】win11上安装visio
Unity gets the width and height of Sprite
What is independent IP and how about independent IP host?
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
Embedded interview questions (I: process and thread)
Redis消息队列
【torch】|torch. nn. utils. clip_ grad_ norm_
Summary of deep learning tuning tricks
Deep learning -yolov5 introduction to actual combat click data set training
Self built DNS server, the client opens the web page slowly, the solution
初识数据库