Visualize it

We are going to predict the category of every point in a two-dimensional grid by calling the trained SVM to predict along the grid:

%matplotlib inlinefrom itertools import product#Minima and maxima of both featuresxmin, xmax = np.percentile(X[:, 0], [0, 100])ymin, ymax = np.percentile(X[:, 1], [0, 100])#Grid/Cartesian product with itertools.producttest_points = np.array([[xx, yy] for xx, yy in product(np.linspace(xmin, xmax,100), np.linspace(ymin, ymax,100))])#Predictions on the gridtest_preds = rand_grid.predict(test_points)plt.figure(figsize=(15,9))   #change figure-size for easier viewingplt.scatter(X_0[:,0],X_0[:,1], color = 'green')plt.scatter(X_1[:,0],X_1[:,1], color = 'blue')plt.scatter(X_2[:,0],X_2[:,1], color = 'red') ...

Get scikit-learn Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.