train_test_split() in python

The train_test_split() function is used to randomly divide the sample data into the training set and the test set. Of course, it can also be divided into artificial slices.

Advantages: divide data randomly and objectively, reducing human factors

Full template:

train_X,test_X,train_y,test_y = train_test_split(train_data,train_target,test_size=0.3,random_state=5)

Parameter explanation:

train_data: sample data to be divided

train_target: the result of the sample data to be divided (label)

test_size: the ratio of test data to sample data, if integer, the sample size

random_state: Set the random number seed to ensure the same random number every time. If it is 0 or not filled, the data will be different every time

————————————————
Copyright statement: This article is the original article of the CSDN blogger "No matter how the future is beautiful", it follows the CC 4.0 BY-SA copyright agreement. Please attach the original source for reprinting. Links and this statement.
Original link: https://blog.csdn.net/qq_36523839/article/details/80280771

Guess you like

Origin blog.csdn.net/banxiaCSDN/article/details/112989197