22.02.2024 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

# Sanity Check: do we get the same results as our

# gradient descent?

linr = LinearRegression()

linr.fit(x_train, y_train)

print(linr.intercept_, linr.coef_[0])

Output

# intercept and coef from Scikit-Learn

[1.02354075] [1.96896447]

They match up to six decimal places—we have a fully working implementation of

linear regression using Numpy.

Time to TORCH it!

PyTorch

First, we need to cover a few basic concepts that may throw you off-balance if you

don’t grasp them well enough before going full-force on modeling.

In deep learning, we see tensors everywhere. Well, Google’s framework is called

TensorFlow for a reason! What is a tensor, anyway?

Tensor

In Numpy, you may have an array that has three dimensions, right? That is,

technically speaking, a tensor.

A scalar (a single number) has zero dimensions, a vector has one

dimension, a matrix has two dimensions, and a tensor has three

or more dimensions. That’s it!

But, to keep things simple, it is commonplace to call vectors and matrices tensors as

well—so, from now on, everything is either a scalar or a tensor.

PyTorch | 71

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

Saved successfully!

Ooh no, something went wrong!