我有一个 nX2 维数组,并且定义了一些 HMM 模型。现在,对于存在的每个 HMM 模型,我正在尝试计算 nx2 数组中存在的每个值的对数似然值。为此,我使用 hmmlearn 包中的 score 函数
链接:https ://hmmlearn.readthedocs.io/en/latest/api.html#hmmlearn.base._BaseHMM.score
作为参考,这些是我编写的代码:
定义 HMM 模型之一:
HMMmodel = hmm.GaussianHMM(n_components=3, covariance_type="full", n_iter=10)
HMMmodel.fit(Sdata2)
HMMpredict = HMMmodel.predict(Sdata2)
HMMmodel.transmat_
然后,与 Score 函数一起使用的数据集:
[[-1.72914138 -1.63633714]
[-1.72914138 -1.63633714]
[-1.69620469 -1.63633714]
...
[-1.72226929 -1.63633714]
[-1.71539655 -1.63633714]
[-1.72914138 -1.63633714]]
查找分数的代码:
score1 = list()
score2 = list()
score3 = list()
score4 = list()
for x in np.nditer(Sdata3):
score1.append(HMMmodel.score(x))
score2.append(HMMmodel2.score(x))
score3.append(HMMmodel3.score(x))
score4.append(HMMmodel4.score(x))
正是在这一点上遇到了错误:
ValueError: Expected 2D array, got scalar array instead:
array=-1.7291413774395343.
我在这个网站上阅读了一些类似的问题,并尝试使用 (-1,1) 和 (1,-1) 重塑我的数组,但它会产生相同的错误。
任何解决错误的技术将不胜感激。谢谢!