numpy.random.seed()的用途是什么? [英] What is the use of numpy.random.seed() Does it make any difference?

查看:600
本文介绍了numpy.random.seed()的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为入场券"的数据集.

I have a dataset named "admissions".

我正在尝试对一个简单的数据集进行保留验证.为了对数据集的索引进行置换,我使用以下命令:

I am trying to carry out holdout validation on a simple dataset. In order to carry out permutation on the index of the dataset, I use the following command:

import numpy as np
np.random.permutation(admissions.index)

在排列之前是否需要使用np.random.seed()?如果是这样,那么np.random.seed(number)中的数字为什么代表什么?

Do I need to use np.random.seed() before the permutation? If so, then why and what does the number in np.random.seed(number)represent?

推荐答案

您无需在随机排列之前初始化种子,因为已经为您设置了种子. 根据 RandomState的文档:

You don't need to initialize the seed before the random permutation, because this is already set for you. According to the documentation of RandomState:

参数:
种子:{None,int,array_like},可选 随机种子初始化伪随机数生成器.可以是 整数,任意长度的整数的数组(或其他序列),或者 无(默认).如果seed为None,则RandomState将尝试读取 来自/dev/urandom(或Windows类似物)的数据(如果有)或种子 否则从时钟开始.

Parameters:
seed : {None, int, array_like}, optional Random seed initializing the pseudo-random number generator. Can be an integer, an array (or other sequence) of integers of any length, or None (the default). If seed is None, then RandomState will try to read data from /dev/urandom (or the Windows analogue) if available or seed from the clock otherwise.

种子的概念与随机数的产生有关.您可以在此处了解更多信息.

The concept of seed is relevant for the generation of random numbers. You can read more about it here.

要将此答案与对您的问题的评论(来自JohnColeman)集成在一起,我想提及此示例:

To integrate this answer with a comment (from JohnColeman) to your question, I want to mention this example:

>>> numpy.random.seed(0)
>>> numpy.random.permutation(4)
array([2, 3, 1, 0])
>>> numpy.random.seed(0)
>>> numpy.random.permutation(4)
array([2, 3, 1, 0])

这篇关于numpy.random.seed()的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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