当前位置:网站首页>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()
边栏推荐
- Algorithm -- climbing stairs (kotlin)
- 05. 博客项目之安全
- 无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
- Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
- 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
- Closure, decorator
- 59. Spiral matrix
- 26file filter anonymous inner class and lambda optimization
- 2022半年总结
- [experience] install Visio on win11
猜你喜欢

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)

Text classification still stays at Bert? The dual contrast learning framework is too strong

Game push image / table /cv/nlp, multi-threaded start

类和对象(一)this指针详解

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

Vulhub vulnerability recurrence 68_ ThinkPHP

Rustdesk builds its own remote desktop relay server

Sword finger offer II 039 Maximum rectangular area of histogram

【经验】win11上安装visio
随机推荐
注释、接续、转义等符号
B站刘二大人-线性回归 Pytorch
Game push: image / table /cv/nlp, multi-threaded start!
Check the useful photo lossless magnification software on Apple computer
JS array list actual use summary
Vulhub vulnerability recurrence 73_ Webmin
Questions d'examen écrit classiques du pointeur
Sword finger offer II 039 Maximum rectangular area of histogram
28io stream, byte output stream writes multiple bytes
After the project is released, index Html is cached
Migrate Infones to stm32
UCF (summer team competition II)
Game push image / table /cv/nlp, multi-threaded start
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
[SQL Server fast track] - authentication and establishment and management of user accounts
SQLite add index
Huawei od computer test question 2
指針經典筆試題
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
What is independent IP and how about independent IP host?