mercredi 25 mai 2016

Why Do I get: TypeError: choice() takes 2 positional arguments but 4 were given?

I have a problem with random.choice which I can't understand. I pass 3 arguments to the function which is allowed to have 4 (http://ift.tt/1OZ1jvz), but it writes I am allowed to give only 2 and 4 were given.

def load_data():
dataset = load_boston()
num_samples = size(dataset.data, 0)
test_set_sz = int(1.0 * num_samples / 10)
tst_sub_inds = random.choice(range(num_samples), test_set_sz, False)
data_test, label_test = dataset.data[tst_sub_inds, :], dataset.target[tst_sub_inds]
trn_sub_inds = list(set(range(num_samples)) - set(tst_sub_inds)) 
data_train, label_train = dataset.data[trn_sub_inds, :], dataset.target[trn_sub_inds]
return ((data_train, label_train), (data_test, label_test))

The Error:

tst_sub_inds = random.choice(range(num_samples), test_set_sz, False) TypeError: choice() takes 2 positional arguments but 4 were given Blockquote

What is the problem? Maybe it due to an old version of python?

Thanks, Eli




Aucun commentaire:

Enregistrer un commentaire