当前位置:网站首页>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()
边栏推荐
- [JVM] [Chapter 17] [garbage collector]
- 29io stream, byte output stream continue write line feed
- ArcGIS application foundation 4 thematic map making
- 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
- 改善Jpopup以实现动态控制disable
- How can large websites choose better virtual machine service providers?
- JDBC calls the stored procedure with call and reports an error
- Yygh-11-timing statistics
- What impact will frequent job hopping have on your career?
- 嵌入式面试题(一:进程与线程)
猜你喜欢

PDK process library installation -csmc

Sequoiadb Lake warehouse integrated distributed database, June 2022 issue

ArcGIS应用基础4 专题图的制作

SequoiaDB湖仓一体分布式数据库2022.6月刊

Graduation design game mall

JS array list actual use summary

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)

毕业设计游戏商城
随机推荐
PDK process library installation -csmc
Solution of QT TCP packet sticking
Rustdesk builds its own remote desktop relay server
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
Vulhub vulnerability recurrence 68_ ThinkPHP
YYGH-11-定时统计
How to get list length
C进阶-数据的存储(上)
应用安全系列之三十七:日志注入
04. Project blog log
【云原生】3.1 Kubernetes平台安装KubeSpher
Vulhub vulnerability recurrence 67_ Supervisor
02. 开发博客项目之数据存储
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
Game push image / table /cv/nlp, multi-threaded start
什么是独立IP,独立IP主机怎么样?
[email protected]树莓派
毕业设计游戏商城
清除浮动的方式