Coding a Hidden Markov Model in Python
Welcome to our tutorial for developing and using a Hidden Markov model (HMM)! This repository offers a notebook to build your own HMM (along with an answer key), a quick intro to the relevant Python fundamentals, and all the training data you'll need for your model. It also includes slides exploring the basic topics covered (markov assumptions, conditional probabilities, uses of HMMs).
These materials were developed jointly by Sara Carioscia and Dylan Taylor as part of a workshop series organized by Agara Bio, a community bio lab at Johns Hopkins.
If you need an introduction or refresher to basic Python, start by launching the Intro to Python notebook. For a more detailed introduction, you can also check out two other notebooks we made for a similar purpose here.
When you're ready, we suggest starting with the HMM Building notebook and working through it on your own. You can always refer to the "key" notebook in that same directory if you get stuck.
To use the resources as Jupyter Notebooks, git clone
the repository on your local machine and then launch each notebook from the command line via jupyter notebook notebookname
. Your changes to the notebook will be automatically saved, so feel free to add additional code or markdown cells as are helpful for you.
To launch these resources in Google Colab (see notebook here for an overview), git clone
this repository on your local machine. Then, open a new Google Colab document (similar to how you would open a Google Doc or Google Sheet); File --> open notebook --> upload, and choose your notebook. These changes will not be saved, unless you download the notebook back out of Google Colab and place it in your local repository.
To access through Binder (which doesn't require any download of Python or jupyter notebook), please click the Binder link. Note that if you refresh the page, your work will be lost; we recommend exporting your page if you wish to save it.
Feel free to use this if you have a group of students who might benefit - or if you're a curious biologist yourself! Reach out to Sara ([email protected]) or Dylan ([email protected]) if you have any questions or suggestions. If there's a feature or other update you'd like added, please create an issue directly on GitHub.