def build(self, A, categories, K=None):
'''Builds the classifier give the data points in A and the categories'''
# figure out how many categories there are and get the mapping (np.unique)
unique, mapping = np.unique(np.array(categories.T), return_inverse=True)
self.num_classes = len(unique)
self.num_features = A.shape[0]
self.categories = categories
# for each category i, build the set of exemplars
for i in range(self.num_classes):
if K is None:
self.exemplars.append(A[(mapping == i),:])
else:
codebook,codes = vq.kmeans(A[(mapping == i),:],K)
self.exemplars.append(codebook)
return
评论列表
文章目录