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