|
|
|
@ -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
|
|
|
|
|