1.1 Fix random seed for reproducibility

In [2]:
seed = 7
np.random.seed(seed)

1.2 We need to generate two sets of data

In [3]:
def spirals(points, noise=.5):
    n = np.sqrt(np.random.rand(points,1)) * 780 * (2*np.pi)/360
    d1x = -np.cos(n)*n + np.random.rand(points,1) * noise
    d1y = np.sin(n)*n + np.random.rand(points,1) * noise
    return (np.vstack((np.hstack((d1x,d1y)),np.hstack((-d1x,-d1y)))), 
            np.hstack((np.zeros(points),np.ones(points))))


X, y = spirals(1000)
print(X.shape)
print(y.shape)
print(type(X))
print(type(y))
(2000, 2)
(2000,)
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>

1.3 Spliting data into train and test

In [4]:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)