classifiers.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:bof-aed 作者: rgrzeszi 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号