2016-11-21 25 views
1

有對HMM模型的三個基本問題:如何使用sklearn HMM來計算觀測數據的可能性

  1. 鑑於模型參數和觀測數據,估計隱藏狀態的最優順序。
  2. 給定模型參數和觀測數據,計算數據的可能性。
  3. 僅給出觀察到的數據,估計模型參數。

問題1和問題3可以通過sklearn HMM tutorial來解決。但是,我們如何使用sklearn來解決問題2?

回答

2

使用score()函數。來自代碼:

def score(self, X, lengths=None): 
"""Compute the log probability under the model. 

    Parameters 
    ---------- 
    X : array-like, shape (n_samples, n_features) 
     Feature matrix of individual samples. 

    lengths : array-like of integers, shape (n_sequences,), optional 
     Lengths of the individual sequences in ``X``. The sum of 
     these should be ``n_samples``. 

    Returns 
    ------- 
    logprob : float 
     Log likelihood of ``X``.