当前位置:网站首页>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()
边栏推荐
- 嵌入式面试题(一:进程与线程)
- 嵌入式面试题(四、常见算法)
- Redis message queue
- Detailed summary of SQL injection
- Zoom and pan image in Photoshop 2022
- 备忘一下jvxetable的各种数据集获取方法
- 【SQL server速成之路】——身份验证及建立和管理用户账户
- 02. Develop data storage of blog project
- [SQL Server fast track] - authentication and establishment and management of user accounts
- After the project is released, index Html is cached
猜你喜欢
随机推荐
What is independent IP and how about independent IP host?
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
JDBC calls the stored procedure with call and reports an error
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
Self built DNS server, the client opens the web page slowly, the solution
29io stream, byte output stream continue write line feed
Anti shake and throttling are easy to understand
[SQL Server fast track] - authentication and establishment and management of user accounts
02. 开发博客项目之数据存储
毕业设计游戏商城
初识数据库
P2802 回家
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
Graduation design game mall
Redis消息队列
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
[JVM] [Chapter 17] [garbage collector]
初识CDN
Pytorch代码注意的细节,容易敲错的地方
YYGH-11-定时统计