4

I have two training sets (observations of known class) representing the two possible states in my data. I would like to have hmmlearn estimate the start, transition, and emission probabilities from these two training sets.

My data is a list of values between 0-1. I have already split the data into to coarse groups 'A' and 'B' using a conservative threshold. I want to use an HMM to refine the points at which my data changes state.

For a single train/test sequence X I would do this:

X = [0, 1, 1, 1, 0.1, 0.015, 0.01, 0.001, 0.005, 0.001, 0.2, 1, 0.8, 1, 1, 0.3]
states = ["A", "B"]

#Fit model, auto set probabilities
model = hmm.MultinomialHMM(n_components=2, covariance_type="full")
model.fit([X])

#Predict states
Z = model.predict(X)

#Predict a sequence of hidden states based on visible states
logprob, state = model.decode(X, algorithm="viterbi")
print "States:", ", ".join(map(lambda x: states[x], state))
>>> States: A, B, B, B, B, A, A, A, A, A, B, B, B, B, B, B

I would like to know how to train state A and state B separately.

Sergei Lebedev
  • 2,659
  • 20
  • 23
Adatar
  • 41
  • 1
  • 4

1 Answers1

1

The fit method takes a list of observation sequences. In your example, assume your X is denoted X1, and the other group denoted X2, you would simply run:

model.fit([X1,X2])
approxiblue
  • 6,982
  • 16
  • 51
  • 59
aikramer2
  • 1,283
  • 12
  • 9
  • 5
    Just for completeness: this won't work in `hmmlearn` 0.2.0. See "Working with multiple sequences" in the [tutorial](http://hmmlearn.readthedocs.org/en/latest/tutorial.html#training-hmm-parameters-and-inferring-the-hidden-states). – Sergei Lebedev Mar 06 '16 at 20:06