votes up 1

Parameter n_best must be greater than 0, but its value is (param1)

Package:
Exception Class:
ValueError

Raise code

                     " {}. It should either be a single integer"
                                 " or an iterable with two integers:"
                                 " (n_row_clusters, n_column_clusters)") from e
        if self.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
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 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

votes up 1 votes down

The parameter n_best should be given a value greater than 0.

Code to reproduce the exception:

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, random_state=0,n_best=0).fit(X)
clustering.row_labels_

The exception output:

--------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-f7d719aed33c> 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, random_state=0,n_best=0).fit(X)  6 clustering.row_labels_ 
/usr/local/lib/python3.7/dist-packages/sklearn/cluster/_bicluster.py in _check_parameters(self)  524 raise ValueError(  525 "Parameter n_best must be greater than 0, but its value is {}".format( --> 526 self.n_best  527 )  528 ) 
ValueError: Parameter n_best must be greater than 0, but its value is 0

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, random_state=0,n_best=2).fit(X)
clustering.row_labels_

Output:

array([1, 1, 1, 0, 0, 0], dtype=int32)

Mar 29, 2022 kellemnegasi answer
kellemnegasi 30.0k

Add a possible fix

Please authorize to post fix