6

I am currently working with Scikit Learn and have been running into the following issue while trying to train a Gaussian HMM:

File "/Library/Python/2.7/site-packages/sklearn/hmm.py", line 443, in fit

self._do_mstep(stats, self.params)

File "/Library/Python/2.7/site-packages/sklearn/hmm.py", line 798, in _do_mstep

super(GaussianHMM, self)._do_mstep(stats, params)

File "/Library/Python/2.7/site-packages/sklearn/hmm.py", line 580, in _do_mstep

np.maximum(self.startprob_prior - 1.0 + stats['start'], 1e-20))

File "/Library/Python/2.7/site-packages/sklearn/hmm.py", line 476, in _set_startprob

raise ValueError('startprob must sum to 1.0')

ValueError: startprob must sum to 1.0

If I eliminate some of the features (fewer than 13 features per observation), it still works. I have checked that all of the input is valid and consists of only 2d-arrays of numpy.float64s for each training example. Any ideas on what is going wrong? Thanks!

Community
  • 1
  • 1
Jay Hack
  • 139
  • 3
  • 10

5 Answers5

4

I fixed the issue by setting the params attribute to a set of all unique values in my training set.

param=set(train.ravel())
model=hmm.GaussianHMM(n_components=6, covariance_type="full", n_iter=100,params=param)

train is my list of numpy arrays used to fit the model.

The initial parameters are set to a string of all ascii characters.

Fahad Sarfraz
  • 1,265
  • 9
  • 19
0

I had the same problem. I could solve it by adjusting the number of hidden state of the model. It seems that, depending on the available data and the number of states, the model is not able to fit correcrtly

Oswin
  • 539
  • 1
  • 6
  • 20
0

The model is just having trouble fitting the data. You could through a bit of code around it to keep trying. You may want to add a bit to get it to stop after x many tries. If that still doesn't work, change the number of hidden states.

while True:
  try:
    model.fit([data])
    break
Clayton
  • 3
  • 3
0

I was just struggling with the same problem while using GaussianHMM. I figured out that the problem was coming from the fact that I was feeding the classifier integer values and it required float values instead. I tried using float numbers when I realized that MultinomialHMM only accepts continuos values, and it worked!

user823743
  • 2,152
  • 3
  • 21
  • 31
0

Looks like there is some issue with hmmlearn package. The following worked for me

  • Uninstall pip version of hmmlearn: pip uninstall hmmlearn
  • Get the source of hmmlearn from here.
  • Remove -1.0 from here and here
  • Install using python setup.py install

This should work. There was an issue raised with the hmmlearn but did not get required attention. link

Credits - https://github.com/wblgers/hmm_speech_recognition_demo

thechargedneutron
  • 802
  • 1
  • 9
  • 24