From 96cf4be49a4e8909599d4ab9b0125454d946c625 Mon Sep 17 00:00:00 2001 From: "gabrie.chataigner" Date: Mon, 30 May 2022 08:30:55 +0200 Subject: [PATCH] knn --- KNN_Mark1.py | 49 ++++++++++++++++++++++++++++++------------------- Thumbs.db | Bin 0 -> 8192 bytes 2 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 Thumbs.db diff --git a/KNN_Mark1.py b/KNN_Mark1.py index 9d8aee3..71eeb4e 100644 --- a/KNN_Mark1.py +++ b/KNN_Mark1.py @@ -5,7 +5,7 @@ def lancer(k, date, temp_moy, temp_ref, temp_num_jour): donnees_point = [date, temp_moy, temp_ref] print(k) print(donnees_point) - print(temp_num_jour) + #print(temp_num_jour) kPlusProches(k, donnees_point, temp_num_jour) #estBissextile(an) @@ -32,18 +32,30 @@ def estBissextile(an): else: return False -def kPlusProches(k, donnees_point, temp_num_jour): +def kPlusProches(k,donnees_point,temp_num_jour): """Fonction qui prend en paramètre un tuple correspondant au point à vérifier, une liste du jeu de données et la conso électrique. Renvoie une liste triée en fonction de la distance dont les éléments sont des tuples.""" - voisins = [] + if k > len(temp_num_jour): k = len(temp_num_jour) + voisin=[] + for j in range(k): + voisin.append([None]) + for i in range(len(temp_num_jour)): - d = distance(temp_num_jour[i],donnees_point) - voisins.append((d, i)) - voisins.sort() - return [voisins[i][1] for i in range(k)] + MN = distance(temp_num_jour[i],donnees_point) + for l in range(k): + if voisin[l][1] == None or MNKmm{h*u82efXAO@{C5i;0Per7 z`M>AGzuqtYp7_5N^VcKyw_^Vh{{Qd!{}Gt}yUl+N0tByVU|x#@?tkX z=VbqPmVY$@|J(S7E4`OSMIu6a?H{VFj0EIWoBk=lKLD~qKs=TG;{%Q5$<>mALh*f=r`WJ?y7g;OzQmcnRTUJZqykzq8r_F4h>>#)3$exF7qz&S1ccKc-qe+ z@kkSj$%xh^BSBY-PL6JC8`z16^uuK=r42u~+pbL-TaU7WwWfw{osWgSFCQG!f>~+w zS%^vTHj;&Mn#lkT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