【问题标题】:Can I set a random state for the Complement Naive Bayes?我可以为 Complement Naive Bayes 设置随机状态吗?
【发布时间】:2021-12-19 04:35:24
【问题描述】:

我注意到我可以在随机森林分类器中设置随机状态,但不能在 Complement Naive Bayes 中设置。我得到错误

TypeError: __init__() got an unexpected keyword argument 'random_state'

我认为这是因为 naive_bayes 正在计算每个类别的概率?

from sklearn.naive_bayes import ComplementNB
model= ComplementNB(random_state=0)

【问题讨论】:

    标签: scikit-learn naivebayes


    【解决方案1】:

    这是因为模型不做任何需要随机初始化或生成的事情。有关详细信息,请参阅source code

    如果您想从自己这边重置该行中的随机种子,您可以执行以下操作。

    import numpy as np
    import random
    
    def set_random_seed(seed=0):
      np.random.seed(seed)
      random.seed(seed)
    

    然后你可以在调用你的模型之前重置随机种子

    from sklearn.naive_bayes import ComplementNB
    
    set_random_seed(0)
    model= ComplementNB()
    

    阅读更多关于mechanism of Complement Naive Bayes的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-25
      • 2014-06-18
      • 2015-03-31
      • 2021-09-15
      • 2021-09-28
      • 1970-01-01
      • 2016-05-07
      • 2014-04-08
      相关资源
      最近更新 更多