RoderickOxen
RoderickOxen

Reputation: 21

Function that returns a hidden state given a set of observations using Python Hmmlearn Multinomial

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.

Upvotes: 2

Views: 352

Answers (0)

Related Questions