Skip to content

Commit

Permalink
Correct the model-selection example
Browse files Browse the repository at this point in the history
  • Loading branch information
blckmaxima authored and anntzer committed Jan 9, 2023
1 parent 6739227 commit 725d4a4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/plot_gaussian_model_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
"""
import numpy as np
import matplotlib.pyplot as plt
from sklearn.utils import check_random_state

from hmmlearn.hmm import GaussianHMM

rs = check_random_state(546)
# %%
# Our model to generate sample data from:
model = GaussianHMM(4, init_params="")
Expand All @@ -30,8 +33,8 @@
model.means_ = np.array([[-2.5], [0], [2.5], [5.]])
model.covars_ = np.sqrt([[0.25], [0.25], [0.25], [0.25]])

X, _ = model.sample(2000)
lengths = [200] * 10
X, _ = model.sample(1000, random_state=rs)
lengths = [X.shape[0]]

# %%
# Search over various n_components and examine the
Expand All @@ -46,7 +49,7 @@
best_ll = None
best_model = None
for i in range(10):
h = GaussianHMM(n, n_iter=200)
h = GaussianHMM(n, n_iter=200, tol=1e-4, random_state=rs)
h.fit(X)
score = h.score(X)
if not best_ll or best_ll < best_ll:
Expand Down

0 comments on commit 725d4a4

Please sign in to comment.