本文主要是介绍【Pytorch深度学习开发实践学习】B站刘二大人课程笔记整理lecture06 Logistic回归,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【Pytorch深度学习开发实践学习】B站刘二大人课程笔记整理lecture06 Logistic回归
课程网址
Pytorch深度学习实践
部分课件内容:
import torchx_data =torch.tensor([[1.0],[2.0],[3.0]])
y_data =torch.tensor([[0.0],[0.0],[1.0]])class LogisticRegressionModel(torch.nn.Module):def __init__(self):super(LogisticRegressionModel, self).__init__()self.linear = torch.nn.Linear(1,1)def forward(self, x):y_pred = torch.sigmoid(self.linear(x))return y_predmodel = LogisticRegressionModel()criterion = torch.nn.BCELoss(reduction='sum')
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)for epoch in range(100):y_pred = model(x_data)loss = criterion(y_pred, y_data)optimizer.zero_grad()loss.backward()optimizer.step()print(epoch,loss.data)
这篇关于【Pytorch深度学习开发实践学习】B站刘二大人课程笔记整理lecture06 Logistic回归的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!