代码
在老师的代码基础上增加了另外四种优化器,并作出随epoch变化loss的变化图。
import numpy as np
import torch
from matplotlib import pyplot as plt
#1.准备数据
x_data = torch.Tensor([[1],[2],[3]])
y_data = torch.Tensor([[2],[4],[6]])
#2.设计模型
class LinearModel(torch.nn.Module):
def __init__(self):
super(LinearModel,self).__init__()
self.linear