python - sklearn.model_selection.train_test_split 示例中的 "random-state"是什么?

标签 python numpy machine-learning random scikit-learn

<分区>

谁能给我解释一下 random_state 在下面的例子中是什么意思?

import numpy as np
from sklearn.model_selection import train_test_split
X, y = np.arange(10).reshape((5, 2)), range(5)


X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.33, random_state=42) 

为什么硬编码为 42?

最佳答案

这不是很明显吗? 42 是 Answer to the Ultimate Question of Life, the Universe, and Everything .

严肃地说,random_state 只是为随机生成器设置一个种子,因此您的训练测试拆分始终是确定性的。如果不设置种子,每次都不一样。

Relevant documentation :

random_state : int, RandomState instance or None, optional (default=None)
If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

关于python - sklearn.model_selection.train_test_split 示例中的 "random-state"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49147774/

相关文章:

python - 对 pandas 数据框进行迭代和平均

python - 在 TF/Numpy 中进行这种串联的优雅方法是什么?

python - 整数 numpy 数组乘以 float

python - 如何引导 numpy 数组的最里面的数组?

Python sklearn : why are my neighbors. KNeighborsRegressor 预测 "perfect"?

使用 subprocess.Popen() 在 python 脚本中设置 PYTHONPATH 失败

python - SQL Server 2016查询导致死锁?

javascript - Brain.js - 无法从 json 文件加载网络

python - 梯度下降 ANN - MATLAB 正在做什么而我没有做什么?

python librosa 包 - 如何从频谱中提取音频