昆仑山:眼中无形心中有穴之穴人合一

夫君子之行,静以修身,俭以养德;非澹泊无以明志,非宁静无以致远。夫学须静也,才须学也;非学无以广才,非志无以成学。怠慢则不能励精,险躁则不能冶性。年与时驰,意与岁去,遂成枯落,多不接世。悲守穷庐,将复何及!

 

统计学习方法[第3章 k近邻法 KNN](李航大神版)

手工实现

import math
from itertools import combinations

def Distance(x, y, p=2):
if len(x) == len(y) and len(x) > 1:
sum = 0;
for i in range(len(x)):
sum += math.pow(abs(x[i] - y[i]), p)
return math.pow(sum, 1 / p);
else:
return 0;

x1 = [1, 1]

x2 = [5, 1]

x3 = [4, 4]

for i in range(1, 5):
r = {'1-{}'.format(c): Distance(x1, c, p=i) for c in [x2, x3]}
print(min(zip(r.values(), r.keys())))

posted on 2019-07-22 14:34  Indian_Mysore  阅读(186)  评论(1编辑  收藏  举报

导航