In this method, the dataset is divided randomly into two parts: a training and testing set. Generally, this ratio is 2:1, which means 2/3 for training and 1/3 for testing. We can also split it into different ratios, such as 6:4, 7:3, and 8:2:
# partition data into training and testing set
from sklearn.model_selection import train_test_split
# split train and test set
feature_train, feature_test, target_train, target_test = train_test_split(features, target, test_size=0.3, random_state=1)
In the preceding example, test_size=0.3 represents 30% for the testing set and 70% for the training set. train_test_split() splits the dataset into 7:3.