default split of train_test_split code example
Example 1: train test split sklearn
from sklearn.model_selection import train_test_split
X = df.drop(['target'],axis=1).values # independant features
y = df['target'].values # dependant variable
# Choose your test size to split between training and testing sets:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
Example 2: code for test and train 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.33, random_state=42)
Example 3: test_size
This parameter decides the size of the data that has to be split as the test dataset. This is given as a fraction. For example, if you pass 0.5 as the value, the dataset will be split 50% as the test dataset. If you’re specifying this parameter, you can ignore the next parameter.
Example 4: train-test split code in pandas
df_permutated = df.sample(frac=1)
train_size = 0.8
train_end = int(len(df_permutated)*train_size)
df_train = df_permutated[:train_end]
df_test = df_permutated[train_end:]