Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

python - What is the use of numpy.random.seed() Does it make any difference?

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)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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.

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])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...