Error in model prediction using hmmlearn
<p>Hi I have a dataframe test, I am trying to predict using a Gaussian HMM with hmmlearn.</p>

<p>When I do this:</p>

<pre><code>y = model.predict(test) 
y
</code></pre>

<p>I get the hmm working fine producing and array of states</p>

<p>however if i do this:</p>

<pre><code>for i in range(0,len(test)):
    y = model.predict(test[:i])
</code></pre>

<p>all I get is y being set to 1.</p>

<p>Can anyone help?</p>

<p>UPDATE</p>

<p>here is the code that does work iterating through</p>

<p>The training set was 0-249:</p>

<pre><code>for i in range(251,len(X)):
    test = X[:i]
    y = model.predict(test)
    print(y[len(y)-1])
</code></pre>

<p>HMM models sequences of observations. If you feed a single observation into <code>predict</code> (which does <a href="https://en.wikipedia.org/wiki/Viterbi_algorithm" rel="nofollow">Viterbi decoding</a> by default) you essentially reduce the prediction to the <code>argmax</code> over</p>

<pre><code>(model.startprob_ * model.predict_proba(test[i:i + 1])).argmax()
</code></pre>

<p>which can be dominated by <code>startprob_</code>, e.g. if <code>startprob = [10**-8, 1 - 10**-8]</code>. This could explain the all-ones behaviour you're seeing.</p>

python pandas numpy hmmlearn