I'm using the GuassianHMM from the python package hmmlearn and after fitting the hmm to the data the predictions that are done in one batch

hm = GaussianHMM(n_components=3,random_state=19)
preds = hm.predict(myData)

seem to be different then the ones that i am doing on a rolling window

low_bound = 0
rolling_preds =[]

for i in range(20,myData):
     low_bound = low_bound +1 

#Creating a window of size 20 and sliding it over the data

preds = preds[20:]
#making the batch predictions the same size as the rolling predictions

len(rolling_preds) == len(preds)
>>>> True

Counter(rolling_preds == preds)
>>>> Counter({True:7000,False:1000})

The reason I am doing rolling predictions is because I'm trying to simulate how the model would behave in a live system scenario,and as suspected the performance drops significantly.

I tried a different window approach without the low_bound variable, so the window would just expand indefinitely the results are very similar however.

What is quite interesting is when i fit the hmm with the sequence parameter

hm.fit(myData,[sequence_length for i in range len(data)])*

  • the sequence_length has to be evenly divisible by the length of your data

and then feed the predictions this way

low_bound = 0 
rolling_preds = []
for i in range(sequence_length,len(myData)):
    low_bound = low_bound +1 

When using this approach where the length of the data I am predicting is equal to the sequence length that the model was trained on the hmm just gives wildly wrong predictions.

for example if the numper of components was 3 this approach would give estimations of really large numbers (-48994798,48994798) or just 10

any help is greatly appreciated.


The Vitrebi algorithm uses all the data for prediction, that's why the predictions change when doing them on a rolling basis, possible fix is to re fit the hmm on a window basis.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.