当前位置:网站首页>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
- 改善Jpopup以实现动态控制disable
- How to use PHP string query function
- [JVM] [Chapter 17] [garbage collector]
- 29io stream, byte output stream continue write line feed
- Codeforces Round #804 (Div. 2) Editorial(A-B)
- 02. 开发博客项目之数据存储
- Anti shake and throttling are easy to understand
- B站刘二大人-反向传播
- Web Security (VI) the use of session and the difference between session and cookie
猜你喜欢

Safe mode on Windows

Vulhub vulnerability recurrence 72_ uWSGI

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist

清除浮动的方式

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

First acquaintance with CDN

Easy to understand IIC protocol explanation

29io stream, byte output stream continue write line feed

Vulhub vulnerability recurrence 68_ ThinkPHP

01. 开发博客项目之项目介绍
随机推荐
Sword finger offer II 039 Maximum rectangular area of histogram
指針經典筆試題
What is independent IP and how about independent IP host?
Game push image / table /cv/nlp, multi-threaded start
【torch】|torch.nn.utils.clip_grad_norm_
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
Problems encountered in installing mysql8 on MAC
Safe mode on Windows
C进阶-数据的存储(上)
算法-- 爬楼梯(Kotlin)
UCF (summer team competition II)
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
Improve jpopup to realize dynamic control disable
巨杉数据库再次亮相金交会,共建数字经济新时代
[SQL Server fast track] - authentication and establishment and management of user accounts
59. Spiral matrix
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
[Jiudu OJ 08] simple search x
What preparations should be made for website server migration?
Web Security (VI) the use of session and the difference between session and cookie