当前位置:网站首页>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()
边栏推荐
- [article de jailhouse] jailhouse hypervisor
- Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
- MySQL数据库(一)
- Animation scoring data analysis and visualization and it industry recruitment data analysis and visualization
- Transform optimization problems into decision-making problems
- 过拟合与正则化
- Brief introduction to tcp/ip protocol stack
- kubeadm系列-00-overview
- Time of process
- Fried chicken nuggets and fifa22
猜你喜欢

Light a light with stm32

Sword finger offer 35 Replication of complex linked list

shared_ Repeated release heap object of PTR hidden danger

Reader writer model

2017 USP Try-outs C. Coprimes

Palindrome (csp-s-2021-palin) solution

YOLOv5-Shufflenetv2

Individual game 12

sync. Interpretation of mutex source code
![[jailhouse article] look mum, no VM exits](/img/fe/87e0851d243f14dff96ef1bc350e50.png)
[jailhouse article] look mum, no VM exits
随机推荐
Palindrome (csp-s-2021-palin) solution
API related to TCP connection
网络工程师考核的一些常见的问题:WLAN、BGP、交换机
kubeadm系列-01-preflight究竟有多少check
object serialization
Annotation and reflection
Time complexity and space complexity
Simple knapsack, queue and stack with deque
剑指 Offer 53 - I. 在排序数组中查找数字 I
全排列的代码 (递归写法)
CF1634 F. Fibonacci Additions
Acwing 4300. Two operations
How can the Solon framework easily obtain the response time of each request?
【实战技能】非技术背景经理的技术管理
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
Implement an iterative stack
Solution to the palindrome string (Luogu p5041 haoi2009)
Sword finger offer 05 Replace spaces
Chapter 6 data flow modeling - after class exercises
Zzulioj 1673: b: clever characters???