Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def subsample(X,y, ratio=0.8):
- # pick a random subsample of X and the corresponding y
- nLength = len(X)
- numberOfPicks = int(nLength * ratio)
- rows, columns = X.shape
- sample_X = np.array([])
- sample_y = np.array([])
- for i in range(numberOfPicks):
- if i == 0:
- sample_X = np.asarray(np.zeros((int(rows*ratio), columns)))
- sample_y = np.asarray(np.zeros((int(rows*ratio), 1)))
- randomIndex = random.randrange(0, numberOfPicks, 1)
- sample_X[randomIndex] = X[randomIndex]
- sample_y[randomIndex] = y[randomIndex]
- assert len(sample_X) == numberOfPicks
- return sample_X,sample_y
- subsampleTestX, subsampleTestY = subsample(X,y)
- print(subsampleTestX)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement