import torch
import numpy as np
#数据读入
xy = np.loadtxt('diabetes.csv.gz',delimiter=',',dtype=np.float32) #delimiter 指的是分隔符的意思
x_data = torch.from_numpy(xy[:,:-1]) #x_data是前8列
y_data = torch.from_numpy(xy[:,[-1]]) # y_data是最后1列
class Model(torch.nn.Module):
def __init__(self):
super(Model,self).__init__()
#self.linear = torch.nn.Linear(8,1) #直接8维输入,1维输出的二分类模型 对应的w为8*1的向量。
self.linear1 = torch.nn.Linear(8,6)
self.linear2 = torch.nn.Linear(6,4)
self.linear3 = torch.nn.Linear(4,1) #从8->4->1维
self.sigmoid = torch.nn.Sigmoid() #这里的激活函数可以选择很多,也可以用Sign()、Linear()、ReLU()等。 要改成:self.activate = torch.nn.ReLU().
def forward(self, x):
# x = self.sigmoid(self.linear(x)) #直接输入8->1
x = self.sigmoid(self.linear1(x))
x = self.sigmoid(self.linear2(x))
Pytorch学习(6):多维输入
最新推荐文章于 2022-11-01 20:49:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)