def construct_train_valid_sets(self, data, p=1/3.):
''' Construct train/valid sets from a dataset, by selecting p% of samples as valid, and the rest for train.mat
data: tuple (X,Y)
p: real ]0,1[, the pourcentage of samples to take as validation.
The samples will be selected randomly.
'''
x = data[0]
y = data[1]
nbr = x.shape[0]
nbr_vald = int(nbr * p)
index = np.arange(nbr)
# shuffle the index
np.random.shuffle(index)
idx_valid = index[:nbr_vald]
idx_train = index[nbr_vald:]
x_train = x[idx_train]
y_train = y[idx_train]
x_valid = x[idx_valid]
y_valid = y[idx_valid]
return [(x_train, y_train), (x_valid, y_valid)]
评论列表
文章目录