<jupyter_start><jupyter_text>KNN programe Basic<jupyter_code>def main(): 
    
    data = {0:[(1,12,5),(2,5,8),(3,6,9),(3,10,6),(3.5,8,2.9),(2,11,4.6),(2,9,9.5),(1,7,5)], 
              1:[(5,3,5.4),(3,2.7,5),(1.5,9,2.9),(7,2,2.9),(6,1,4.8),(3.8,1,5.9),(5.6,4,6),(4,2,5),(2,5,1)]
                 } 
  
    # testing point p(x,y,z) 
    p = (2,5,8)    # change co-ordinates    
  
    # Number of neighbours  
    k = 2
  
    print("The value differentiated to point 'P' is: {}".\
          format(differentiator(data, p, k))) 
#     here we are calling a  'differentiator' a function.
#     that will do all calcutations of euclidean distances.
#     it will also store values of each point from point 'p' to another points

import math

def differentiator(data,p,k=2):
    distance = []
    for group in data:
        print(group)
        for feature in data[group]:
            print(feature)
            euclidean_distance = math.sqrt((feature[0]-p[0])**2 +(feature[1]-p[1])**2 +(feature[2]-p[2])**2)
            
            distance.append((euclidean_distance,group))
            
    distance = sorted(distance)[:k]
    
    freq1 = 0
    freq2 = 0
 
    
    for d in distance:
        if d[0] == 0:
            
            freq1 += 1
            
        elif d[1] == 1:
            
            freq2 += 1 
            
    return 0 if freq1 > freq2 else 1
if __name__ == '__main__': 
    
    main()<jupyter_output>0
(1, 12, 5)
(2, 5, 8)
(3, 6, 9)
(3, 10, 6)
(3.5, 8, 2.9)
(2, 11, 4.6)
(2, 9, 9.5)
(1, 7, 5)
1
(5, 3, 5.4)
(3, 2.7, 5)
(1.5, 9, 2.9)
(7, 2, 2.9)
(6, 1, 4.8)
(3.8, 1, 5.9)
(5.6, 4, 6)
(4, 2, 5)
(2, 5, 1)
The value differentiated to point 'P' is: 0
{'fraction_non_alphanumeric': 0.1959378733572282, 'fraction_numerical': 0.1009557945041816, 'mean_word_length': 2.0017921146953404, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '378213', 'license': 'Apache-2.0', 'n_tokens_mistral': 809, 'n_tokens_neox': 713, 'n_words': 170, 'path': 'KNN.ipynb', 'repo_name': 'akshay6008/justlearn', 'size': '1674'}