Added new functions
This commit is contained in:
parent
5e14a0e059
commit
4a1023206b
|
@ -101,15 +101,29 @@ def kovarianz(werte=[]):
|
||||||
x = wert[0]
|
x = wert[0]
|
||||||
y = wert[1]
|
y = wert[1]
|
||||||
summe = summe + ((x - xMittel) * (y - yMittel))
|
summe = summe + ((x - xMittel) * (y - yMittel))
|
||||||
return summe / n
|
return float(summe) / float(n)
|
||||||
|
|
||||||
|
def korrelationskoeffizentPearson(werte=[]):
|
||||||
|
xStandardabweichung = standardabweichung([wert[0] for wert in werte])
|
||||||
|
yStandardabweichung = standardabweichung([wert[1] for wert in werte])
|
||||||
|
return float(kovarianz(werte)) / float(xStandardabweichung * yStandardabweichung)
|
||||||
|
|
||||||
|
def bildeWertePaare(x=[], y=[]):
|
||||||
|
wertePaare = []
|
||||||
|
if not len(x) == len(y):
|
||||||
|
return False
|
||||||
|
for i in range(len(x)):
|
||||||
|
wertePaare.append((x[i], y[i]))
|
||||||
|
return wertePaare
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#werte = [12, -5, 5, 52, -6, -5, 8, -7, 22, -46, 8, -14, 5, 47]
|
#werte = [12, -5, 5, 52, -6, -5, 8, -7, 22, -46, 8, -14, 5, 47]
|
||||||
#haufigkeiten = {0: 6, 1: 6, 2: 3, 3: 5, 8: 6}
|
#haufigkeiten = {0: 6, 1: 6, 2: 3, 3: 5, 8: 6}
|
||||||
werte = [(1, 2), (3, 4), (5, 6)]
|
werteX = [163, 165, 166, 169, 170, 171, 171, 173, 174, 175, 177, 177, 179, 180, 185]
|
||||||
|
werteY = [59, 62, 65, 69, 65, 69, 76, 73, 75, 73, 80, 71, 82, 84, 81]
|
||||||
|
werte = bildeWertePaare(werteX, werteY)
|
||||||
print(kovarianz(werte))
|
print(kovarianz(werte))
|
||||||
|
print(korrelationskoeffizentPearson(werte))
|
||||||
#werte = [9, 7, 7, 6, 1]
|
#werte = [9, 7, 7, 6, 1]
|
||||||
# haufigkeiten = {11: 3/20, 13: 1/2, 15: 1/10, 17: 1/5, 19: 1/20}
|
# haufigkeiten = {11: 3/20, 13: 1/2, 15: 1/10, 17: 1/5, 19: 1/20}
|
||||||
# print("Anzahl Elemente: " , anzahlElemente(werte))
|
# print("Anzahl Elemente: " , anzahlElemente(werte))
|
||||||
|
|
Loading…
Reference in New Issue