当前位置:网站首页>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()
边栏推荐
- 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
- Questions d'examen écrit classiques du pointeur
- JDBC calls the stored procedure with call and reports an error
- [machine learning notes] univariate linear regression principle, formula and code implementation
- Deep learning -yolov5 introduction to actual combat click data set training
- Self built DNS server, the client opens the web page slowly, the solution
- Solution of QT TCP packet sticking
- 2022半年总结
- 【华为机试真题详解】检查是否存在满足条件的数字组合
猜你喜欢

26file filter anonymous inner class and lambda optimization

进程和线程

Redis message queue

05. 博客项目之安全

03. 开发博客项目之登录

清除浮动的方式

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

【云原生】3.1 Kubernetes平台安装KubeSpher

PDK工藝庫安裝-CSMC

Application Security Series 37: log injection
随机推荐
JS array list actual use summary
PDK工艺库安装-CSMC
jdbc使用call调用存储过程报错
Download, install and use NVM of node, and related use of node and NRM
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
Text classification still stays at Bert? The dual contrast learning framework is too strong
Detailed summary of SQL injection
大型网站如何选择比较好的云主机服务商?
[detailed explanation of Huawei machine test] statistics of shooting competition results
Pointer classic written test questions
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
移植InfoNES到STM32
[SQL Server fast track] - authentication and establishment and management of user accounts
ArcGIS application foundation 4 thematic map making
Jushan database appears again in the gold fair to jointly build a new era of digital economy
SQLite add index
Installation de la Bibliothèque de processus PDK - csmc
Yygh-11-timing statistics
Go language -- language constants