22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5 Step 3: Computing gradients

6 Step 4: Updating parameters

Output

# b and w after initialization

[0.49671415] [-0.1382643]

# b and w after our gradient descent

[1.02354094] [1.96896411]

"Do we need to run it for 1,000 epochs? Shouldn’t it stop

automatically after getting close enough to the minimum loss?"

Good question: We don’t need to run it for 1,000 epochs. There are ways of

stopping it earlier, once the progress is considered negligible (for instance, if the

loss was barely reduced). These are called, most appropriately, early stopping

methods. For now, since our model is a very simple one, we can afford to train it for

1,000 epochs.

Figure 1.3 - Fully trained model’s predictions

Just to make sure we haven’t made any mistakes in our code, we can use Scikit-

Learn’s linear regression to fit the model and compare the coefficients.

70 | Chapter 1: A Simple Regression Problem

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!