为什么我的sklearn.model_selection.train_test_split()
每次运行代码时都返回相同的X_train
、X_test
、y_train
、y_test
样本,即使我设置了shuffle=True
,也没有手动定义种子值?
我是这样打印样本的:
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, random_state = 100, shuffle=True)print (y_test)
回答:
train_test_split
中的random_state
控制样本的状态(https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html):
控制在应用分割之前对数据应用的洗牌。传递一个整数以在多次函数调用中获得可重现的输出
要获得不同的结果,只需删除该参数即可。