1. 分类并返回对应类的输出
def fizz_buzz_encode(i):
if i % 15 == 0: return 3
elif i % 5 == 0: return 2
elif i % 3 == 0: return 1
else: return 0
def fizz_buzz_decode(i, prediction):
return [str(i), "fizz", "buzz", "fizzbuzz"][prediction]
2. 将数字转化为二进制的array
NUM_DIGITS = 10
def binary_encode(i, num_digits):
return np.array([i >> d & 1 for d in range(num_digits)])
3. 寻找到数值最小的位置的序号
distance = np.sum(np.abs(self.Xtr - X[i,:]), axis = 1)
min_index = np.argmin(distance)
Ypred[i] = self.ytr[min_index]