Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scikit Learn Gaussian HMM: ValueError: startprob must sum to 1.0

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!

like image 366
Jay Hack Avatar asked Oct 03 '22 23:10

Jay Hack


1 Answers

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.

like image 130
Fahad Sarfraz Avatar answered Oct 13 '22 10:10

Fahad Sarfraz