July 2017
Intermediate to advanced
382 pages
9h 13m
English
To test our perceptron classifier, we need to create some mock data. Let's keep things simple for now and generate 100 data samples (n_samples) belonging to one of two blobs (centers), again relying on scikit-learn's make_blobs function:
In [3]: from sklearn.datasets.samples_generator import make_blobs... X, y = make_blobs(n_samples=100, centers=2,... cluster_std=2.2, random_state=42)
One thing to keep in mind is that our perceptron classifier expects target labels to be either +1 or -1, whereas make_blobs returns 0 and 1. An easy way to adjust the labels is with the following equation:
In [4]: y = 2 * y - 1
Let's have a look at the data:
In [5]: import matplotlib.pyplot as plt... plt.style.use('ggplot')... %matplotlib ...Read now
Unlock full access