|
12 | 12 | from load import load_dataset |
13 | 13 | import numpy as np |
14 | 14 | from sklearn.neighbors import KNeighborsClassifier |
15 | | -from knn import fit_model, predict |
16 | 15 |
|
17 | 16 | feature_names = [ |
18 | 17 | 'area', |
@@ -40,8 +39,8 @@ def plot_decision(features, labels): |
40 | 39 | ''' |
41 | 40 | y0, y1 = features[:, 2].min() * .9, features[:, 2].max() * 1.1 |
42 | 41 | x0, x1 = features[:, 0].min() * .9, features[:, 0].max() * 1.1 |
43 | | - X = np.linspace(x0, x1, 100) |
44 | | - Y = np.linspace(y0, y1, 100) |
| 42 | + X = np.linspace(x0, x1, 1000) |
| 43 | + Y = np.linspace(y0, y1, 1000) |
45 | 44 | X, Y = np.meshgrid(X, Y) |
46 | 45 |
|
47 | 46 | model = KNeighborsClassifier(1) |
@@ -72,9 +71,11 @@ def plot_decision(features, labels): |
72 | 71 | labels = np.array([names.index(ell) for ell in labels]) |
73 | 72 |
|
74 | 73 | fig,ax = plot_decision(features, labels) |
| 74 | +fig.tight_layout() |
75 | 75 | fig.savefig('figure4sklearn.png') |
76 | 76 |
|
77 | 77 | features -= features.mean(0) |
78 | 78 | features /= features.std(0) |
79 | 79 | fig,ax = plot_decision(features, labels) |
| 80 | +fig.tight_layout() |
80 | 81 | fig.savefig('figure5sklearn.png') |
0 commit comments