在进行常见机器学习任务中,我们经常会随机抽取一定比例的数据为训练集,而剩下的为测试集。一般情况下都比较繁琐,所以看了其他的博客之后,准备了一个小函数实现这个功能。

EG: def getRandomIndex(n, x): # form n samples choice x the number of samples # return index of samples that had been choiced and rest index_choiced = np.random.choice(np.arange(n), size=x, replace=False) index_rest = np.delete(np.arange(n), index_choiced) return [index_choiced, index_choiced]
版权声明:本文为yxs9527原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。