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.

If you’re using Jupyter’s default settings, this link should open Chapter 1’s

notebook. If not, just click on Chapter01.ipynb on your Jupyter’s home page.

Imports

For the sake of organization, all libraries needed throughout the code used in any

given chapter are imported at its very beginning. For this chapter, we’ll need the

following imports:

import numpy as np

from sklearn.linear_model import LinearRegression

import torch

import torch.optim as optim

import torch.nn as nn

from torchviz import make_dot

A Simple Regression Problem

Most tutorials start with some nice and pretty image classification problem to

illustrate how to use PyTorch. It may seem cool, but I believe it distracts you from

the main goal: learning how PyTorch works.

For this reason, in this first example, I will stick with a simple and familiar problem:

a linear regression with a single feature x! It doesn’t get much simpler than that!

Equation 1.1 - Simple linear regression model

A Simple Regression Problem | 61

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

Saved successfully!

Ooh no, something went wrong!