Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. def subsample(X,y, ratio=0.8):    
  2.         # pick a random subsample of X and the corresponding y
  3.         nLength = len(X)
  4.         numberOfPicks = int(nLength * ratio)
  5.         rows, columns = X.shape
  6.         sample_X = np.array([])
  7.         sample_y = np.array([])
  8.         for i in range(numberOfPicks):
  9.             if i == 0:
  10.                 sample_X = np.asarray(np.zeros((int(rows*ratio), columns)))
  11.                 sample_y = np.asarray(np.zeros((int(rows*ratio), 1)))
  12.             randomIndex = random.randrange(0, numberOfPicks, 1)
  13.             sample_X[randomIndex] = X[randomIndex]
  14.             sample_y[randomIndex] = y[randomIndex]
  15.         assert len(sample_X) == numberOfPicks
  16.         return sample_X,sample_y
  17.  
  18. subsampleTestX, subsampleTestY = subsample(X,y)
  19. print(subsampleTestX)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement