import torch
import torch.utils.data as Data
import torch.nn.functional as F
from torch.autograd import Variable
import matplotlib.pyplot as plt
import numpy as np
torch.manual_seed(1)
LR =0.01
BATCH_SIZE =20
EPOCH =10#生成数据
x = torch.unsqueeze(torch.linspace(-1,1,1500),dim =1)
y = x.pow(3)+0.1*torch.normal(torch.zeros(*x.size()))#数据画图
plt.scatter(x.numpy(),y.numpy())
plt.show()
classNet(torch.nn.Module):def__init__(self):super(Net,self).__init__()
self.hidden = torch.nn.Linear(1,20)
self.predict = torch.nn.Linear(20,1)defforward(self,x):
x = F.relu(self.hidden(x))
x = self.predict(x)return x