x = [8,2,7,7,3,1]
x = [8,2,7,7,3,1]
y = [5,3,10,3,8,1]
label=['과일','단백질','채소','과일','채소','단백질']
tomato =[6,4]
grape = [8, 5]
fish = [2, 3]
carrot = [7, 10]
orange = [7, 3]
celery = [3, 8]
cheese = [1, 1]
from copy import copy
def knn(a,k):
d=[]
for i in range(len(x)):
d.append(np.sqrt(((x[i]-a[0])**2)+(y[i]-a[1])**2))
d_c=copy(d)
#최소값 k개 구현
min_d=[]
for i in range(k):
min_d.append(min(d))
d.pop(d.index(min(d)))
#거리 최소 값들의 인덱싱 출력
min_d_index=[]
for i in range(len(min_d)):
min_d_index.append(d_c.index(min_d[i]))
# 라벨링
label_mdi=[]
for i in min_d_index:
label_mdi.append(label[i])
# 라벨링 많은 거 선택해~
ih=[]
lab=[]
fruits=[]
for i in range(len(label)):
ih.append(i)
fruits.append(label_mdi.count(label[i]))
lab.append(label[i])
print(lab[fruits.index(max(fruits))])
# label[fruits.index(max(fruits))]
knn(tomato,3)