-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ENH duck-typing scikit-learn estimator instead of inheritance #858
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
Changes from 2 commits
d17b6b5
379ea7e
8790628
e997e23
94b0725
9fbf360
f736879
fcb118e
a4e959c
65ae4fd
5b76d49
8284b70
e97ae36
495ec27
10456f5
93200e1
f104057
b82e4d9
70b6778
c67c775
010f4d5
178d0f0
9868d0f
2e1ee17
8889cfd
5e875a0
9545172
29a414b
12991ba
e24ee06
525002f
189f0e9
2cbe273
cc7fae9
29e4619
a098e84
0aa328e
8cce474
8d4ff31
0ceacfb
ee6b7b0
d089b7b
ac7e00a
d815e2d
964d082
99d5206
48d1fd5
18b6057
76fbd59
8fa97ed
615a2bf
b75b77d
b627cf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ def check_neighbors_object(nn_name, nn_object, additional_neighbor=0): | |
""" | ||
if isinstance(nn_object, Integral): | ||
return NearestNeighbors(n_neighbors=nn_object + additional_neighbor) | ||
elif isinstance(nn_object, KNeighborsMixin): | ||
elif hasattr(nn_object, 'kneighbors') and hasattr(nn_object, 'kneighbors_graph'): | ||
return clone(nn_object) | ||
else: | ||
raise_isinstance_error(nn_name, [int, KNeighborsMixin], nn_object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we should as well change the error message since we don't strictly require to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been debating between two implementations here (my two latest commits [1 2]). [1] uses sklearn.base.clone to verify that the nn_object is an sklearn-like estimator that can be cloned. This implementation is more consistent with how the library checks the integrity of other estimators - such as the KMeans Estimator check in [2] raises a TypeError if the nn_object is neither an integer, nor exposes both Do you prefer one over the other? |
||
|
Uh oh!
There was an error while loading. Please reload this page.