用PyTorch类实现Logistic regression
1.PyTorch基础实现代码
import torch
from torch.autograd import Variable
torch.manual_seed(2)
x_data = Variable(torch.Tensor([[1.0], [2.0], [3.0], [4.0]]))
y_data = Variable(torch.Tensor([[0.0], [0.0], [1.0], [1.0]]))
# 初始化
w = Variable(torch.Tensor([-1]), requires_grad=True)
b = Variable(torch.Tensor([0]), requires_grad=True)
epochs = 100
costs = []
lr = 0.1
print('before training,predict of x = 1.5 is :')
print

本文介绍了如何使用PyTorch基础代码实现Logistic Regression,并通过torch.nn.Module类来构建网络结构,详细阐述了这两个方法。
最低0.47元/天 解锁文章
598

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



