title: How to map hidden states to their corresponding categories after decoding in hmmlearn (Hidden Markov Model)?
body: <p>I would like to predict hidden states using Hidden Markov Model (decoding problem). The data is categorical. The hidden states include Hungry, Rest, Exercise and Movie. The observation set include Food, Home, Outdoor &amp; Recreation and Arts &amp; Entertainment. My program is first to train the HMM based on the observation sequence (Baum-Welch algorithm). And then I do the decoding (Viterbi algorithm) to predict the hidden state sequence.</p>
  
  <p>My question is that how I can map the result (non-negative integers) to their corresponding categories like Hungry or Rest. Because of the non-deterministic property of the training algorithm , the parameters are different for every training of the same data. Therefore the hidden state sequence is different every time if I do the map like the following code. </p>
  
  <p>The code is as follows:</p>
  
  <pre><code>from __future__ import division
  import numpy as np
  from hmmlearn import hmm
  
  states = ["Hungry", "Rest", "Exercise", "Movie"]
  n_states = len(states)
  
  observations = ["Food", "Home", "Outdoor &amp; Recreation", "Arts &amp; Entertainment"]
  
  # The number in this sequence is the index of observation
  category_sequence = [1, 0, 1, 2, 1, 3, 1]
  Location = np.array([category_sequence]).T
  model = hmm.MultinomialHMM(n_components=n_states).fit(Location)
  
  logprob, result = model.decode(Location)
  print "Category:", ", ".join(map(lambda x: observations[x], Location.T[0]))
  print "Intent:", ", ".join(map(lambda x: states[x], result))
  </code></pre>