【问题标题】:Scipy.stats / Why can't I get the value for randint?Scipy.stats / 为什么我不能得到 randint 的值?
【发布时间】:2022-11-28 06:06:29
【问题描述】:

你好

这是我的代码:

from scipy.stats import randint
param_distributions = {'n_estimators': randint(1, 5),
                       'max_depth': randint(5, 10)}

param_distributions["max_depth"]结果是:

{'n_estimators': <scipy.stats._distn_infrastructure.rv_frozen 对象 在 0x7f05f1b05210>, 'max_depth': <scipy.stats._distn_infrastructure.rv_frozen 对象位于 0x7f05f1b053d0>}

为什么我不能得到这个值?

【问题讨论】:

    标签: scipy


    【解决方案1】:

    randint(low, high) 将返回一个分发对象。要从中采样,您需要使用 rvs() 方法:

    from scipy.stats import randint
    param_distributions = {'n_estimators': randint(1, 5).rvs(),
                           'max_depth': randint(5, 10).rvs()}
    
    >>> param_distributions
    
    {'n_estimators': 3, 'max_depth': 9}
    

    docs 列出了所有可用的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多