什么是“随机状态"?在sklearn.model_selection.train_test_split示例中? [英] What is "random-state" in sklearn.model_selection.train_test_split example?

查看:168
本文介绍了什么是“随机状态"?在sklearn.model_selection.train_test_split示例中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是机器学习的新手,我正在通过 sklearn

I am really new to machine learning,i was going through some example on sklearn

在下面的示例中,有人可以解释一下随机状态"的真正含义吗?

Can someone explain me what really "Random-state" means in below example

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

list(y)


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

X_train

y_train

X_test

y_test

为什么将其硬编码为42?

推荐答案

那不是很明显吗? 42是关于生命,宇宙和万物的终极问题的答案

Isn't that obvious? 42 is the Answer to the Ultimate Question of Life, the Universe, and Everything.

要特别注意的是,random_state只是为随机生成器设置了一个种子,因此您的火车测试拆分始终是确定性的.如果您不设置种子,则每次都不同.

On a serious note, random_state simply sets a seed to the random generator, so that your train-test splits are always deterministic. If you don't set a seed, it is different each time.

相关文档 :

random_state : intRandomState实例或None,可选 (默认= None)
如果int,则random_state是随机变量使用的种子 数字生成器;如果RandomState实例,则random_state是随机变量 数字生成器;如果None,则随机数生成器为 np.random使用的RandomState实例.

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.

这篇关于什么是“随机状态"?在sklearn.model_selection.train_test_split示例中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆