Scikit-learn Gaussianhmm Valueerror: Input Must Be A Square Array
I am working with scikit-learn's GaussianHMM and am getting the following ValueError when I try to fit it to some observations. here is code that demonstrates the error: >>&g
Solution 1:
You have to fit with a list, see official examples:
>>> gmm.fit([arr])
GaussianHMM(algorithm='viterbi', covariance_type='diag', covars_prior=0.01,
covars_weight=1,
init_params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
means_prior=None, means_weight=0, n_components=1, n_iter=10,
params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
random_state=None, startprob=None, startprob_prior=1.0, thresh=0.01,
transmat=None, transmat_prior=1.0)
>>> gmm.n_features
3>>> gmm.n_components
1
Solution 2:
According to the docs, gmm.fit(obs)
expects obs
to be a list of array-like objects:
obs : list
List ofarray-like observation sequences (shape (n_i, n_features)).
Therefore, try:
import numpy as np
from sklearn.hmm import GaussianHMM
arr = np.matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
gmm = GaussianHMM()
print(gmm.fit([arr]))
Hidden markov models (HMMs) are no longer supported by sklearn.
Post a Comment for "Scikit-learn Gaussianhmm Valueerror: Input Must Be A Square Array"