I am asking you a question because a SyntaxError occurred while coding related to KNN...

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

I am asking you a question because a SyntaxError occurred while coding related to KNN... How can I solve this problem?

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 occurs here, but I'm not sure why the error occurs. (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

syntax-error

2022-09-20 08:57

1 Answers

I tried copying and pasting the source code of the question into the vcode

An invisible blank character was immediately preceded by n_test.


2022-09-20 08:57

If you have any answers or tips


© 2022 pinfo. All rights reserved.