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)
1from sklearn.model_selection import train_test_split
2X_train, X_test, y_train, y_test = train_test_split(
3 X, y, test_size=0.33, 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]
1from sklearn.model_selection import train_test_split
2
3X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
1 import numpy as np
2 from sklearn.model_selection import train_test_split
3
4
5X_train, X_test, y_train, y_test = train_test_split(
6 X, y, test_size=0.33, random_state=42
7)
1from sklearn.linear_model import LinearRegression
2
3rl = LinearRegression().fit(X, y)
4rl.fit(X, y) #We can fit model to dataset in this way too
5