Polynomial.py 文件源码

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

项目:nimo 作者: wolfram2012 项目源码 文件源码
def trainClassifer(self,labels,vectors,ilog=None):
        '''
        Train the polynomial.  Do not call this function
        manually, instead call the train function on the super
        class.
        '''
        #build matrix
        matrix = []
        for each in vectors:
            if len(each) != 2:
                raise ValueError("ERROR: Vector length=%d.  Polynomial2D only predicts for vectors of length 2."%len(each))
            x,y = each
            matrix.append(self.buildRow(x,y))

        matrix = array(matrix)
        labels = array(labels)

        x,resids,rank,s = lstsq(matrix,labels)

        self.x = x
        self.resids = resids
        self.rank = rank
        self.s = s

        if rank != matrix.shape[1]:
            print "WARNING: Polynomial is not fully constrained."
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号