当前位置:网站首页>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()
边栏推荐
- After setting up the database and website When you open the app for testing, it shows that the server is being maintained
- 【实战技能】非技术背景经理的技术管理
- Csp-j-2020-excellent split multiple solutions
- 个人开发的渗透测试工具Satania v1.2更新
- 【云原生】微服务之Feign自定义配置的记录
- How many checks does kubedm series-01-preflight have
- SSH password free login settings and use scripts to SSH login and execute instructions
- Sword finger offer 04 Search in two-dimensional array
- Codeforces round 712 (Div. 2) d. 3-coloring (construction)
- 26、 File system API (device sharing between applications; directory and file API)
猜你喜欢
Dichotomy, discretization, etc
Codeforces round 712 (Div. 2) d. 3-coloring (construction)
Time of process
Implement a fixed capacity stack
Pointnet++ learning
剑指 Offer 58 - II. 左旋转字符串
剑指 Offer 06.从头到尾打印链表
A misunderstanding about the console window
【Jailhouse 文章】Performance measurements for hypervisors on embedded ARM processors
Service fusing hystrix
随机推荐
个人开发的渗透测试工具Satania v1.2更新
Developing desktop applications with electron
Introduction et expérience de wazuh open source host Security Solution
Demonstration of using Solon auth authentication framework (simpler authentication framework)
智慧工地“水电能耗在线监测系统”
Sword finger offer 06 Print linked list from beginning to end
Little known skills of Task Manager
剑指 Offer 05. 替换空格
卷积神经网络简介
挂起等待锁 vs 自旋锁(两者的使用场合)
从Dijkstra的图灵奖演讲论科技创业者特点
Implement an iterative stack
PC register
shared_ Repeated release heap object of PTR hidden danger
AtCoder Grand Contest 013 E - Placing Squares
注解与反射
Mysql database (I)
Introduction to memory layout of FVP and Juno platforms
A misunderstanding about the console window
Full Permutation Code (recursive writing)