-2

我正在尝试运行隐藏的马尔可夫模型,但是拟合功能无法正常工作。

代码:

import numpy as np
from hmmlearn import hmm

X1 = [[0.5], [1.0], [-1.0], [0.42], [0.24]]
X2 = [[2.4], [4.2], [0.5], [-0.24]]

X = np.concatenate([X1, X2])
lengths = [len(X1), len(X2)]

hmm.GaussianHMM(n_components=3).fit(X, lengths) 

我收到此错误消息:

TypeError                                 Traceback (most recent call last)
<ipython-input-16-cdfada1be202> in <module>()
      8 lengths = [len(X1), len(X2)]
      9 
---> 10 hmm.GaussianHMM(n_components=3).fit(X, lengths)

TypeError: fit() takes 2 positional arguments but 3 were given
4

2 回答 2

0

请检查hmmlearn您拥有的版本并进行更新。参数在较新的lengths版本中可用,如此处所示

http://hmmlearn.readthedocs.io/en/latest/api.html#hmmlearn.hmm.GaussianHMM.fit

然后尝试做(正如@Harpal 建议的那样):

hmm.GaussianHMM(n_components=3).fit(X, lengths=lengths)
于 2018-03-29T14:14:16.820 回答
0

hmmlearn0.1.1可以重现这个错误,

但是,如果您pip install hmmlearn==0.2.0在虚拟环境中执行 a 并跟进hmm.GaussianHMM(n_components=3).fit(X, lengths=lengths).

事情应该会很好!

于 2018-04-17T21:42:08.327 回答