我正在使用scikit-learn的train_test_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.1, random_state=42)
当我记录
y_train
中唯一元素的数量时:logger.info(len(set(y_train)))
我会在重复运行代码时得到不同的值(即使没有更改任何代码)。 我原以为random_state
可以确保分割的确定性。
如何确保每次都分割相同的数据?