0

I have sequence of 3 observations and I have three such sequence of observations. There are three hidden states. I am using GaussianHMM of HMMlearn library.

state_machine = GaussianHMM(n_components=3, covariance_type="full", n_iter=1000) state_machine.fit(np.stack(np.split(X, 3), axis=1))

For one feature, the data is as below

    [ 119.01182027 87.03816453 100.50549142 130.54392216 98.57366214
    98.62378821 102.27561523 102.84749098 114.64554409]

I am splitting observations as below. Because my aim is to predict the next observation. And keeping observations as it is would produce '9 X 3'_compute_log_likelihood. So I need it in form '3 X 3' so that I can predict next observation.

    np.stack(np.split(X, 3), axis=1)
    [[ 119.01182027 130.54392216 102.27561523]
    [ 87.03816453 98.57366214 102.84749098]
    [ 100.50549142 98.62378821 114.64554409]]

But I am getting state transition matrix as

    [[ 0. 0. 1.]
    [ 0. 0. 0.]
    [ 0. 1. 0.]]

Also for "state_machine.predict(test_r)" I am getting error as "ValueError: rows of transmat_ must sum to 1.0 (got [ 1. 0. 1.])".

But for other feature, the data as below

    [ 98.37498104 98.45256112 94.2081596 108.67319206 92.9055614
    98.27020888 90.16851055 105.08352667 102.24313963]

    np.stack(np.split(X, 3), axis=1)
    [[ 98.37498104 108.67319206 90.16851055]
    [ 98.45256112 92.9055614 105.08352667]
    [ 94.2081596 98.27020888 102.24313963]]

I am getting below state transition matrix.

    [[` 5.17868641e-03 2.58836952e-03 9.92232944e-01]
    [ 9.95633499e-01 7.42556661e-04 3.62394458e-03]
    [ 3.40871039e-01 3.07185528e-03 6.56057106e-01]]

For "state_machine.predict(test_r)" I am getting "Hidden state: [2]".

Please suggest me the possible reason behind this and solution.

Thanks.

1000er
  • 1
  • As a general remark, the sequences are too short and too few for proper training. 3 sequences of length 3 for 3 states. HMM is a statistical model providing a statistical representation, therefore you need enough samples for all the computed probabilities to be statistically significant. – Eskapp Nov 27 '17 at 17:10
  • Ok, I will check with more number of sequences of same length. I will share the result. Thanks @Eskapp – 1000er Nov 28 '17 at 18:31

0 Answers0