Repository navigation
R23-T027: Compare KNN with scikit-learn, fix iterator exhaustion, add regression doctest - #118
Open
mohammedsohail0301-dot wants to merge 1 commit into
Open
mohammedsohail0301-dot wants to merge 1 commit into
mohammedsohail0301-dot wants to merge 1 commit into
Conversation
… regression doctest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
Checklist
Description
This pull request completes Task R23-T027: comparing the repository's kNN classifier (
machine_learning/k_nearest_neighbors.py) against scikit-learn'sKNeighborsClassifieron the Iris dataset, resolving a critical single-use iterator exhaustion defect, and expanding doctests with a 5-point known-answer dataset.Findings & Comparison Highlights:
random_state=42), repositoryKNNand scikit-learn achieved 100.00% agreement (45/45 matches).KNN.__init__,self.data = zip(...)stored a one-time generator iterator. Classifying a single point exhausted the iterator, causing any subsequent.classify()call to crash withIndexError: list index out of range. This is now resolved withself.data = list(zip(...)).Type of Change
Agreement & Benchmark Summary
KNNKNeighborsClassifiernsmallestChanges Made
machine_learning/k_nearest_neighbors.py:self.data = list(zip(train_data, train_target))inKNN.__init__..classify()calls on distinct test points.work/R23-T027/:compare_test.py: Benchmark and agreement verification script on the Iris dataset.COMPARE.md: Detailed technical comparison covering API paradigms, tie-breaking mechanisms, runtime complexities, and beginner recommendations.test_output.txt: Test logs for doctests, pytest, ruff, and ty check.Testing & Verification
uv run python work/R23-T027/compare_test.py-> 100.00% agreement, all checks passed.python3 -m doctest -v machine_learning/k_nearest_neighbors.py-> 14/14 passed.uv run --with pytest pytest --doctest-modules machine_learning/k_nearest_neighbors.py-> 1 passed in 0.32s.uvx ruff check machine_learning/k_nearest_neighbors.py work/R23-T027/compare_test.py-> All checks passed.uvx ruff format --check machine_learning/k_nearest_neighbors.py work/R23-T027/compare_test.py-> 2 files already formatted.uvx ty check --exit-zero machine_learning/k_nearest_neighbors.py-> 0 diagnostics.Additional Notes
student/E26B07F0850/R23-T027-upstream(andR23-T027-upstream) containing only the changes inmachine_learning/k_nearest_neighbors.pyhas been created and pushed for a later upstream PR.