From a985d6536756d2a14d738f4df6ee5145210cafb6 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Wed, 19 Jan 2022 11:07:08 +0100 Subject: [PATCH 1/3] Update knn example to reflect current implementation --- examples/classification/demo_knn.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/classification/demo_knn.py b/examples/classification/demo_knn.py index 2b411b87a2..bf6c5e52ef 100644 --- a/examples/classification/demo_knn.py +++ b/examples/classification/demo_knn.py @@ -138,7 +138,8 @@ def verify_algorithm(x, y, split_number, split_size, k, seed=None): for split_index in range(split_number): fold_x, fold_y, verification_x, verification_y = create_fold(x, y, split_size, seed) - classifier = KNeighborsClassifier(fold_x, fold_y, k) + classifier = KNeighborsClassifier(k) + classifier.fit(fold_x, fold_y) result_y = classifier.predict(verification_x) accuracies.append(calculate_accuracy(result_y, verification_y).item()) return accuracies From 9fb36cb2ab6a293986c00daca4cba3d0bf380ecd Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Wed, 19 Jan 2022 15:27:04 +0100 Subject: [PATCH 2/3] Remove redundant ht.array() calls --- examples/classification/demo_knn.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/classification/demo_knn.py b/examples/classification/demo_knn.py index bf6c5e52ef..c3a557acbc 100644 --- a/examples/classification/demo_knn.py +++ b/examples/classification/demo_knn.py @@ -95,10 +95,10 @@ def create_fold(dataset_x, dataset_y, size, seed=None): data_indices = ht.array(indices[0:size], split=0) verification_indices = ht.array(indices[size:], split=0) - fold_x = ht.array(dataset_x[data_indices], is_split=0) - fold_y = ht.array(dataset_y[data_indices], is_split=0) - verification_y = ht.array(dataset_y[verification_indices], is_split=0) - verification_x = ht.array(dataset_x[verification_indices], is_split=0) + fold_x = dataset_x[data_indices] + fold_y = dataset_y[data_indices] + verification_y = dataset_y[verification_indices] + verification_x = dataset_x[verification_indices] # Balance arrays fold_x.balance_() From 994673c3579fd0b38b00466a6c7fbcbe6ae9be71 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Thu, 20 Jan 2022 10:44:00 +0100 Subject: [PATCH 3/3] Print statement update --- examples/classification/demo_knn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/classification/demo_knn.py b/examples/classification/demo_knn.py index c3a557acbc..590ea08c1b 100644 --- a/examples/classification/demo_knn.py +++ b/examples/classification/demo_knn.py @@ -145,4 +145,4 @@ def verify_algorithm(x, y, split_number, split_size, k, seed=None): return accuracies -print(verify_algorithm(X, Y, 1, 30, 5, 1)) +print("Accuracy: {}".format(verify_algorithm(X, Y, 1, 30, 5, 1)))