From 154844eb7c150e481aef16dd31a615376ec586fb Mon Sep 17 00:00:00 2001 From: zhled14 <¨hgmholk@gmail.com¨> Date: Sat, 2 Dec 2023 16:14:55 -0600 Subject: [PATCH] tabla --- Environmental.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Environmental.py b/Environmental.py index 67bd2a3..c3ee817 100644 --- a/Environmental.py +++ b/Environmental.py @@ -30,6 +30,53 @@ def FilteringData(b,e): return luxesf, tempf, humf, powf +# Pearson and Spearman correlation +def Correlation(l,t,h,p,c): + # Empty 4x4 array + arr = np.empty((4,4)) + # Joints luxesf, tempf, humf, powf in one array + l=np.array(l).reshape(-1,1) + t=np.array(t).reshape(-1,1) + h=np.array(h).reshape(-1,1) + p=np.array(p).reshape(-1,1) + aa=np.hstack((l,t,h,p)) + + for a in range(0,4): + for t in range (0,4): + if c=='p':corr, j = pearsonr(aa[:,a],aa[:,t]) # If c iquals s, pearson correlation is calculated + elif c=='s': corr, j = spearmanr(aa[:,a],aa[:,t]) # If c iquals s, pearson correlation is calculated + else: print("Elija un tipo de correlacion valida: pearson(p) o spearman(s)") + arr[a][t]=corr + return arr +# Table of correlation Function +def Tablecorrelation(data,title): + fig, ax = plt.subplots() + table = ax.table(cellText=np.around(data, decimals=4), + rowLabels=['Lux','Temp','Hum','Pow'], + colLabels=['Lux','Temp','Hum','Pow'], + loc='center') + table.set_fontsize(10) + table.scale(1.2,1.2) + ax.axis('off') + plt.title(title) + plt.savefig(f'{title}.png') + plt.show() +#Filtered data from 9Hrs to 16Hrs +l, t, h, p = FilteringData(9,16) +#Importing scipy library +from scipy.stats import pearsonr +from scipy.stats import spearmanr +#Correlation calculation +#SPEARMAN +Spearmancorrelation = Correlation(l, t, h, p,'s') +print('Spearman correlation') +print(Spearmancorrelation) +Tablecorrelation(Spearmancorrelation,'Spearman correlation') +#PEARSON +pearsoncorreltaion = Correlation(l, t, h, p,'p') +print('Pearson correlation') +print(pearsoncorreltaion) +Tablecorrelation(pearsoncorreltaion,'Pearson correltaion') ############## PLOTTING DATA FUNCTION ############## #Inputs: Luxes, Temperature, Humidity and Power #Output: Vs graph 4x4