MCPcopy
hub / github.com/ddbourgin/numpy-ml / test_knn_clf

Function test_knn_clf

numpy_ml/tests/test_nonparametric.py:50–84  ·  view source on GitHub ↗
(N=15)

Source from the content-addressed store, hash-verified

48
49
50def test_knn_clf(N=15):
51 np.random.seed(12345)
52
53 i = 0
54 while i < N:
55 N = np.random.randint(2, 100)
56 M = np.random.randint(2, 100)
57 k = np.random.randint(1, N)
58 n_classes = np.random.randint(2, 10)
59 ls = np.min([np.random.randint(1, 10), N - 1])
60 weights = "uniform"
61
62 X = np.random.rand(N, M)
63 X_test = np.random.rand(N, M)
64 y = np.random.randint(0, n_classes, size=N)
65
66 knn = KNN(k=k, leaf_size=ls, metric=euclidean, classifier=True, weights=weights)
67 knn.fit(X, y)
68 preds = knn.predict(X_test)
69
70 gold = KNeighborsClassifier(
71 p=2,
72 metric="minkowski",
73 leaf_size=ls,
74 n_neighbors=k,
75 weights=weights,
76 algorithm="ball_tree",
77 )
78 gold.fit(X, y)
79 gold_preds = gold.predict(X_test)
80
81 for mine, theirs in zip(preds, gold_preds):
82 np.testing.assert_almost_equal(mine, theirs)
83 print("PASSED")
84 i += 1
85
86
87def test_gp_regression(N=15):

Callers

nothing calls this directly

Calls 5

fitMethod · 0.95
predictMethod · 0.95
KNNClass · 0.90
fitMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected