Fork me on GitHub

sklearn.hmm.MultinomialHMM

class sklearn.hmm.MultinomialHMM(n_components=1, startprob=None, transmat=None, startprob_prior=None, transmat_prior=None, algorithm='viterbi', random_state=None, n_iter=10, thresh=0.01, params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', init_params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')

Hidden Markov Model with multinomial (discrete) emissions

See also

GaussianHMM
HMM with Gaussian emissions

Examples

>>> from sklearn.hmm import MultinomialHMM
>>> MultinomialHMM(n_components=2)
...                             
MultinomialHMM(algorithm='viterbi',...

Attributes

n_components int Number of states in the model.
n_symbols int Number of possible symbols emitted by the model (in the observations).
transmat array, shape (n_components, n_components) Matrix of transition probabilities between states.
startprob array, shape (‘n_components`,) Initial state occupation distribution.
emissionprob array, shape (‘n_components`, ‘n_symbols`) Probability of emitting a given symbol when in each state.
random_state: RandomState or an int seed (0 by default)   A random number generator instance
n_iter int, optional Number of iterations to perform.
thresh float, optional Convergence threshold.
params string, optional Controls which parameters are updated in the training process. Can contain any combination of ‘s’ for startprob, ‘t’ for transmat, ‘e’ for emmissionprob. Defaults to all parameters.
init_params string, optional Controls which parameters are initialized prior to training. Can contain any combination of ‘s’ for startprob, ‘t’ for transmat, ‘e’ for emmissionprob. Defaults to all parameters.

Methods

decode(obs[, algorithm]) Find most likely state sequence corresponding to obs.
eval(*args, **kwargs) DEPRECATED: HMM.eval was renamed to HMM.score_samples in 0.14 and will be removed in 0.16.
fit(obs, **kwargs) Estimate model parameters.
get_params([deep]) Get parameters for this estimator.
predict(obs[, algorithm]) Find most likely state sequence corresponding to obs.
predict_proba(obs) Compute the posterior probability for each state in the model
sample([n, random_state]) Generate random samples from the model.
score(obs) Compute the log probability under the model.
score_samples(obs) Compute the log probability under the model and compute posteriors.
set_params(**params) Set the parameters of this estimator.
__init__(n_components=1, startprob=None, transmat=None, startprob_prior=None, transmat_prior=None, algorithm='viterbi', random_state=None, n_iter=10, thresh=0.01, params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', init_params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')

Create a hidden Markov model with multinomial emissions.

Parameters :

n_components : int

Number of states.

algorithm

decoder algorithm

decode(obs, algorithm='viterbi')

Find most likely state sequence corresponding to obs. Uses the selected algorithm for decoding.

Parameters :

obs : array_like, shape (n, n_features)

Sequence of n_features-dimensional data points. Each row corresponds to a single point in the sequence.

algorithm : string, one of the decoder_algorithms

decoder algorithm to be used

Returns :

logprob : float

Log probability of the maximum likelihood path through the HMM

state_sequence : array_like, shape (n,)

Index of the most likely states for each observation

See also

score_samples
Compute the log probability under the model and posteriors.
score
Compute the log probability under the model.
emissionprob_

Emission probability distribution for each state.

eval(*args, **kwargs)

DEPRECATED: HMM.eval was renamed to HMM.score_samples in 0.14 and will be removed in 0.16.

fit(obs, **kwargs)

Estimate model parameters.

An initialization step is performed before entering the EM algorithm. If you want to avoid this step, pass proper init_params keyword argument to estimator’s constructor.

Parameters :

obs : list

List of array-like observation sequences, each of which has shape (n_i, n_features), where n_i is the length of the i_th observation.

get_params(deep=True)

Get parameters for this estimator.

Parameters :

deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns :

params : mapping of string to any

Parameter names mapped to their values.

predict(obs, algorithm='viterbi')

Find most likely state sequence corresponding to obs.

Parameters :

obs : array_like, shape (n, n_features)

Sequence of n_features-dimensional data points. Each row corresponds to a single point in the sequence.

Returns :

state_sequence : array_like, shape (n,)

Index of the most likely states for each observation

predict_proba(obs)

Compute the posterior probability for each state in the model

Parameters :

obs : array_like, shape (n, n_features)

Sequence of n_features-dimensional data points. Each row corresponds to a single point in the sequence.

Returns :

T : array-like, shape (n, n_components)

Returns the probability of the sample for each state in the model.

sample(n=1, random_state=None)

Generate random samples from the model.

Parameters :

n : int

Number of samples to generate.

random_state: RandomState or an int seed (0 by default) :

A random number generator instance. If None is given, the object’s random_state is used

Returns :

(obs, hidden_states) :

obs : array_like, length n List of samples

hidden_states : array_like, length n List of hidden states

score(obs)

Compute the log probability under the model.

Parameters :

obs : array_like, shape (n, n_features)

Sequence of n_features-dimensional data points. Each row corresponds to a single data point.

Returns :

logprob : float

Log likelihood of the obs.

See also

score_samples
Compute the log probability under the model and posteriors
decode
Find most likely state sequence corresponding to a obs
score_samples(obs)

Compute the log probability under the model and compute posteriors.

Parameters :

obs : array_like, shape (n, n_features)

Sequence of n_features-dimensional data points. Each row corresponds to a single point in the sequence.

Returns :

logprob : float

Log likelihood of the sequence obs.

posteriors : array_like, shape (n, n_components)

Posterior probabilities of each state for each observation

See also

score
Compute the log probability under the model
decode
Find most likely state sequence corresponding to a obs
set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :
startprob_

Mixing startprob for each state.

transmat_

Matrix of transition probabilities.

Previous
Next