July 2018
Beginner to intermediate
406 pages
9h 55m
English
We will now examine the decision boundaryies. In order to plot these on paper, we will simplify and look at only two dimensions:
knn.fit(features[:, [0,2]], target)
We will call predict on a grid of feature values (1000 by 1000 points):
y0, y1 = features[:, 2].min() * .9, features[:, 2].max() * 1.1 x0, x1 = features[:, 0].min() * .9, features[:, 0].max() * 1.1 X = np.linspace(x0, x1, 1000) Y = np.linspace(y0, y1, 1000) X, Y = np.meshgrid(X, Y) C = knn.predict(np.vstack([X.ravel(), Y.ravel()]).T).reshape(X.shape)
Now, we plot the decision boundaries:
cmap = ListedColormap([(1., 1., 1.), (.2, .2, .2), (.6, .6, .6)]) fig,ax = plt.subplots() ax.scatter(features[:, 0], features[:, 2], c=target, cmap=cmap) for ...
Read now
Unlock full access