Skip to content

Commit

Permalink
use hasattr to check if model has been fitted
Browse files Browse the repository at this point in the history
  • Loading branch information
rbroc committed Mar 20, 2024
1 parent 4fcab17 commit 21944dd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions turftopic/models/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def __init__(
self.feature_importance = feature_importance
self.n_reduce_to = n_reduce_to
self.reduction_method = reduction_method
self.components_ = None

def _merge_agglomerative(self, n_reduce_to: int) -> np.ndarray:
n_topics = self.components_.shape[0]
Expand Down Expand Up @@ -328,7 +327,7 @@ def fit_transform_dynamic(
if embeddings is None:
embeddings = self.encoder_.encode(raw_documents)
for i_timebin in np.arange(len(self.time_bin_edges) - 1):
if self.components_ is not None:
if hasattr(self, 'components_'):
doc_topic_matrix = label_binarize(
self.labels_, classes=self.classes_
)
Expand Down
3 changes: 1 addition & 2 deletions turftopic/models/gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def __init__(
self.gmm_ = make_pipeline(dimensionality_reduction, mixture)
else:
self.gmm_ = mixture
self.components_ = None

def fit_transform(
self, raw_documents, y=None, embeddings: Optional[np.ndarray] = None
Expand Down Expand Up @@ -163,7 +162,7 @@ def fit_transform_dynamic(
bins: Union[int, list[datetime]] = 10,
):
time_labels, self.time_bin_edges = bin_timestamps(timestamps, bins)
if self.components_ is not None:
if hasattr(self, 'components_'):
doc_topic_matrix = self.transform(
raw_documents, embeddings=embeddings
)
Expand Down

0 comments on commit 21944dd

Please sign in to comment.