Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- def split_train_test(df_in, test_ratio):
- # Reserve an out-of-place sample for final evaluation
- # Could have used train_test_split from sklearn
- df = df_in.copy(deep=True)
- np.random.seed(42)
- shuffled_indices = np.random.permutation(len(df))
- test_set_size = int(len(df) * test_ratio)
- test_indices = shuffled_indices[:test_set_size]
- train_indices = shuffled_indices[test_set_size:]
- return df.iloc[train_indices], df.iloc[test_indices]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement