import numpy as np def spirals(n_samples=400): N = n_samples theta = np.sqrt(np.random.rand(N))*2*np.pi r_a = 2*theta + np.pi data_a = np.array([np.cos(theta)*r_a, np.sin(theta)*r_a]).T x_a = data_a + np.random.randn(N,2) r_b = -2*theta - np.pi data_b = np.array([np.cos(theta)*r_b, np.sin(theta)*r_b]).T x_b = data_b + np.random.randn(N,2) res_a = np.zeros((N,1), dtype='uint8') res_b = np.ones((N,1), dtype='uint8') x = np.concatenate([x_a, x_b], axis=0) res = np.concatenate([res_a, res_b], axis=0).reshape(-1) return x, res Xdata, ydata = spirals()