Last chapter, we covered logistic regression and its loss function (i.e., BCE). We were able to implement it using NumPy, and we also covered some tricks along the way. In this chapter, we’ll be covering logistic regression again, but this time, in PyTorch.

We’re going to start by importing the same libraries as before, except this time, we won’t be importing NumPy, we’ll be importing PyTorch instead.

`import torch`

import matplotlib.pyplot as plt

from IPython import display

import time

Now that we imported the required libraries, let’s make the same dataset which we constructed at the start of chapter 2, but this time, in PyTorch.

`X = torch.cat((torch.arange(15, dtype=float), torch.arange(20, 35, dtype=float)), axis=0)`

y = torch.cat((torch.zeros(15, dtype=float), torch.ones(15, dtype=float)), axis=0)

Those 2 lines above look almost identical to the NumPy lines. We essentially replaced “np” with “torch” and voila, we’re using PyTorch instead.

Let’s print out the content of the variables and look inside.

`print('X')`

print(X)

print('y')

print(y)