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