We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
手动实现向量化的norm,应该通用性更好一些, 是否可行,请指正: def predict_leon(self, X): dist = np.power(X - self.X_train, self.p).sum(axis=1) dist = np.power(dist, 1 / self.p) knn = self.y_train[np.argsort(dist)[:self.n]]
# 统计 count_pairs = Counter(knn) max_count = sorted(count_pairs.items(), key=lambda x: x[1])[-1][0] return max_count
The text was updated successfully, but these errors were encountered:
同样是这个问题, 原代码中 max_count = sorted(count_pairs.items(), key=lambda x: x[1])[-1][0] 可以直接用 max_count=count_pairs.most_common(1)[0][0] 代替
Sorry, something went wrong.
No branches or pull requests
手动实现向量化的norm,应该通用性更好一些, 是否可行,请指正:
def predict_leon(self, X):
dist = np.power(X - self.X_train, self.p).sum(axis=1)
dist = np.power(dist, 1 / self.p)
knn = self.y_train[np.argsort(dist)[:self.n]]
The text was updated successfully, but these errors were encountered: