Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

fkdosilovic
Copy link
Contributor

@fkdosilovic fkdosilovic commented Jan 6, 2024

Reference Issues/PRs

None.

What does this implement/fix? Explain your changes.

This PR refactors the fit method of the NearestCentroid classifier.
Changes include:

  • decoupling of the computation of class centroids and choosing the function for centroid computation
  • improvements to References

Any other comments?

None.

Copy link

github-actions bot commented Jan 6, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 1a10bc5. Link to the linter CI: here

@@ -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"])

Copy link
Member

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>`_
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.