Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. def split_train_test(df_in, test_ratio):
  5. # Reserve an out-of-place sample for final evaluation
  6. # Could have used train_test_split from sklearn
  7. df = df_in.copy(deep=True)
  8. np.random.seed(42)
  9. shuffled_indices = np.random.permutation(len(df))
  10. test_set_size = int(len(df) * test_ratio)
  11. test_indices = shuffled_indices[:test_set_size]
  12. train_indices = shuffled_indices[test_set_size:]
  13. return df.iloc[train_indices], df.iloc[test_indices]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement