# 构建计算图(构建网络模型)import torch.nn.functional as F
import torch.nn.init as init
import math
import torch
import torch.nn.init as init
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
%matplotlib inline
读取数据
# 如何用一个PyTorch类来搭建神经网络,# 首先从nn.module中继承整个神经网络的搭建原件,# 这个类中我们可以继承所有可以用于搭建后续神经网络原件
data = pd.read_csv("diabetes.csv",engine ="python").values
x = torch.from_numpy(data[:,0:-1])
y = torch.from_numpy(data[:,-1])#划分训练数据和测试数据
x_train, x_test,y_train,y_test= train_test_split(x.numpy(),y.numpy(), test_size=0.3,random_state=2018)
ss = StandardScaler()
x_train = torch.tensor(ss.fit_transform(x_train))
x_test = torch.tensor(ss.fit_transform(x_test))
y_train = torch.tensor(y_train)
y_test = torch.tensor(y_test)