Last active
September 18, 2017 04:07
-
-
Save alivcor/9516927cc211c4cf274167d84574e068 to your computer and use it in GitHub Desktop.
Random Indices for train and test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import random | |
def randPartition(alldata_X, alldata_Y, _FRACTION): | |
""" | |
alldata_X : All of your X (Features) data | |
alldata_Y : All of your Y (Prediction) data | |
_FRACTION : The fraction of data rows you want for train (0.75 means you need 75% of your data as train and 25% as test) | |
""" | |
np.random.seed(0) | |
indices = np.arange(alldata_X.shape[0]) | |
np.random.shuffle(indices) | |
dataX = alldata_X[indices] | |
dataY = alldata_Y[indices] | |
partition_index = int(dataX.shape[0] * _FRACTION) | |
trainX = dataX[0:partition_index] | |
testX = dataX[partition_index:dataX.shape[0]] | |
trainY = dataY[0:partition_index] | |
testY = dataY[partition_index:dataY.shape[0]] | |
return [trainX, trainY, testX, testY] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment