def split_data(self,n,v=5):
''' The function split the data into v folds. Whatever the number of sample per class
Input:
n : the number of samples
v : the number of folds
Output: None
'''
step = n //v # Compute the number of samples in each fold
sp.random.seed(1) # Set the random generator to the same initial state
t = sp.random.permutation(n) # Generate random sampling of the indices
indices=[]
for i in range(v-1): # group in v fold
indices.append(t[i*step:(i+1)*step])
indices.append(t[(v-1)*step:n])
for i in range(v):
self.iT.append(sp.asarray(indices[i]))
l = range(v)
l.remove(i)
temp = sp.empty(0,dtype=sp.int64)
for j in l:
temp = sp.concatenate((temp,sp.asarray(indices[j])))
self.it.append(temp)
评论列表
文章目录