1

n_best cannot be larger than n_components, but (param1) > (param1)

Package:
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.

Ways to fix

2

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_)
```
Mar 29, 2022
kellemnegasi 30.0k