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.

import numpy as np

import torch

import torch.optim as optim

import torch.nn as nn

import torch.functional as F

from torch.utils.data import DataLoader, TensorDataset

from sklearn.datasets import make_moons

from sklearn.preprocessing import StandardScaler

from sklearn.model_selection import train_test_split

from sklearn.metrics import confusion_matrix, roc_curve, \

precision_recall_curve, auc

from stepbystep.v0 import StepByStep

A Simple Classification Problem

It is time to handle a different class of problems: classification problems (pun

intended). In a classification problem, we’re trying to predict which class a data

point belongs to.

Let’s say we have two classes of points: They are either red or blue. These are the

labels (y) of the points. Sure enough, we need to assign numeric values to them. We

could assign zero to red and one to blue. The class associated with zero is the

negative class, while one corresponds to the positive class.

In a nutshell, for binary classification, we have:

Color Value Class

Red 0 Negative

Blue 1 Positive

IMPORTANT: In a classification model, the output is the

predicted probability of the positive class. In our case, the model

will predict the probability of a point being blue.

A Simple Classification Problem | 207

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

Saved successfully!

Ooh no, something went wrong!