0

Im working along with this documentation, but I can't figure out how to extract the sequence of predictions from the test data.

I have trained the model with .fit(X_train), but the following:

unseen_hidden_states = model.predict(X_test)

Returns an array:

[2 1 1 ..., 3 3 3]

Which I dont know how to interpret or how to extract the predicted sequence from

redress
  • 1,399
  • 4
  • 20
  • 34

1 Answers1

1

As stated in the documentation:

The inferred optimal hidden states can be obtained by calling the predict method.

A results such as [2, 1, 1, 3] for a sequence X_test = [x1, x2, x3, x4] means that x1 has most probably be generated by the hidden state 2, x2 by the hidden state 1, x3 by the hidden state 1, and x4 by the hidden state 3.

If you want to read about the algorithm behind this, you can look for the Viterbi algorithm.

EDIT:

If you are looking for computing the likelihood of the data with respect to the model, you should have a look to the functions score, _compute_log_likelihood, or score_samples.

UeliDeSchwert
  • 1,146
  • 10
  • 23
Eskapp
  • 3,419
  • 2
  • 22
  • 39
  • How do I get the actual value, as opposed to just hidden state its likely generated by? – redress Oct 04 '17 at 17:01
  • @redress Check my edit. "Actual value" is quite unclear... I think you mean the likelihood of the data w.r.t. the model – Eskapp Oct 04 '17 at 18:34
  • If I’m predicting the stock market, how do I get the predicted price. That’s what I mean by actual value – redress Oct 04 '17 at 18:37
  • @redress Your question seems similar to this one: https://stackoverflow.com/questions/45258306/predicting-future-emissions-from-fitted-hmm-model Please let me know if there is something you do not understand in that answer :) – Eskapp Oct 04 '17 at 18:41
  • `score_samples` returns ```(-734802478.69610989, array([[ 0., 0., 1., 0.], [ 0., 0., 0., 1.], [ 0., 0., 0., 1.], ..., [ 0., 0., 0., 1.], [ 0., 0., 0., 1.], [ 0., 0., 0., 1.]])) pred``` – redress Oct 05 '17 at 02:03
  • This still doesnt tell me the predicted price at each interval, only the hidden state – redress Oct 05 '17 at 02:03