项目作者: adrz

项目描述 :
Unsupervised clustering of sequences of arbitrary length using mixture of discrete-state markov models.
高级语言: Python
项目地址: git://github.com/adrz/py-mmm.git
创建时间: 2017-02-09T10:29:19Z
项目社区:https://github.com/adrz/py-mmm

开源协议:

下载


Overview

Unsupervised clustering of sequences of arbitrary length using mixture of discrete-state markov models.

For more informations about the model, see Chap 23 pp
Barber, David. Bayesian reasoning and machine learning. Cambridge University Press, 2012.
APA (available: http://web4.cs.ucl.ac.uk/staff/D.Barber/pmwiki/pmwik)

Installation

  1. $ git clone git@github.com:adrz/py-mmm.git
  2. $ cd py-mmm
  3. $ virtualenv -p python3 env
  4. $ source env/bin/activate
  5. $ pip install -r requirements.txt

Example of code

Clustering a mixted length sequences.
The number of states is 5, and the number of wished clusters is 3:

  1. from pymmm.mmm import MixtureMarkovChains
  2. import numpy as np
  3. model = MixtureMarkovChains(n_cluster=3)
  4. observations = [[0, 2, 2, 2, 4],
  5. [0, 1, 2, 4, 4, 4, 1, 1, 1],
  6. [0, 3, 2, 2, 2, 1, 1, 1],
  7. [0, 1, 2, 2, 2, 1, 1, 1],
  8. [0, 2, 2, 2, 2, 2, 1, 1, 1],
  9. [0, 1, 2, 2, 2, 1, 1, 1],
  10. [0, 3, 2, 2, 2, 4, 0, 1],
  11. [0, 1, 2, 1, 2, 0, 0, 0, 1]]
  12. model.fit(observations)
  13. z_training = model.predict(observations)
  14. observation_testing = [[0, 3, 2, 0, 0, 1, 1, 1],
  15. [0, 3, 2, 2, 2, 1, 1, 1],
  16. [0, 1, 1, 1, 2, 2, 1, 1]]
  17. z_testing = model.predict(observation_testing)
  18. # Posterior:training
  19. print('Posterior training')
  20. print(z_training)
  21. print('Label training')
  22. print(np.argmax(z_training, 0))
  23. print('Posterior testing')
  24. print(z_testing)
  25. print('Label testing')
  26. print(np.argmax(z_testing, 0))