-
Notifications
You must be signed in to change notification settings - Fork 1
Knn #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…o bst Merging branch bst.
…o bst sdf building a binary search tree.
…ctures into traversal-bst g g Lines starting with '#' will be ignocquire post_order_trav. red, and an empty message aborts
.travis.yml
Outdated
| # command to install dependencies | ||
| install: | ||
| - pip install -e .[test] | ||
| # - pip install coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove corpse code
.travis.yml
Outdated
| script: | ||
| - py.test --cov=. --cover-report term-missing | ||
|
|
||
| # notifications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove corpse code
src/knn.py
Outdated
| self.data = data | ||
| if k > len(data) or type(k) is not int or k <= 0: | ||
| raise ValueError("The number of neighbors to predict against must be an integer greater than 0 and less than size of data.") | ||
| self.k = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why set self.k if you have it coming into the method as an optional parameter
| for data_idx in range(len(self.data)): | ||
| squares_sum = 0.0 | ||
| for item_idx in range(len(eval_item)): | ||
| squares_sum += (eval_item[item_idx] - self.data[data_idx][item_idx]) ** 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing out on the power of numpy or pandas to perform math operations across an entire data set. The distance calculation could be one-lined.
| raise ValueError("The number of neighbors to predict against must be an integer greater than 0 and less than size of data.") | ||
| self.k = 5 | ||
|
|
||
| def predict(self, evals, k=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you providing k here? You set it when you initialize the object.
| win.append(self._get_winner(distance_list, k)) | ||
| return win | ||
|
|
||
| def _get_winner(self, distance_list, k): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you getting k here when you've defined it on init?
No description provided.