Files
pytorch-deep-learning/02_pytorch_classification.ipynb

50 KiB

02. Neural Network Classification with PyTorch

TK - What we're going to cover

  • Simple classification (reiterate PyTorch workflow)
  • More advanced classification (e.g. black and white images or FashionMNIST or FoodMNIST or something)
  • Visualizing a PyTorch model (all of the different connections)

TK - How you can use this notebook

TK - Architecture of a classification network

TK - Make data

In [3]:
from sklearn.datasets import make_moons

# Make 1000 samples 
n_samples = 1000

# Create circles
X, y = make_moons(n_samples,
                  noise=0.07,
                  random_state=42) # keep random state so we get the same values
In [7]:
# Get dataframe of moons
import pandas as pd
moons = pd.DataFrame({"X1": X[:, 0],
    "X2": X[:, 1],
    "label": y
})
moons.head()
Out [7]:
X1 X2 label
0 -0.033411 0.421391 1
1 0.998827 -0.442890 1
2 0.889592 -0.327843 1
3 0.341958 -0.417690 1
4 -0.838531 0.532375 0
In [8]:
# Check different labels
moons.label.value_counts()
Out [8]:
1    500
0    500
Name: label, dtype: int64
In [10]:
# Visualize with a plot
import matplotlib.pyplot as plt
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.RdYlBu)
Out [10]:
<matplotlib.collections.PathCollection at 0x7f53bb9db580>

TK - why show data like this? This is a toy problem but it represents the major key of classification, you have some kind of data represented as numerical values and you'd like to build a model that's able to classify (separate red from blue) it.

In [11]:
# UPTOHERE - building a model 
In [ ]: