0

I am trying to use the predict_proba() function on my HMM, but I get an error which i do not fully understand. First of all I create my model as follows:

model = hmm.GaussianHMM(n_components=vocab_size, covariance_type="full")
model.start_prob_ = np.array(frequency_list)
model.transmat_ = np.array(transitions)

integer_array = integer_array.reshape(-1,1)
model.fit(integer_array)

With integer_list being my list of integers which is my training data. If I then try to run the predict_proba function as follows, I get the following error:

base._BaseHMM.predict_proba(integer_array, None)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-54-62c5bedf3e8a> in <module>
----> 1 base._BaseHMM.predict_proba(integer_list, None)

D:\Anaconda\lib\site-packages\hmmlearn\base.py in predict_proba(self, X, lengths)
    390             State-membership probabilities for each sample from ``X``.
    391         """
--> 392         _, posteriors = self.score_samples(X, lengths)
    393         return posteriors
    394 

AttributeError: 'np.array' object has no attribute 'score_samples'

Does anyone know how to solve this issue? I already tried to convert my array to a list, but that gives a similar error.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
WibeMan
  • 91
  • 7
  • 1
    Can you show completely code? – han Jun 16 '20 at 13:33
  • what parts of the code would you like to see? the integer list looks as follows: [1, 2, 3, 4, 5, 6, 7, 8, 2, 9, 10, 11, 6, 12, 13, 14, 15, 16, 17, 16, 8, 18, 19, 20, 21, 6, 6, 22, 4, 23, 8, 24, 25, 2, 26, 27, 5, 19, 7, 4, 10] – WibeMan Jun 16 '20 at 14:19
  • Nevermind I fixed the issue, I should have used model.predict_proba() , thanks anyway – WibeMan Jun 16 '20 at 15:08

1 Answers1

1

The call should be

model.predict_proba(integer_array, None)

which is syntactic sugar for

base._BaseHMM.predict_proba(model, integer_array, None)

Note model being passed as self parameter.

Jon Nordby
  • 5,494
  • 1
  • 21
  • 50