classifiers.py 文件源码

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

项目:data-analysis 作者: ymohanty 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号