File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
sklearn/decomposition/tests Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -286,10 +286,20 @@ def test_perplexity_input_format():
286
286
def test_lda_score_perplexity ():
287
287
# Test the relationship between LDA score and perplexity
288
288
n_topics , X = _build_sparse_mtx ()
289
- lda = LatentDirichletAllocation (n_topics = n_topics , max_iter = 10 , random_state = 0 )
289
+ lda = LatentDirichletAllocation (n_topics = n_topics , max_iter = 10 ,
290
+ random_state = 0 )
290
291
distr = lda .fit_transform (X )
291
292
perplexity_1 = lda .perplexity (X , distr , sub_sampling = False )
292
293
293
294
score = lda .score (X )
294
295
perplexity_2 = np .exp (- 1. * (score / np .sum (X .data )))
295
296
assert_almost_equal (perplexity_1 , perplexity_2 )
297
+
298
+
299
+ def test_lda_empty_docs ():
300
+ """Test LDA on empty document (all-zero rows)."""
301
+ Z = np .zeros ((5 , 4 ))
302
+ for X in [Z , csr_matrix (Z )]:
303
+ lda = LatentDirichletAllocation (max_iter = 750 ).fit (X )
304
+ assert_almost_equal (lda .components_ .sum (axis = 0 ),
305
+ np .ones (lda .components_ .shape [1 ]))
You can’t perform that action at this time.
0 commit comments