当前位置:网站首页>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()
边栏推荐
- Solution to the palindrome string (Luogu p5041 haoi2009)
- Control unit
- Drawing dynamic 3D circle with pure C language
- [jailhouse article] jailhouse hypervisor
- Palindrome (csp-s-2021-palin) solution
- 浅谈JVM(面试常考)
- 【实战技能】非技术背景经理的技术管理
- A preliminary study of sdei - see the essence through transactions
- kubeadm系列-01-preflight究竟有多少check
- Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
猜你喜欢

A misunderstanding about the console window

Wazuh開源主機安全解决方案的簡介與使用體驗

智慧工地“水电能耗在线监测系统”

Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail

网络工程师考核的一些常见的问题:WLAN、BGP、交换机

剑指 Offer 35.复杂链表的复制

Solution to the palindrome string (Luogu p5041 haoi2009)

Sword finger offer 05 Replace spaces

【Jailhouse 文章】Jailhouse Hypervisor

Graduation project of game mall
随机推荐
Control unit
Maximum number of "balloons"
After setting up the database and website When you open the app for testing, it shows that the server is being maintained
剑指 Offer 35.复杂链表的复制
Hang wait lock vs spin lock (where both are used)
High precision subtraction
记录QT内存泄漏的一种问题和解决方案
Kubedm series-00-overview
CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
ALU逻辑运算单元
利用HashMap实现简单缓存
On-off and on-off of quality system construction
挂起等待锁 vs 自旋锁(两者的使用场合)
Implement an iterative stack
Introduction and experience of wazuh open source host security solution
【实战技能】如何做好技术培训?
API related to TCP connection
A new micro ORM open source framework
Fried chicken nuggets and fifa22
Sword finger offer 04 Search in two-dimensional array