当前位置:网站首页>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()
边栏推荐
- Hang wait lock vs spin lock (where both are used)
- Talking about JVM (frequent interview)
- 使用Electron开发桌面应用
- Alu logic operation unit
- SSH password free login settings and use scripts to SSH login and execute instructions
- Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
- CF1634 F. Fibonacci Additions
- 卷积神经网络——卷积层
- Simply sort out the types of sockets
- [cloud native] record of feign custom configuration of microservices
猜你喜欢
Graduation project of game mall
读者写者模型
Introduction and experience of wazuh open source host security solution
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
CF1637E Best Pair
Pointnet++ learning
Sword finger offer 58 - ii Rotate string left
Sword finger offer 05 Replace spaces
Sword finger offer 04 Search in two-dimensional array
Sword finger offer 09 Implementing queues with two stacks
随机推荐
Graduation project of game mall
软件测试 -- 0 序
Solution to the palindrome string (Luogu p5041 haoi2009)
Educational codeforces round 109 (rated for Div. 2) C. robot collisions D. armchairs
Add level control and logger level control of Solon logging plug-in
动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
Time complexity and space complexity
Personal developed penetration testing tool Satania v1.2 update
Pointnet++ learning
Simple knapsack, queue and stack with deque
常见的最优化方法
二十六、文件系统API(设备在应用间的共享;目录和文件API)
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
[jailhouse article] jailhouse hypervisor
Maximum number of "balloons"
Fried chicken nuggets and fifa22
R语言【数据集的导入导出】
Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
Bit mask of bit operation
SSH password free login settings and use scripts to SSH login and execute instructions