0

I am working on sign language recognition on GitHub available here https://github.com/udacity/AIND-Recognize.

I have a problem on a rubric of Model selection. When I run this cell there

import warnings 
from hmmlearn.hmm import GaussianHMM

def train_a_word(word, num_hidden_states, features):
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    training = asl.build_training(features)  
    X, lengths = training.get_word_Xlengths(word)
    model = GaussianHMM(n_components=num_hidden_states, n_iter=1000).fit(X, lengths)
    logL = model.score(X, lengths)
    return model, logL

demoword = 'BOOK'
model, logL = train_a_word(demoword, 3 , features=features_ground)
print("Number of states trained in model for {} is {}".format(demoword, model.n_components))
print("logL = {}".format(logL))

I have this error:

TypeError Traceback (most recent call last) in () 12  13 demoword = 'BOOK' ---> 14 model, 
  logL = train_a_word(demoword, 3 , features=features_ground) 15 print("Number of states 
  trained in model for {} is {}".format(demoword, model.n_components)) 
  16 print("logL = {}".format(logL)) in train_a_word(word, num_hidden_states, features) 
  7 training = asl.build_training(features) 8 X, lengths = training.get_word_Xlengths(word) 
  ----> 9 model = GaussianHMM(n_components=num_hidden_states, n_iter=1000).fit(X, lengths) 
  10 logL = model.score(X, lengths) 11 return model, logL

TypeError: fit() takes 2 positional arguments but 3 were given

And I can't figure it out and I want to mention that we were not supposed to modify this cell.

thewaywewere
  • 8,128
  • 11
  • 41
  • 46

2 Answers2

0

The problem is caused by your line

model = GaussianHMM(n_components=num_hidden_states, n_iter=1000).fit(X, lengths)

To fix the problem:
Change fit(X, lengths) for fit(X, lengths=lengths)

See the hmmlearn documentation
A possibly helpful answer about arguments

codeiscool
  • 119
  • 2
  • 7
  • hello @codeiscool , i changed `fit(X, lengths)` for `fit(X, lengths=lengths)` like you proposed and then i got this new error : fit() got an unexpected keyword argument 'lengths' – Stephens Talla Jun 17 '17 at 12:51
0

Try updating your dependencies, especially hmmlearn and scikit-learn. You could find the complete project here for future references: https://github.com/llSeedll/Udacity-AIND/tree/master/Project%204%20-%20ASLRecognizer

Eddy Adams
  • 21
  • 3