n_best cannot be larger than n_components, but (param1) > (param1)
Package:
scikit-learn
47032

Exception Class:
ValueError
Raise code
elf.n_components < 1:
raise ValueError("Parameter n_components must be greater than 0,"
" but its value is {}".format(self.n_components))
if self.n_best < 1:
raise ValueError("Parameter n_best must be greater than 0,"
" but its value is {}".format(self.n_best))
if self.n_best > self.n_components:
raise ValueError("n_best cannot be larger than"
" n_components, but {} > {}"
"".format(self.n_best, self.n_components))
def _fit(self, X):
n_sv = self.n_components
if self.method == 'bistochastic':
normalized_data = _bistochastic_normalize(X)
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/scikit-learn/scikit-learn/blob/c67518350f91072f9d37ed09c5ef7edf555b6cf6/sklearn/cluster/_bicluster.py#L457Ways to fix
n_best shouldn't greater than n_components.
Code to reproduce the exception:
$ pip install scikit-learn==1.0.2
from sklearn.cluster import SpectralBiclustering
import numpy as np
X = np.array([[1, 1], [2, 1], [1, 0],
[4, 7], [3, 5], [3, 6]])
clustering = SpectralBiclustering(n_clusters=2,n_components=3,random_state=0,n_best=5).fit(X)
print(clustering.row_labels_)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-31-d85870820f04> in <module>() 3 X = np.array([[1, 1], [2, 1], [1, 0], 4 [4, 7], [3, 5], [3, 6]]) ----> 5 clustering = SpectralBiclustering(n_clusters=2,n_components=3,random_state=0,n_best=5).fit(X) 6 print(clustering.row_labels_)
/usr/local/lib/python3.7/dist-packages/sklearn/cluster/_bicluster.py in fit(self, X, y) 129 """ 130 X = self._validate_data(X, accept_sparse="csr", dtype=np.float64) --> 131 self._check_parameters() 132 self._fit(X) 133 return self
/usr/local/lib/python3.7/dist-packages/sklearn/cluster/_bicluster.py in _check_parameters(self) 530 raise ValueError( 531 "n_best cannot be larger than n_components, but {} > {}".format( --> 532 self.n_best, self.n_components 533 ) 534 )
ValueError: n_best cannot be larger than n_components, but 5 > 3
Fixed version of the code:
from sklearn.cluster import SpectralBiclustering
import numpy as np
X = np.array([[1, 1], [2, 1], [1, 0],
[4, 7], [3, 5], [3, 6]])
clustering = SpectralBiclustering(n_clusters=2,n_components=3,random_state=0,n_best=3).fit(X)
print(clustering.row_labels_)
Add a possible fix
Please authorize to post fix