Skip to content

predict_mhmm()

predict_mhmm() assigns each sequence to its most likely mixture cluster (hard classification).

Function Usage

python
predict_mhmm(
    model,
    newdata=None
)

seqHMM Parameter Mapping

SequenzoseqHMM
modelFitted mhmm object
newdataNew stslist
Return valuemost_probable_cluster()

Entry Parameters

ParameterRequiredTypeDescription
modelMHMMFitted model from build_mhmm() + fit_mhmm().
newdataSequenceData / NoneSequences to classify. Default: training data.

What It Returns

A NumPy array of cluster indices (0-based), one value per sequence.

For probabilistic membership, use posterior_probs_mhmm().

Example

python
from sequenzo.seqhmm import build_mhmm, fit_mhmm, predict_mhmm

mhmm = build_mhmm(seq, n_clusters=3, n_states=4, random_state=42)
mhmm = fit_mhmm(mhmm)

labels = predict_mhmm(mhmm)
print(labels)  # e.g. [0, 2, 1, 0, ...]

R Counterpart

  • Closest R function: seqHMM most_probable_cluster()
  • Mapping note: Returns integer cluster indices; map to cluster_names on the model if you set them at build time.

Notes

  • Requires a fitted model.
  • Hard assignments ignore uncertainty; prefer posterior_probs_mhmm() when sequences sit near cluster boundaries.

Authors

Code: Yuqi Liang

Documentation: Yuqi Liang

References

Helske, S., & Helske, J. (2019). Mixture hidden Markov models for sequence data: The seqHMM package in R. Journal of Statistical Software, 88(3), 1–32.