当前位置:网站首页>7. Processing the input of multidimensional features
7. Processing the input of multidimensional features
2022-07-05 05:41:00 【A big pigeon】
Multidimensional input logistic regression
Multi layer network
Complete code :
import torch
import torch.nn.functional as F
import numpy as np
import matplotlib.pyplot as plt
# 1. Prepare the data , from csv File read
xy = np.loadtxt('diabetes.csv.gz', delimiter=',', dtype=np.float32)
x_data = torch.from_numpy(xy[:,:-1])
y_data = torch.from_numpy(xy[:,[-1]])
# 2. The design model ( class ) Inherit nn.Module In order to use its method
class Model(torch.nn.Module):
# initialization
def __init__(self):
super(Model, self).__init__()
#3 Layer neural networks
self.linear1 = torch.nn.Linear(8, 6) # Linear Is a linear unit
self.linear2 = torch.nn.Linear(6, 4)
self.linear3 = torch.nn.Linear(4, 1)
self.sigmoid = torch.nn.Sigmoid()
# Feedforward method
def forward(self, x):
# The output of each layer is the input of the lower layer
x = self.sigmoid(self.linear1(x))
x = self.sigmoid(self.linear2(x))
x = self.sigmoid(self.linear3(x))
return x
model = Model()
# 3 loss and optimizer( Optimizer )
criterion = torch.nn.BCELoss(size_average=True)
# Optimizer . model.parameters() Get the parameters that need to be optimized in the model ,lr(learning rate, Learning rate )
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
# 4 Training process
for epoch in range(100):
# feedforward
y_pred = model(x_data)
# Calculate the loss
loss = criterion(y_pred, y_data)
print("epoch={},loss={}".format(epoch, loss))
optimizer.zero_grad() # Zeroing
# Back propagation
loss.backward()
# to update 、 Optimization parameters
optimizer.step()
边栏推荐
- Introduction to tools in TF-A
- Add level control and logger level control of Solon logging plug-in
- 剑指 Offer 58 - II. 左旋转字符串
- CF1634E Fair Share
- 搭建完数据库和网站后.打开app测试时候显示服务器正在维护.
- Implement a fixed capacity stack
- Control Unit 控制部件
- 中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
- 卷积神经网络简介
- Sword finger offer 04 Search in two-dimensional array
猜你喜欢
剑指 Offer 05. 替换空格
利用HashMap实现简单缓存
剑指 Offer 53 - II. 0~n-1中缺失的数字
用STM32点个灯
Implement a fixed capacity stack
Sword finger offer 53 - I. find the number I in the sorted array
Full Permutation Code (recursive writing)
F - Two Exam(AtCoder Beginner Contest 238)
Solution to game 10 of the personal field
SAP method of modifying system table data
随机推荐
Kubedm series-00-overview
Typical use cases for knapsacks, queues, and stacks
Personal developed penetration testing tool Satania v1.2 update
数仓项目的集群脚本
【实战技能】非技术背景经理的技术管理
利用HashMap实现简单缓存
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
Time complexity and space complexity
PC寄存器
How can the Solon framework easily obtain the response time of each request?
【Jailhouse 文章】Look Mum, no VM Exits
SAP-修改系统表数据的方法
Daily question - Search two-dimensional matrix PS two-dimensional array search
挂起等待锁 vs 自旋锁(两者的使用场合)
【Jailhouse 文章】Jailhouse Hypervisor
Detailed explanation of expression (csp-j 2021 expr) topic
剑指 Offer 09. 用两个栈实现队列
A preliminary study of sdei - see the essence through transactions
ALU逻辑运算单元
PC register