Browse Source

1st commit

master
sacha.serny 3 years ago
parent
commit
e037b91fd2
  1. 12
      py_main.py

12
py_main.py

@ -1,6 +1,4 @@
%matplotlib inline
import numpy as np import numpy as np
import matplotlib.pyplot as plt
def lecture(name): def lecture(name):
lst_date = [] lst_date = []
@ -18,28 +16,28 @@ def lecture(name):
return(np.array(lst_date), np.array(lst_conso), np.array(lst_t_moy), np.array(lst_t_ref)) return(np.array(lst_date), np.array(lst_conso), np.array(lst_t_moy), np.array(lst_t_ref))
def numero_jour (date): def numero_jour (date):
return date.split("-")[2]
return int(date.split("-")[2])
def distance (pos1, pos2): def distance (pos1, pos2):
x1, y1, z1 = pos1 x1, y1, z1 = pos1
x2, y2, z2 = pos2 x2, y2, z2 = pos2
return np.sqrt(((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2)) return np.sqrt((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2)
def kPlusProches(echantillon, donnees, k): def kPlusProches(echantillon, donnees, k):
voisins = [] voisins = []
for i in range(len(donnees)): for i in range(len(donnees)):
date, conso, t_moy = donnees[i] date, conso, t_moy = donnees[i]
print(donnees[i])
d = distance(echantillon, (date, conso, t_moy)) d = distance(echantillon, (date, conso, t_moy))
print (d)
voisins.append((d, i)) voisins.append((d, i))
return [voisins[i][1] for i in range(k)] return [voisins[i][1] for i in range(k)]
num_jour = [] num_jour = []
dates, consos, t_moys, t_refs = lecture("pic-journalier-consommation.csv") dates, consos, t_moys, t_refs = lecture("pic-journalier-consommation.csv")
for date in dates: for date in dates:
num_jour.append(numero_jour(date)) num_jour.append(numero_jour(date))
coords = list(zip(num_jour, t_moys, t_refs)) coords = list(zip(num_jour, t_moys, t_refs))
kPlusProches((13, 21.0, 20.6), coords, 4) print(kPlusProches((31, 0, 0), coords, 4))

Loading…
Cancel
Save