开始使用免费开始使用

在 PyTorch 中构建二分类器

回顾一下:一个包含单个线性层、后接 sigmoid 函数的小型神经网络就是一个二分类器。它的行为与逻辑回归相同。

练习搭建这个小型网络,并解读分类器的输出。

本练习是课程的一部分

使用 PyTorch 的深度学习入门

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

import torch
import torch.nn as nn

input_tensor = torch.Tensor([[3, 4, 6, 2, 3, 6, 8, 9]])

# Implement a small neural network for binary classification
model = nn.Sequential(
  nn.____(____),
  nn.____()
)

output = model(input_tensor)
print(output)
编辑并运行代码