【问题标题】:Evaluating the model as you train with scikit's LatentDirichletAllocation class在使用 scikit 的 LatentDirichletAllocation 类进行训练时评估模型
【发布时间】:2017-01-07 15:00:33
【问题描述】:

我在scikit-learn中试验LatentDirichletAllocation() classevaluate_every参数有如下描述。

多久评估一次困惑。仅用于 fit 方法。将其设置为 0 或负数根本不评估训练中的困惑。 评估困惑度可以帮助您检查训练中的收敛性 过程,但它也会增加总的训练时间。评估 每次迭代中的困惑可能会增加训练时间 两次。

我将此参数设置为 2(默认为 0)并看到训练时间增加,但我似乎无法在任何地方找到困惑值。这些结果是否已保存,还是仅由模型用于确定何时停止?我希望使用困惑度值来衡量我的模型的进度和学习曲线。

【问题讨论】:

    标签: machine-learning scikit-learn unsupervised-learning lda


    【解决方案1】:

    根据source,它与perp_tol 参数一起用于评估收敛性,并且不会在迭代之间保存:

    for i in xrange(max_iter):
    
        # ...
    
        # check perplexity
        if evaluate_every > 0 and (i + 1) % evaluate_every == 0:
            doc_topics_distr, _ = self._e_step(X, cal_sstats=False,
                                                random_init=False,
                                                parallel=parallel)
            bound = self.perplexity(X, doc_topics_distr,
                                    sub_sampling=False)
            if self.verbose:
                print('iteration: %d, perplexity: %.4f'
                        % (i + 1, bound))
    
            if last_bound and abs(last_bound - bound) < self.perp_tol:
                break
            last_bound = bound
        self.n_iter_ += 1
    

    请注意,您可以通过 (1) 将行 self.saved_bounds = [] 添加到 __init__ 方法 (2) 将 self.bounds.append(bound) 添加到上面,轻松地调整现有源代码,如下所示:

    if last_bound and abs(last_bound - bound) < self.perp_tol:
        break
    last_bound = bound
    self.bounds.append(bound)
    

    根据您保存更新类的位置,您还必须调整文件顶部的导入以引用 scikit-learn 中的完整模块路径。

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 1970-01-01
      • 2019-03-20
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      相关资源
      最近更新 更多