svm.py 文件源码

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

项目:NTHU-Machine-Learning 作者: YuChunLOL 项目源码 文件源码
def _postcompute_biases(self):
        """ Post-computed biases for non-boundary training examples (support vectors) when training is done.
            This is for estimating sample mean and sample std of biases.
            For a good learning result, sample std of biases should be small.
        """
        def _b(i):
            if self.enable_kernel_cache:
                return self.train_y[i] - np.dot(self.alpha*self.train_y, self.kernel_cache[i])
            else:
                return self.train_y[i] - self._f(self.train_X[i])

        I_non_boundary = np.where(np.logical_and(self.alpha > 0, self.alpha < self.C) == True)[0].tolist()

        if len(I_non_boundary):
            biases = np.vectorize(_b)(I_non_boundary)
            self.b_mean = np.mean(biases)
            self.b_std = np.sqrt(np.sum((biases - self.b_mean)**2) / (len(biases) - 1))
            self.postcomputed_biases[I_non_boundary] = biases
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号