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."
评论列表
文章目录