|
|
@@ -1,4 +1,5 @@
|
|
|
#!/usr/bin/python3
|
|
|
+from sklearn.model_selection import KFold
|
|
|
from sklearn.neighbors import NearestNeighbors, KNeighborsClassifier
|
|
|
from sklearn.ensemble import RandomForestClassifier
|
|
|
import numpy as np
|
|
|
@@ -32,7 +33,8 @@ def main():
|
|
|
# kNearestNeighbors([[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 5, 5]],
|
|
|
# ["three", 2, 3, "5"], [[1, 1, 0], [0, 5, 5]])
|
|
|
|
|
|
-def kNearestNeighbors(data: list, classifications: list):
|
|
|
+
|
|
|
+def kNearestNeighbors(data: list, classifications: list, test_data: list):
|
|
|
folds = KFold(n_splits=5)
|
|
|
for train_index, test_index in folds.split(data):
|
|
|
kn = KNeighborsClassifier(n_neighbors=2)
|
|
|
@@ -49,6 +51,7 @@ def kNearestNeighbors(data: list, classifications: list):
|
|
|
# with open("results.txt", "w+") as file:
|
|
|
# file.write(writestr)
|
|
|
|
|
|
+
|
|
|
def nearestNeighbors(data: list, test_data: list):
|
|
|
x = np.array(data)
|
|
|
nbrs = NearestNeighbors(n_neighbors=1, algorithm='ball_tree').fit(x)
|