-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.py
More file actions
25 lines (17 loc) · 882 Bytes
/
test.py
File metadata and controls
25 lines (17 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
from src.kNN import KNearestNeighbors
from src.distance import euclidean
# testing the kNN model
raw_data = np.array([[1, 2, 1], [3, 2, 1], [2, 4, 1],
[3, 3, 1], [2, 5, 1], [-1, -2, 0],
[-3, -2, 0], [-2, -4, 0], [-3, -3, 0],
[-2, -5, 0]], dtype=float)
X = raw_data[:, :2]
y = raw_data[:, -1]
model = KNearestNeighbors(k=3, distance_metric=euclidean)
model.train(X, y)
print("Value: {},\tPrediction: {}".format([1, 0], model.predict(np.array([1, 0]))))
print("Value: {},\tPrediction: {}".format([0, 1], model.predict(np.array([0, 1]))))
print("Value: {},\tPrediction: {}".format([0, 0], model.predict(np.array([0, 0]))))
print("Value: {},\tPrediction: {}".format([-1, 0], model.predict(np.array([-1, 0]))))
print("Value: {},\tPrediction: {}".format([0, -1], model.predict(np.array([0, -1]))))