1 train_test_split
netclass edited this page 3 years ago

train_test_split

导入方法

from sklearn.model_selection import train_test_split

函数与参数解释

X_train,X_test, y_train, y_test =train_test_split(train_data,train_target,test_size=0.4, random_state=0)

  • train_data:所要划分的样本特征集
  • train_target:所要划分的样本结果
  • test_size:样本占比,如果是整数的话就是样本的数量
  • random_state:是随机数的种子。
  • 随机数种子:其实就是该组随机数的编号,在需要重复试验的时候,保证得到一组一样的随机数。

调用实例

X_train, X_test, y_train, y_test = train_test_split(data, target, test_size=0.3)