Browse Source

1st commit

master
sacha.serny 3 years ago
parent
commit
e2b601d870
  1. 30
      py_main.py

30
py_main.py

@ -1,4 +1,7 @@
%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 = []
lst_conso = [] lst_conso = []
@ -14,4 +17,29 @@ def lecture(name):
lst_t_ref.append(float(t_ref)) lst_t_ref.append(float(t_ref))
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 def numero_jour (date):
return date.split("-")[2]
def distance (pos1, pos2):
x1, y1, z1 = pos1
x2, y2, z2 = pos2
return np.sqrt(((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2))
def kPlusProches(echantillon, donnees, k):
voisins = []
for i in range(len(donnees)):
date, conso, t_moy = donnees[i]
print(donnees[i])
d = distance(echantillon, (date, conso, t_moy))
voisins.append((d, i))
return [voisins[i][1] for i in range(k)]
num_jour = []
dates, consos, t_moys, t_refs = lecture("pic-journalier-consommation.csv")
for date in dates:
num_jour.append(numero_jour(date))
coords = list(zip(num_jour, t_moys, t_refs))
kPlusProches((13, 21.0, 20.6), coords, 4)

Loading…
Cancel
Save