'How do I solve the ValueError: startprob_ must sum to 1 (got nan) for the hmmlearn package?

I am modeling countries economies based on some different features. I have the model working for all countries except Canada where I get the error above. I have looked at the input extensively, but it is not different than the other inputs.

Important to mention is that the startprobabilities do sum up to 1! The model is initialized the following way:

daily_change_prob = 0.10n_components = 2startprob_prior = tf.fill([n_components],daily_change_prob / (n_components - 1))startprob_prior= startprob_prior.numpy()startprob_prior[0] = 1 - daily_change_probtransmat_prior = tf.fill([n_components, n_components],daily_change_prob / (n_components - 1))transmat_prior = tf.linalg.set_diag(transmat_prior,tf.fill([n_components],1 - daily_change_prob))

I get the following warnings before the error, I think this has something to do with it:

RuntimeWarning: invalid value encountered in true_divideself.covars_ = c_n / c_dC:\Users\QG381YP\Anaconda3\lib\site-packages\hmmlearn\hmm.py:887: RuntimeWarning: divide by zero encountered in loglog_cur_weights = np.log(self.weights_[i_comp])

I hope one of you can help me!

I tried looking at the data, to see if there where any 0 or nan values which could lead to this error. Furthermore, I found online that the np.where should be removed and also tried this. Both did unfortunately not work for me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source