Skip to content Skip to sidebar Skip to footer

Found Array With 0 Sample(s) (shape=(0, 40)) While A Minimum Of 1 Is Required

I'm testing a simple prediction program with Python 2.7, sklearn 0.17.1, numpy 1.11.0. I got matrix with propabilities from LDA model, and now I want create RandomForestClassifier

Solution 1:

This is the original code from the scikit-learn repo (validation.py#L409):

if ensure_min_samples > 0:
   n_samples = _num_samples(array)
   if n_samples < ensure_min_samples:
      raise ValueError("Found array with %d sample(s) (shape=%s) while a"
                       " minimum of %d is required%s."
                        % (n_samples, shape_repr, ensure_min_samples,
                        context))

So, the n_samples = _num_samples(array). By the way, array is the input object to check / convert.

Next, validation.py#L111:

def _num_samples(x):
    """Return number of samples in array-like x."""
    if hasattr(x, 'fit'):
        # stuff
    if not hasattr(x, '__len__') and not hasattr(x, 'shape'):
        # stuff
    if hasattr(x, 'shape'):
        if len(x.shape) == 0:
            # raise TypeError
        return x.shape[0]
    else:
        return len(x)

So, the number of samples equals to the length of first dimension of array, which is 0 since array.shape = (0, 40).

And I don't know what this all means, but I hope it makes things clearer.


Solution 2:

It is only probably, you write a wrong path of your test data, please get some check.


Post a Comment for "Found Array With 0 Sample(s) (shape=(0, 40)) While A Minimum Of 1 Is Required"