Back to models
Detector

GaussianHMM

Hidden Markov Model with Gaussian emissions.

Quickstart

python
from sktime.detection.hmm_learn.gaussian import GaussianHMM

estimator = GaussianHMM(n_components: int=1, covariance_type: str='diag', min_covar: float=0.001, startprob_prior: float=1.0, transmat_prior: float=1.0, means_prior: float=0, means_weight: float=0, covars_prior: float=0.01, covars_weight: float=1, algorithm: str='viterbi', random_state: float=None, n_iter: int=10, tol: float=0.01, verbose: bool=False, params: str='stmc', init_params: str='stmc', implementation: str='log')

Parameters(14)

n_componentsint
Number of states
covariance_type{“spherical”, “diag”, “full”, “tied”}, optional

The type of covariance parameters to use:

  • “spherical” — each state uses a single variance value that

    applies to all features.

min_covarfloat, optional
Floor on the diagonal of the covariance matrix to prevent overfitting. Defaults to 1e-3.
means_prior, means_weightarray, shape (n_mix,), optional

Mean and precision of the Normal prior distribution for means_.

covars_prior, covars_weightarray, shape (n_mix,), optional

Parameters of the prior distribution for the covariance matrix covars_. If covariance_type is “spherical” or “diag” the prior is the inverse gamma distribution, otherwise — the inverse Wishart distribution.

startprob_priorarray, shape (n_components,), optional

Parameters of the Dirichlet prior distribution for startprob_.

transmat_priorarray, shape (n_components, n_components), optional

Parameters of the Dirichlet prior distribution for each row of the transition probabilities transmat_.

algorithm{“viterbi”, “map”}, optional
Decoder algorithm.
random_state: RandomState or an int seed, optional
A random number generator instance.
n_iterint, optional
Maximum number of iterations to perform.
tolfloat, optional
Convergence threshold. EM will stop if the gain in log-likelihood is below this value.
verbosebool, optional

Whether per-iteration convergence reports are printed to sys.stderr. Convergence can also be diagnosed using the monitor_ attribute.

params, init_paramsstring, optional

The parameters that get updated during (params) or initialized before (init_params) the training. Can contain any combination of ‘s’ for startprob, ‘t’ for transmat, ‘m’ for means and ‘c’ for covars. Defaults to all parameters.

implementation: string, optional
Determines if the forward-backward algorithm is implemented with logarithms (“log”), or using scaling (“scaling”). The default is to use logarithms for backwards compatibility.

Examples

>>> from sktime.detection.hmm_learn import GaussianHMM
>>> from sktime.detection.datagen import piecewise_normal
>>> data = piecewise_normal (
... means = [2, 4, 1 ], lengths = [10, 35, 40 ], random_state = 7
... ). reshape ((- 1, 1))
>>> model = GaussianHMM (algorithm = 'viterbi', n_components = 2)
>>> model = model. fit (data)
>>> labeled_data = model. predict (data)