KNN관련하여 코딩을 하다가 SyntaxError가 발생하여 질문을 드립니다...
조회수 338회
KNN관련하여 코딩을 하다가 SyntaxError가 발생하여 질문을 드립니다... 어떻게 해결하면 될까요?
def compute_distance(self, X_test, dist_metric='dot'):
if dist_metric=='dot':
sim = np.matmul(X_test, self.X_train.T)
dists = -sim
elif dist_metric=='l2':
n_test = X_test.shape[0]
#여기서 SyntaxError: invalid character in identifier가 발생하는데 왜 에러가 생기는지 잘 모르겠습니다. (n_test = X_test.shape[0])
n_train = self.X_train.shape[0]
dists = np.sqrt(np.tile(np.sum(np.square(self.X_train), axis=1), (n_test, 1)) + np.tile(np.sum(np.square(X_test), axis=1), (n_train, 1)).T - 2 * np.matmul(X_test, self.X_trai.T)
else:
raise KeyError("Distance metrics currently supported: \'l2\' and \'dot\'")
return dists
댓글 입력