Skip to content

Commit

Permalink
More pathlib stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
davecom committed Dec 2, 2024
1 parent a18caaa commit 936ccc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions KNN/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
from KNN.knn import KNN
from KNN.digit import Digit
import os
from pathlib import Path
import sys
import pygame
import numpy as np
Expand All @@ -33,9 +33,9 @@ def run():
digit_pixels = np.zeros((PIXEL_HEIGHT, PIXEL_WIDTH, 3),
dtype=np.uint32)
# Load the training data
os.chdir(os.path.dirname(os.path.abspath(__file__)))
digits_knn = KNN(Digit, './datasets/digits/digits.csv',
has_header=False)
digits_file = (Path(__file__).resolve().parent
/ "datasets" / "digits" / "digits.csv")
digits_knn = KNN(Digit, digits_file, has_header=False)
# Startup Pygame, create the window
pygame.init()
screen = pygame.display.set_mode(size=(PIXEL_WIDTH, PIXEL_HEIGHT),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self) -> None:

def test_nearest(self):
k: int = 3
fish_knn = KNN(Fish, str(self.data_file))
fish_knn = KNN(Fish, self.data_file)
test_fish: Fish = Fish("", 0.0, 30.0, 32.5, 38.0, 12.0, 5.0)
nearest_fish: list[Fish] = fish_knn.nearest(k, test_fish)
self.assertEqual(len(nearest_fish), k)
Expand All @@ -42,7 +42,7 @@ def test_nearest(self):

def test_classify(self):
k: int = 5
fish_knn = KNN(Fish, str(self.data_file))
fish_knn = KNN(Fish, self.data_file)
test_fish: Fish = Fish("", 0.0, 20.0, 23.5, 24.0, 10.0, 4.0)
classify_fish: str = fish_knn.classify(k, test_fish)
self.assertEqual(classify_fish, "Parkki")
Expand Down

0 comments on commit 936ccc0

Please sign in to comment.