1
2
3
4
5
6
7
8
9
10
11
|
from sklearn.model_selection import train_test_split
def train_test_val_split(x,y, train_ratio = 0.8,validation_ratio = 0.1,test_ratio = 0.1,random_state=0):
# random_state for reproduction
# shuffle must be 'True'
[x_train, x_test, y_train, y_test] = train_test_split(
x, y, test_size=validation_ratio+test_ratio, random_state=random_state, shuffle=True)
[x_val, x_test, y_val, y_test] = train_test_split(
x_test, y_test, test_size=test_ratio/(test_ratio + validation_ratio), random_state=random_state)
return x_train,y_train, x_test, y_test, x_val, y_val
|