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

ENH Adding callable function option to bicluster method #29196

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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions 10 sklearn/cluster/_bicluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,13 @@ class SpectralBiclustering(BaseSpectral):
The number of row and column clusters in the checkerboard
structure.

method : {'bistochastic', 'scale', 'log'}, default='bistochastic'
method : {'bistochastic', 'scale', 'log'} or callable, default='bistochastic'
Method of normalizing and converting singular vectors into
biclusters. May be one of 'scale', 'bistochastic', or 'log'.
The authors recommend using 'log'. If the data is sparse,
however, log normalization will not work, which is why the
default is 'bistochastic'.
Callable must take a 2D array and return a 2D array.

.. warning::
if `method='log'`, the data must not be sparse.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if `method='log'`, the data must not be sparse.
if `method='log'`, the data must not be sparse.
.. versionadded:: 1.6
The support for passing a callable was added.

Expand Down Expand Up @@ -491,7 +492,7 @@ class SpectralBiclustering(BaseSpectral):
_parameter_constraints: dict = {
**BaseSpectral._parameter_constraints,
"n_clusters": [Interval(Integral, 1, None, closed="left"), tuple],
"method": [StrOptions({"bistochastic", "scale", "log"})],
"method": [StrOptions({"bistochastic", "scale", "log"}), callable],
"n_components": [Interval(Integral, 1, None, closed="left")],
"n_best": [Interval(Integral, 1, None, closed="left")],
}
Expand Down Expand Up @@ -558,7 +559,10 @@ def _check_parameters(self, n_samples):

def _fit(self, X):
n_sv = self.n_components
if self.method == "bistochastic":
if callable(self.method):
normalized_data = self.method(X)
n_sv += 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone add a log based normalization then this would be incorrect, isn't it?

elif self.method == "bistochastic":
normalized_data = _bistochastic_normalize(X)
n_sv += 1
elif self.method == "scale":
Expand Down
2 changes: 1 addition & 1 deletion 2 sklearn/cluster/tests/test_bicluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_spectral_biclustering(global_random_seed, csr_container):
)

non_default_params = {
"method": ["scale", "log"],
"method": ["scale", "log", lambda x: x / x.sum(axis=0)],
"svd_method": ["arpack"],
"n_svd_vecs": [20],
"mini_batch": [True],
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.