Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tweetopic/btm.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ def transform(self, X: Union[spr.spmatrix, ArrayLike]) -> np.ndarray:
doc_unique_words=doc_unique_words,
doc_unique_word_counts=doc_unique_word_counts,
)

def predict(self, X: Union[spr.spmatrix, ArrayLike]) -> np.ndarray:
"""Predicts cluster labels for a set of documents. Mainly exists for
compatibility with density estimators in sklearn.

Parameters
----------
X: array-like or sparse matrix of shape (n_samples, n_features)
Document-term matrix.

Returns
-------
array of shape (n_samples,)
Cluster label for each document.

Raises
------
NotFittedException
If the model is not fitted, an exception will be raised
"""
return np.argmax(self.transform(X), axis=1)

def fit_transform(
self,
Expand Down