def train(self, datadict, labels=None):
'''
Runs the classifier training using the dictionary of label, features
@param datadict: dictonary of label, features
@param labels: (optional) list of labels. If given the order of labels is used from this list.
'''
# Set labels from data dict
if labels is None:
self.labels = datadict.keys()
else:
self.labels = labels
# Train the GMM for BoF computation
if self.model.gmm is None:
print >> sys.stderr, 'Model not trained yet.'
self.model.train(datadict, self.labels)
print >> sys.stderr,'Computing',self.model.__class__.__name__,'...'
# Parse dictionary into BoF representations and labels
bofs, bofl = self._parse_dict(datadict, self.labels)
#Create Multinomial Bayes
print >> sys.stderr,'Training Multinomial Bayes ...'
self.bay = bayes.MultinomialNB(alpha=0.5, fit_prior=False)
self.bay.fit(bofs, bofl)
return
评论列表
文章目录