I know how to utilize a basic train_test_split
:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)
However, what if I want to divide my training and testing set by a variable, in this case year
. I want all values where year==2019
to be my test set while year<2019
is my training set. How can I alter the code above to make that happen?