Когда я попробовал примеры MaxentClassifier из http://nltk.googlecode.com/svn/trunk/doc/howto/classify.html,, я получил ошибку ниже:
Grad eval # 0
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
classifier = MaxentClassifier.train(train)
File "C:\Python27\lib\site-packages\nltk\classify\maxent.py", line 323, in train
gaussian_prior_sigma, **cutoffs)
File "C:\Python27\lib\site-packages\nltk\classify\maxent.py", line 1456, in train_maxent_classifier_with_scipy
model.fit(algorithm=algorithm)
File "C:\Python27\lib\site-packages\scipy\maxentropy\maxentropy.py", line 1026, in fit
return model.fit(self, self.K, algorithm)
File "C:\Python27\lib\site-packages\scipy\maxentropy\maxentropy.py", line 226, in fit
callback=callback)
File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line 636, in fmin_cg
gfk = myfprime(x0)
File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line 176, in function_wrapper
return function(x, *args)
File "C:\Python27\lib\site-packages\scipy\maxentropy\maxentropy.py", line 420, in grad
G = self.expectations() - self.K
ValueError: operands could not be broadcast together with shapes (54) (12)
Код Python:
train = [(dict(a=1,b=1,c=1), 'y'),
(dict(a=1,b=1,c=1), 'x'),
(dict(a=1,b=1,c=0), 'y'),
(dict(a=0,b=1,c=1), 'x'),
(dict(a=0,b=1,c=1), 'y'),
(dict(a=0,b=0,c=1), 'y'),
(dict(a=0,b=1,c=0), 'x'),
(dict(a=0,b=0,c=0), 'x')]
test = [(dict(a=1,b=0,c=1)), # unseen
(dict(a=1,b=0,c=0)), # unseen
(dict(a=0,b=1,c=1)), # seen 3 times, labels=y,y,x
(dict(a=0,b=1,c=0)) # seen 1 time, label=x
]
classifier = MaxentClassifier.train(train)
Но я не знаю, как это решить.
Помоги мне, спасибо!