-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
MNT Refactor fit method of NearestCentroid. #28072
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: main
Are you sure you want to change the base?
MNT Refactor fit method of NearestCentroid. #28072
Conversation
@@ -162,73 +169,86 @@ def fit(self, X, y): | ||
X, y = self._validate_data(X, y, accept_sparse=["csc"]) | ||
else: | ||
X, y = self._validate_data(X, y, accept_sparse=["csr", "csc"]) | ||
|
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.
Please remove the break line to minimize the diff. They don't break more clarity to the codebase.
multiple cancer types by shrunken centroids of gene expression. Proceedings | ||
of the National Academy of Sciences of the United States of America, | ||
99(10), 6567-6572. The National Academy of Sciences. | ||
<https://www.pnas.org/doi/full/10.1073/pnas.082099299>`_ |
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.
Nowadays we use :doi:
sphinx marker. You can check other occurrences.
|
||
# Choose the transformation for boolean class mask vector. | ||
if is_X_sparse: | ||
mask_trf = lambda mask: np.where(mask)[0] # noqa: E731 |
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.
We don't use lambda and do not add exception to ruff
.
n_samples, n_features = X.shape | ||
|
||
# Compute the centroids. | ||
self.centroids_ = np.empty((n_classes, n_features), dtype=np.float64) |
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.
Actually, I am wondering if this refactoring is necessary since we are modifying this code in this PR: #26689
I have to check if we can just combine both approaches.
Reference Issues/PRs
None.
What does this implement/fix? Explain your changes.
This PR refactors the
fit
method of the NearestCentroid classifier.Changes include:
Any other comments?
None.