-
Notifications
You must be signed in to change notification settings - Fork 19
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
Allowing FPS to take numpy array of ints as initialize parameter #225
Changes from 9 commits
5e5847b
1e1658a
34229f9
9b0b77d
ce536cd
c1a1b9e
c25c850
c4ee830
fe78f8f
624b9bb
a383936
c5480cc
8718214
9cf5bb0
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 |
---|---|---|
|
@@ -934,7 +934,7 @@ class _FPS(GreedySelector): | |
Parameters | ||
---------- | ||
|
||
initialize: int, list of int, or 'random', default=0 | ||
initialize: int, list of int, numpy.ndarray of int, or 'random', default=0 | ||
Index of the first selection(s). If 'random', picks a random | ||
value when fit starts. Stored in :py:attr:`self.initialize`. | ||
|
||
|
@@ -1038,7 +1038,14 @@ def _init_greedy_search(self, X, y, n_to_select): | |
self.hausdorff_ = np.full(X.shape[self._axis], np.inf) | ||
self.hausdorff_at_select_ = np.full(X.shape[self._axis], np.inf) | ||
|
||
if self.initialize == "random": | ||
if isinstance(self.initialize, np.ndarray): | ||
if all(isinstance(i, numbers.Integral) for i in self.initialize): | ||
for i, val in enumerate(self.initialize): | ||
self.selected_idx_[i] = val | ||
self._update_post_selection(X, y, self.selected_idx_[i]) | ||
else: | ||
raise ValueError("Initialize parameter must contain only int") | ||
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. Would you mind adding a test for this error raise? You can take a look how to test that in the pytest docs or find another example in our test suite 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. Should be fixed now. Added the unit tests I wrote in test_feature_simple_fps to test_sample_simple_fps. Let me know if this looks correct! |
||
elif self.initialize == "random": | ||
random_state = check_random_state(self.random_state) | ||
initialize = random_state.randint(X.shape[self._axis]) | ||
self.selected_idx_[0] = initialize | ||
|
@@ -1053,6 +1060,7 @@ def _init_greedy_search(self, X, y, n_to_select): | |
for i, val in enumerate(self.initialize): | ||
self.selected_idx_[i] = val | ||
self._update_post_selection(X, y, self.selected_idx_[i]) | ||
|
||
else: | ||
raise ValueError("Invalid value of the initialize parameter") | ||
|
||
|
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.
Shouldn't these operattions also be performed for a List and not only for a numpy array? Something like
Even though there is probably a shorter way to check of an instance belongs to either one of two classes.
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.
Yes. Let me know what you think about the new changes I made.