What stable Python library can I use to implement Hidden Markov Models? I need it to be reasonably well documented, because I've never really used this model before.

Alternatively, is there a more direct approach to performing a time-series analysis on a data-set using HMM?

  • $\begingroup$ There's an alternative implementation of sklearn HMM that appears to have active contributions that can be found here: github.com/hmmlearn/hmmlearn I haven't used it before, so I can't speak to how good it is, but, looking at the examples, it appears to be fairly straightforward. $\endgroup$
    – Kyle.
    Oct 16, 2015 at 18:46

5 Answers 5


For another alternative approach, you can take a look at the PyMC library. There is a good gist created by Fonnesbeck which walks you through the HMM creation.

And if you become really eager about the PyMC, there is an awesome open-source book about Bayesian Modeling. It does not explicitly describe Hidden Markov Processes, but it gives a very good tutorial on the library itself with plenty of examples.


As an update on this question, I believe the accepted answer is not the best as of 2017.

As suggested in comments by Kyle, hmmlearn is currently the library to go with for HMMs in Python.

Several reasons for this:

  • The up-to-date documentation, that is very detailed and includes tutorial

  • The _BaseHMM class from which custom subclass can inherit for implementing HMM variants

  • Compatible with the last versions of Python 3.5+

  • Intuitive use

Opposite to this, the ghmm library does not support Python 3.x according to the current documentation. Most of the documentation pages have been generated in 2006. It does not seem at first glance a library of choice...

Edit: Still valid in 2018.


pomegranate library has support for HMM and the documentation is really helpful. After trying with many hmm libraries in python, I find this to be quite good.


For an alternative approach, perhaps even to help foster understanding, you will probably find some utility in doing some analysis via R. Simple time series based tutorials abound for [wannabe] quants that should provide a bootstrap. Part 1, Part 2, Part 3, Part 4. These provide sources for data generation/intake as well as manipulation, allowing you to bypass much of the work to be able to see the actual HMM methods at work. There are direct analogues to the Python implementations.

As a side note, for a more theoretical introduction, perhaps Rabiner might provide some insights


The ghmm library might be the one which you are looking for.

As it is said in their website:

It is used for implementing efficient data structures and algorithms for basic and extended HMMs with discrete and continuous emissions. It comes with Python wrappers which provide a much nicer interface and added functionality.

It also has a nice documentation and a step-by-step tutorial for getting your feet wet.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.