Skip to content

Instantly share code, notes, and snippets.

@geniusnhu
Created March 5, 2020 09:29
Show Gist options
  • Save geniusnhu/9e80e6a2dbce52d81c548e54dc9b6196 to your computer and use it in GitHub Desktop.
Save geniusnhu/9e80e6a2dbce52d81c548e54dc9b6196 to your computer and use it in GitHub Desktop.
Train test set for Time series
# Split train and test sets in correspondence with Time series data
def ts_train_test_split(X, y, test_size):
test_index = int(len(X)*(1-test_size))
X_train = X.iloc[:test_index]
y_train = y.iloc[:test_index]
X_test = X.iloc[test_index:]
y_test = y.iloc[test_index:]
return X_train, X_test, y_train, y_test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment