First of all, HMM
is deprecated in sklearn
. You need to check out https://github.com/hmmlearn/hmmlearn, which is Hidden Markov Models in Python, with scikit-learn like API
BTW, The problem you ask seems like a bug. When you set emissionprob_
, the _set_emissionprob
is called. This tries re-normalize
by calling normalize(emissionprob)
:
if not np.alltrue(emissionprob):
normalize(emissionprob)
However, this code has two problems:
- dose not set axis properly.
- not in-place even though the document says that.
So modified as
if not np.alltrue(emissionprob):
normalize(emissionprob, 1) # added axis term
and
def normalize(A, axis=None):
A += EPS
Asum = A.sum(axis)
if axis and A.ndim > 1:
# Make sure we don't divide by zero.
Asum[Asum == 0] = 1
shape = list(A.shape)
shape[axis] = 1
Asum.shape = shape
A /= Asum # this is true in-place, it was `return A / Asum` <<= here