Routines.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:structured-output-ae 作者: sbelharbi 项目源码 文件源码
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)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号