Last active
October 7, 2016 00:30
-
-
Save romainecarter/65d2d635e0c91a1c309a760ebac78c4e to your computer and use it in GitHub Desktop.
Example Hidden Markov Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[1 0 0 0 0 1]\n" | |
] | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"from hmmlearn import hmm\n", | |
"\n", | |
"model = hmm.MultinomialHMM(n_components=2) # create model with two states\n", | |
"model.startprob_ = np.array([0.6, 0.4]) # start_probability\n", | |
"model.n_features = 3 # observations\n", | |
"model.transmat_ = np.array([[0.7, 0.3], [0.4, 0.6]]) # transition_probability\n", | |
"model.emissionprob_ = np.array([[0.1, 0.4, 0.5], [0.6, 0.3, 0.1]]) # emission_probability\n", | |
"\n", | |
"print(model.predict(np.column_stack([[0, 2, 1, 1, 2, 0]])))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3.0 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment