1from sklearn.model_selection import train_test_split
2
3X = df.drop(['target'],axis=1).values # independant features
4y = df['target'].values # dependant variable
5
6# Choose your test size to split between training and testing sets:
7X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
1import numpy as np
2from sklearn.model_selection import train_test_split
3
4X, y = np.arange(10).reshape((5, 2)), range(5)
5
6X_train, X_test, y_train, y_test = train_test_split(
7 X, y, test_size=0.33, random_state=42)
8
9X_train
10# array([[4, 5],
11# [0, 1],
12# [6, 7]])
13
14y_train
15# [2, 0, 3]
16
17X_test
18# array([[2, 3],
19# [8, 9]])
20
21y_test
22# [1, 4]
1train=df.sample(frac=0.8,random_state=200) #random state is a seed value
2test=df.drop(train.index)
1from sklearn.model_selection import train_test_split
2
3
4y = df.pop('output')
5X = df
6
7X_train,X_test,y_train,y_test = train_test_split(X.index,y,test_size=0.2)
8X.iloc[X_train] # return dataframe train
9
1from sklearn.model_selection import train_test_split
2
3train, test = train_test_split(df, test_size=0.2)
4
1from sklearn.model_selection import train_test_split
2xTrain, xTest, yTrain, yTest = train_test_split(x, y, test_size = 0.2, random_state = 0)