<jupyter_start><jupyter_text>def dist(x1,x2):    return np.sqrt(sum((x1-x2)**2))def knn(X,Y,querypoint,k=5):    vals=[]    m=X.shape[0]    print(m)        for i in range(m):        d=dist(querypoint,X[i])        vals.append((d,Y[i]))            vals=sorted(vals)    vals=vals[:k]        vals=np.array(vals)    new_vals=np.unique(vals[:,1],return_counts=True)    print(new_vals)        index=new_vals[1].argmax()    pred=new_vals[0][index]        return pred<jupyter_code>from sklearn.neighbors import KNeighborsClassifier 

knn =KNeighborsClassifier(n_neighbors=10)


cap=cv2.VideoCapture(0)

face_cascade=cv2.CascadeClassifier("haarcascade_frontalface_alt.xml")
skip=0
dataset_path='./data/'
face_data=[]
labels=[]

classId=0
names={}
for fx in os.listdir(dataset_path):
    if fx.endswith('.npy'):
        names[classId]=fx[:-4]
        print("loaded "+fx)
        data_item=np.load(dataset_path+fx)
        face_data.append(data_item)
        
        target=classId*np.ones((data_item.shape[0],))
        classId+=1
        labels.append(target)
        
face_data=np.concatenate(face_data,axis=0)
face_labels=np.concatenate(labels,axis=0)

print(face_data)
print(face_labels)



knn.fit(face_data,face_labels)
while True:
    ret,frame=cap.read()
    if ret ==False:
        continue
    faces=face_cascade.detectMultiScale(frame,1.3,5)
    
    for face in faces:
        x,y,w,h=face
        offset = 10
        face_section = frame[y-offset:y+h+offset,x-offset:x+w+offset]
        face_section = cv2.resize(face_section,(100,100))
        
        out=knn.predict([face_section.flatten()])
        pred_name=names[int(out)]
        cv2.putText(frame,pred_name,(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,255),2,cv2.LINE_AA)
        cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,255),3)
        
    cv2.imshow("Faces",frame)
    key_pressed=cv2.waitKey(1) & 0xFF
    if key_pressed == ord('q'):
        break
        
cap.release()
cv2.destroyAllWindows()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1558572146807441, 'fraction_numerical': 0.03117144293614882, 'mean_word_length': 3.522727272727273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '220363', 'license': 'MIT', 'n_tokens_mistral': 810, 'n_tokens_neox': 774, 'n_words': 87, 'path': 'MachineLearning/faceDetection/faceReccognition.ipynb', 'repo_name': 'pulkit10251/cbData-Science-Master', 'size': '1989'}