title: writing a train_test_split function with numpy
body: <p>I am trying to write my own train test split function using numpy instead of using sklearn's train_test_split function. I am splitting the data into 70% training and 30% test. I am using the boston housing data set from sklearn.</p>
  
  <p>This is the shape of the data:</p>
  
  <pre><code>housing_features.shape #(506,13) where 506 is sample size and it has 13 features.
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>city_data = datasets.load_boston()
  housing_prices = city_data.target
  housing_features = city_data.data
  
  def shuffle_split_data(X, y):
      split = np.random.rand(X.shape[0]) &lt; 0.7
  
      X_Train = X[split]
      y_Train = y[split]
      X_Test =  X[~split]
      y_Test = y[~split]
  
      print len(X_Train), len(y_Train), len(X_Test), len(y_Test)
      return X_Train, y_Train, X_Test, y_Test
  
  try:
      X_train, y_train, X_test, y_test = shuffle_split_data(housing_features, housing_prices)
      print "Successful"
  except:
      print "Fail"
  </code></pre>
  
  <p>The print output i got is:</p>
  
  <pre><code>362 362 144 144
  "Successful"
  </code></pre>
  
  <p>But i know it was not successful because i get a different numbers for the length when i run it again Versus just using SKlearn's train test function and always get 354 for the length of X_train.</p>
  
  <pre><code>#correct output
  from sklearn.cross_validation import train_test_split
  X_train, X_test, y_train, y_test = train_test_split(housing_features, housing_prices, test_size=0.3, random_state=42)
  print len(X_train) 
  #354 
  </code></pre>
  
  <p>What am i missing my my function?</p>