Regression
就我现在学到的知识而言,我所目前知道的问题分两类,一类是回归分析,另一类是分类。
初学者水平较低,仅为个人学习笔记,如有纰漏,请大佬们指出~
今天所学的就是回归 Regression。1.搭建神经网络 2.定义损失函数 3.训练网络
先贴出代码
import torch
import torch.nn.functional as F #import activation fuctions(导入激活函数)
class Net(torch.nn.Module): # extends the module of torch(继承torch中的 Module 模块)
def __init__(self,n_input,n_hidden1,n_hidden2,n_output):
super(Net,self).__init__() # extends the init fuctions(继承初始化方法)
self.hidden1 = torch.nn.Linear(n_input,n_hidden1)# linear function (线性函数)
self.hidden2 = torch.nn.Linear(n_hidden1,n_hidden2)#linear function(线性函数)
self.output = torch.nn.Linear(n_hidden2,n_output)#linear function(线性函数)
def forward(self,x):# forward function (前向传播方法)
x = F.relu(self.hidden1(x))# use relu function to activate(采用 relu 激活函数)
x = F.relu(self.hidden2(x))# use

这篇博客介绍了PyTorch中回归Regression的基本概念和实现步骤,包括搭建神经网络、定义损失函数和训练过程。博主分享了个人学习心得,并探讨了激活函数的作用和不同损失函数的含义,如均方误差和交叉熵。
最低0.47元/天 解锁文章
785

被折叠的 条评论
为什么被折叠?



