In the following steps, you will learn how to create and plot a toy dataset:
- 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
- In the following code, we ...