Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Was Ist Kovarianz? | Kovarianz und Korrelation
Grundlagen der Wahrscheinlichkeitstheorie
course content

Kursinhalt

Grundlagen der Wahrscheinlichkeitstheorie

Grundlagen der Wahrscheinlichkeitstheorie

1. Grundlagen der Wahrscheinlichkeitstheorie
2. Wahrscheinlichkeit Komplexer Ereignisse
3. Häufig Verwendete Diskrete Verteilungen
4. Häufig Verwendete Kontinuierliche Verteilungen
5. Kovarianz und Korrelation

book
Was Ist Kovarianz?

Kovarianz ist ein numerisches Maß, das die Beziehung zwischen zwei Variablen quantifiziert.
Es misst, wie Änderungen in einer Variablen mit Änderungen in einer anderen Variablen einhergehen. Genauer gesagt, misst die Kovarianz die gemeinsame Variabilität zweier Variablen und liefert Einblicke in die Richtung (positiv oder negativ) dieser Variabilität.

Berechnung der Kovarianz

  1. Führe das erste stochastische Experiment mehrmals durch und notiere die Ergebnisse jedes Experiments in einem Array. Dies wird ein x-Array sein;
  2. Führe das zweite stochastische Experiment mehrmals durch und notiere die Ergebnisse in dem y-Array;
  3. Berechne die Kovarianz mit der numpy-Bibliothek: covariance = np.cov(x, y)[0, 1].

Beispiele

12345678910111213141516171819
import numpy as np import matplotlib.pyplot as plt # Assume that results of some stochastic experiments are stored in x array x = np.random.rand(100) * 10 # We provide another stochastic experiment by using the value of x and adding some noise y = x + np.random.randn(100) # Calculate the covariance covariance = np.cov(x, y)[0, 1] plt.scatter(x, y) # Add labels and title plt.xlabel('X') plt.ylabel('Y') plt.title('Covariance is '+ str(round(covariance, 3) )) # Show the plot plt.show()
copy

Wir sehen, dass mit steigendem x-Wert auch der y-Wert zunimmt. Daher ist die Korrelation positiv. Lassen Sie uns ein weiteres Experiment durchführen:

12345678910111213141516171819
import numpy as np import matplotlib.pyplot as plt # Assume that resylts of some stohastic experiments are stored in x array x = np.random.rand(100) * 10 # We provide another stohastic experiment by using the value of -x and adding some noise y = -x + np.random.randn(100) # Calculate the covariance covariance = np.cov(x, y)[0, 1] plt.scatter(x, y) # Add labels and title plt.xlabel('X') plt.ylabel('Y') plt.title('Covariance is '+ str(round(covariance, 3) )) # Show the plot plt.show()
copy

Nun, während der x-Wert zunimmt, sinkt der y-Wert und die Kovarianz ist negativ. Schauen wir uns nun die Kovariation zwischen den Ergebnissen von zwei unabhängigen Experimenten an:

1234567891011121314151617181920
import numpy as np import matplotlib.pyplot as plt # Generate random data for two variables with zero correlation np.random.seed(0) x = np.random.rand(200) y = np.random.rand(200) # Calculate the covariance covariance = np.cov(x, y)[0, 1] plt.scatter(x, y) # Add labels and title plt.xlabel('X') plt.ylabel('Y') plt.title('Covariance is '+ str(round(covariance, 3) )) # Show the plot plt.show()
copy

Folglich können wir die folgende Schlussfolgerung ziehen:

  1. Wenn die Kovarianz zwischen zwei Werten positiv ist, steigt auch der zweite Wert, wenn der erste Wert zunimmt;
  2. Wenn die Kovarianz zwischen zwei Werten negativ ist, sinkt der zweite Wert, wenn der erste Wert zunimmt;
  3. Sind die Werte unabhängig, dann ist ihre Korrelation null (sie sind unkorreliert).

Beachte den letzten Punkt: Die Korrelation ist null, wenn die Werte unabhängig sind. Aber das Umgekehrte gilt nicht: nur weil die Korrelation null ist, bedeutet das nicht, dass sie unabhängig sind. Schau dir das Beispiel an:

1234567891011121314151617181920212223242526
import numpy as np import matplotlib.pyplot as plt # Set the number of vectors/points to generate num_points = 1000 # Generate random angles uniformly distributed between 0 and 2*pi angles = np.random.uniform(0, 2*np.pi, num_points) # Convert angles to vectors in polar coordinates r = np.sqrt(np.random.uniform(0, 1, num_points)) # Square root to achieve uniform distribution within the circle x = r * np.cos(angles) y = r * np.sin(angles) # Calculate the covariance covariance = np.cov(x, y)[0, 1] plt.scatter(x, y) # Add labels and title plt.xlabel('X') plt.ylabel('Y') plt.title('Covariance is '+ str(round(covariance, 3) )) # Show the plot plt.show()
copy

Die Punkte im obigen Beispiel liegen innerhalb des Einheitskreises und sind daher abhängig, aber unkorreliert.
Im Allgemeinen können nur lineare Zusammenhänge zwischen Werten mithilfe der Kovarianz gut identifiziert werden. Daher können wir im Fall unkorrelierter Werte schließen, dass sie keine linearen Abhängigkeiten aufweisen, jedoch möglicherweise andere, komplexere Arten von Abhängigkeiten haben.

Welche der folgenden Aussagen ist wahr?

Welche der folgenden Aussagen ist wahr?

Wählen Sie die richtige Antwort aus

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 5. Kapitel 1
We're sorry to hear that something went wrong. What happened?
some-alt