@@ -723,7 +723,7 @@ def _unnormalized_transform(self, X):
723723
724724 return doc_topic_distr
725725
726- def transform (self , X ):
726+ def transform (self , X , * , normalize = True ):
727727 """Transform data X according to the fitted model.
728728
729729 .. versionchanged:: 0.18
@@ -734,6 +734,9 @@ def transform(self, X):
734734 X : {array-like, sparse matrix} of shape (n_samples, n_features)
735735 Document word matrix.
736736
737+ normalize : bool, default=True
738+ Whether to normalize the document topic distribution.
739+
737740 Returns
738741 -------
739742 doc_topic_distr : ndarray of shape (n_samples, n_components)
@@ -744,9 +747,35 @@ def transform(self, X):
744747 X , reset_n_features = False , whom = "LatentDirichletAllocation.transform"
745748 )
746749 doc_topic_distr = self ._unnormalized_transform (X )
747- doc_topic_distr /= doc_topic_distr .sum (axis = 1 )[:, np .newaxis ]
750+ if normalize :
751+ doc_topic_distr /= doc_topic_distr .sum (axis = 1 )[:, np .newaxis ]
748752 return doc_topic_distr
749753
754+ def fit_transform (self , X , y = None , * , normalize = True ):
755+ """
756+ Fit to data, then transform it.
757+
758+ Fits transformer to `X` and `y` and returns a transformed version of `X`.
759+
760+ Parameters
761+ ----------
762+ X : array-like of shape (n_samples, n_features)
763+ Input samples.
764+
765+ y : array-like of shape (n_samples,) or (n_samples, n_outputs), \
766+ default=None
767+ Target values (None for unsupervised transformations).
768+
769+ normalize : bool, default=True
770+ Whether to normalize the document topic distribution in `transform`.
771+
772+ Returns
773+ -------
774+ X_new : ndarray array of shape (n_samples, n_features_new)
775+ Transformed array.
776+ """
777+ return self .fit (X , y ).transform (X , normalize = normalize )
778+
750779 def _approx_bound (self , X , doc_topic_distr , sub_sampling ):
751780 """Estimate the variational bound.
752781
0 commit comments