2

I have been stuck on a problem regarding a python function using Multinomial HMM (from hmmlearn) for a while...

The general idea is for the HMM be capable of finding the hidden state (0, 1 or 2) given a set of observations where each is composed by 4 arrays of 0s and 1s. Example:

#For a set of observations: 

c1 = [0,1,1,0,0,0,1]
c2 = [0,0,0,0,1,1,0]
c3 = [0,0,0,1,1,0,1]
c4 = [0,0,0,0,1,1,1]

observation = [c1 , c2, c3, c4]


#Which state will be the next hidden state
state = 1 or state = 2 or state = 3

Currently my code is the following:

#Observations
c1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0]
c2 = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,1,1,0,0,0,1,0,0,0,1,0]
c3 = [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0]
c4 = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0,1,1,1,0,0,1,1,1,0]

#Train
model = hmm.MultinomialHMM(n_components=3, verbose=True)
model.n_features_=2
model.fit([c1,c2,c3,c4])


#Predict
pred = model.predict([[0],[1],[0],[0]])
print(pred)

The issue is that this outpus an array (for example: [1 2 0 1]) and my goal is for it to return just either 0,1 or 2... ([1]).

Any feedback, ideas or help are well received, Thank you in advance.

  • I never used this specific library, but in `tensorflow` you can predict batches of data, and it looks like you are passing 4 observation as a batch and you get 4 predicted states. Does it apply here? – Pietro Mar 30 '21 at 21:09
  • @Pietro I never used tensorflow, but I will look it up. Regarding the question, yes the idea is to provide an observation that is an aggregation of 4 different criteria (c1, c2, c3 and c4) and in the end find the one hidden state. I could be providing the wrong input type – RoderickOxen Mar 30 '21 at 21:19

0 Answers0