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.

The choice of which class is positive and which class is negative does

not affect model performance. If we reverse the mapping, making

red the positive class, the only difference would be that the model

would predict the probability of a point being red. But, since both

probabilities have to add up to one, we could easily convert

between them, so the models are equivalent.

Instead of defining a model first and then generating synthetic data for it, we’ll do it

the other way around.

Data Generation

Let’s make the data a bit more interesting by using two features (x 1 and x 2 ) this

time. We’ll use Scikit-Learn’s make_moons() to generate a toy dataset with 100

data points. We will also add some Gaussian noise and set a random seed to ensure

reproducibility.

Data Generation

1 X, y = make_moons(n_samples=100, noise=0.3, random_state=0)

Then, we’ll perform the train-validation split using Scikit-Learn’s

train_test_split() for convenience (we’ll get back to splitting indices later):

Train-validation Split

1 X_train, X_val, y_train, y_val = train_test_split(

2 X,

3 y,

4 test_size=.2,

5 random_state=13

6 )

Remember, the split should always be the first thing you do—no

pre-processing, no transformations, nothing happens before the

split.

208 | Chapter 3: A Simple Classification Problem

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

Saved successfully!

Ooh no, something went wrong!