Skip to content

Homework 2#2

Merged
xImoZA merged 10 commits intomainfrom
homework2
Apr 28, 2025
Merged

Homework 2#2
xImoZA merged 10 commits intomainfrom
homework2

Conversation

@xImoZA
Copy link
Owner

@xImoZA xImoZA commented Mar 3, 2025

KNN with KD-Tree

Copy link

@maybenotilya maybenotilya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень даже неплохо, но key-value лейблы и ломающиеся скейлеры это проблема

self.root: Node[T] = self._build_kdtree(points)

@staticmethod
def _select_axis(points: list[Point[T]]) -> int:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Скорее ax, а не axis, ось то одна

node: Node[T] | None,
neighbors: list[tuple[float, Point[T]]],
) -> list[tuple[float, Point[T]]]:
if node:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Довольно сложно читать такие огромные и страшные ветвения


data = [Point(X[i]) for i in range(len(X))]
self.classifier = KDTree(data, leaf_size=self.leaf_size)
self.clss = {point: cls for point, cls in zip(data, y)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что мешает двум одинаковым точкам иметь разные лейблы?


class Scaler(ABC):
@abstractmethod
def fit(self, data: NDArray[T]):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Немного странно что KNNClassifier работает с питоновскими листами, а скейлеры с нумпаем, но да ладно

if self.min is None or self.max is None:
raise ValueError("Scaler has not been fitted yet.")

return (data - self.min) / (self.max - self.min)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если max == min, то случится коллапс вселенной

if self.max_abs is None:
raise ValueError("Scaler has not been fitted yet.")

return data / self.max_abs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Второй коллапс вселенной

if self.mean is None or self.std is None:
raise ValueError("Scaler has not been fitted yet.")

return (data - self.mean) / self.std

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Третий коллапс вселенной

@xImoZA xImoZA merged commit 5f8090c into main Apr 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants