sklearn.utils.validation.check_random_state(seed)

参数:

————————————————————————————————————

 seed:若seed为None,返回RandomState singleton(np.random)。

            若seed 为int,返回一个新的randomState实例,由这个新的seed产生。 

            若seed为randomState实例则直接返回它本身。

流程

———————————————————————————————————— 

def check_random_state(seed): 

"""Turn seed into a np.random.RandomState instance    
If seed is None, return the RandomState singleton used by np.random.    
If seed is an int, return a new RandomState instance seeded with seed.    
If seed is already a RandomState instance, return it.    
Otherwise raise ValueError.    
"""
#seed为None或者为np.random则返回np.random.mtrand._rand 。
if seed is None or seed is np.random:
     return np.random.mtrand._rand

#seed为numbers.Intergral或np.integer实例。
if isinstance(seed, (numbers.Integral, np.integer)):
     return np.random.RandomState(seed)
     
#若为np.random.RandomState则返回自身。


if isinstance(seed, np.random.RandomState):
     return seed 


#若不为上述情况则报错。


raise ValueError('%r cannot be used to seed a numpy.random.RandomState'    
' instance' % seed)

转载于:https://my.oschina.net/u/2336323/blog/479411

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值