示例#1
0
"""
HMM model with K=4 possible states and observations conditional to the chain are normally distributed.
"""

K = 4
seed = 1995
max_iter = 100
log_interval = 10
verbose = 1

clf = HMM(K=K, max_iter=max_iter, verbose=verbose, log_interval=log_interval)
clf = clf.fit(df_train.values)

print("Log-likelihood at convergence on train %.3f" % clf.lc)
print("Log-likelihood on test %.3f" %
      clf._get_lc(df_test.values, clf.predict(df_test.values)))

fig, ax = plt.subplots(nrows=1, ncols=1)
plot_clusters(df_train.values, clf.mu, clf.labels, ax=ax)

widths = np.zeros(K)
heights = np.zeros(K)
angles = np.zeros(K)

for j in range(K):
    widths[j], heights[j], angles[j] = extract_params_ellipse(clf.Sigma[j])

plot_ellipses(clf.mu,
              2 * 1.65 * widths,
              2 * 1.65 * heights,
              alpha=0.35,