Closed Vishu92 closed 1 year ago
Hi @Vishu92 , I notice that your error message reads AttributeError: 'GaussianHMM' object has no attribute 'k'
, but in line 100 of my FSHMM.py, the def init() has included a k variable:
def __init__(self, n_components=1, covariance_type='diag',
min_covar=1e-3,
startprob_prior=1.0, transmat_prior=1.0,
means_prior=0, means_weight=0,
covars_prior=1e-2, covars_weight=1,
algorithm="viterbi", random_state=None,
n_iter=10, tol=1e-2, verbose=False,
params="stmc", init_params="stmc",
implementation="log",
### NEW ###
k=50):
Did you do import FSHMM
and save it in the correct directory? And if you've imported as I suggested, did you try instantiating the model with FSHMM.GaussianHMM()
instead?
Hi Waikho, Thank you for replying. Does the FSHMM need to be saved with the hmmlearn library? I have saved it in the same folder as my current directory. Please correct me if this is not the case. I am pasting my code below. Please let me know if you find any issue there.
import pandas as pd
import numpy as np
import hmmlearn
import FSHMM
n_components = 2
k = 50
fsshm_model = FSHMM.GaussianHMM(n_components = n_components,
covariance_type = "diag",
n_iter = 10000, random_state = 42,
k=k) #k is the cost
fsshm_model.fit(X = X)
where X is an array if shape (500,2)
I was using Colab. I saved FSHMM.py in the same directory as my notebook, not with the hmmlearn library. It may be just a path issue, i.e., you may need to save it in a directory where you can import without interfering with the hmmlearn library.
And for the fit statement, I just did fsshm_model.fit(X_train)
. Then the fitted model should be able to run the methods provided in FSHMM.py, such as fsshm_model.score(X_test)
, fsshm_model.monitor_.converged
@Vishu92
I too have saved the FSHMM.py file in the same directory as my notebook. I will check at my side and confirm once I discover the issue. Thanks. @waikho
I couldn't figure out the reason for the error. I have removed the k from the initialization and put it constant. Closing the issue. Many thanks for the code. @waikho
I took further look into your error message. My read is "AttributeError: 'GaussianHMM' object has no attribute 'k'" means you're trying to get an attribute "k" from the GaussianHMM object. I'm not sure if your code is trying to get the same "k", but in line 102 of FSHMM.py, you'll see that the value of "k" in the GaussianHMM object can be returned by self.k_factor_
Good luck and feel free to discuss more! @Vishu92
Hi @waikho Thanks for taking the effort to solve the issue. I am not trying to get the attribute from the object. I am initiating the module and calling model.fit() with the training data. I have spend considerable time to understand the issue but failed to do so. Happy to discuss further and solve it. @waikho
Hi Waikho, thank you for updating the code. I am facing issue while running the code. Please find below the error message.
Below is my code for running the code.
where, X = an array with shape (550, 5)
Can you please assist?