Skip to content

fix(ml): add validation for matching dataSet and labels lengths in kNN - #2201

Open
loulanyue wants to merge 1 commit into
trekhleb:masterfrom
loulanyue:fix/neural-network-learning-rate-guard
Open

fix(ml): add validation for matching dataSet and labels lengths in kNN#2201
loulanyue wants to merge 1 commit into
trekhleb:masterfrom
loulanyue:fix/neural-network-learning-rate-guard

Conversation

@loulanyue

Copy link
Copy Markdown

Summary

In src/algorithms/ml/knn/kNN.js:

  • If dataSet.length !== labels.length, calculating distances and picking labels[i] can produce undefined labels which participate in voting and cause incorrect classification outputs.
  • This PR validates that dataSet.length === labels.length upfront with a clear, descriptive error and adds corresponding unit tests.

@m-coder567

m-coder567 commented Aug 24, 2026 via email

Copy link
Copy Markdown

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.

3 participants