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.

It is also possible to think of it as the simplest neural network possible: one input,

one output, and no activation function (that is, linear).

Figure 1.1 - The simplest of all neural networks

If you have read Chapter 0, you can either choose to skip to the

"Linear Regression in Numpy" section or to use the next two

sections as a review.

Data Generation

Let’s start generating some synthetic data. We start with a vector of 100 (N) points

for our feature (x) and create our labels (y) using b = 1, w = 2, and some Gaussian

noise [41] (epsilon).

Synthetic Data Generation

Data Generation

1 true_b = 1

2 true_w = 2

3 N = 100

4

5 # Data Generation

6 np.random.seed(42)

7 x = np.random.rand(N, 1)

8 epsilon = (.1 * np.random.randn(N, 1))

9 y = true_b + true_w * x + epsilon

Next, let’s split our synthetic data into train and validation sets, shuffling the array

of indices and using the first 80 shuffled points for training.

62 | Chapter 1: A Simple Regression Problem

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

Saved successfully!

Ooh no, something went wrong!