Scikit hmm 分数返回负值

1 投票
1 回答
2183 浏览
提问于 2025-04-17 23:16

我尝试运行来自 http://scikit-learn.org/stable/modules/hmm.html 的示例代码:

import numpy as np
from sklearn import hmm

startprob = np.array([0.6, 0.3, 0.1])
transmat = np.array([[0.7, 0.2, 0.1], [0.3, 0.5, 0.2], [0.3, 0.3, 0.4]])
means = np.array([[0.0, 0.0], [3.0, -3.0], [5.0, 10.0]])
covars = np.tile(np.identity(2), (3, 1, 1))
model = hmm.GaussianHMM(3, "full", startprob, transmat)
model.means_ = means
model.covars_ = covars
X, Z = model.sample(150)

model2 = hmm.GaussianHMM(3, "full")
model2.fit([X])

然后我计算了在这个模型下观察到的X的对数概率:

print (model2.score(X))

我本来期待结果在0到1之间,但却得到了一个非常低的负值。比如上面的例子,得到了-554.979039475。我不太明白这是什么意思。

请问有人能给我点建议吗?

根据文档:
score(obs):计算在模型下的对数概率
返回值:观察到的对数似然性。

scklearn hmm.score 文档

1 个回答

4

对数概率就是概率的对数。在这里,概率是

>>> np.exp(-554.979039475)
9.4550881914378009e-242

撰写回答