mardi 23 novembre 2021

How do you fix a randrange error showing no range but your input is correct?

I have a Machine Learning pipeline and in the Cross-validation function, randrange is being used. When I execute it though, it gives an error saying that the input's empty. However, when I test the same line of input code above, it does give me a range of 13. Does anybody know what's going wrong?

My code

# Split a dataset into k folds
def cross_validation_split(dataset, n_folds):
    dataset_split = list()
    dataset_copy = list(dataset)
    print(len(dataset_copy))
    fold_size = int(len(dataset) / n_folds)
    for i in range(n_folds):
      fold = list()
      while len(fold) < fold_size:
        index = randrange(len(dataset_copy))
        fold.append(dataset_copy.pop(index))
      dataset_split.append(fold)
    return dataset_split

The output

13
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-33-5932ea250f4a> in <module>()
    190 n_epoch = 100
    191 n_hidden = 5
--> 192 scores = evaluate_algorithm(dataset, back_propagation, n_folds, l_rate, n_epoch, n_hidden)
    193 print('Scores: %s' % scores)
    194 print('Mean Accuracy: %.3f%%' % (sum(scores)/float(len(scores))))

2 frames
/usr/lib/python3.7/random.py in randrange(self, start, stop, step, _int)
    188             if istart > 0:
    189                 return self._randbelow(istart)
--> 190             raise ValueError("empty range for randrange()")
    191 
    192         # stop argument supplied.

ValueError: empty range for randrange()



Aucun commentaire:

Enregistrer un commentaire