11/1479
Statistical Analysis & Correlation · Page 1 of 1

Correlation & Covariance

18 min Advanced

Statistical Analysis & Correlation

Understanding Relationships Between Variables

Correlation measures how two variables move together:

  • +1: Perfect positive correlation (both increase together)
  • 0: No correlation
  • -1: Perfect negative correlation (one increases, other decreases)

Calculate Correlation

# Pearson correlation (default) — linear relationships
df.corr()                    # all numeric columns
df['age'].corr(df['salary']) # between two columns

# Spearman correlation — rank-based, more robust
df.corr(method='spearman')

Interpreting Correlation Strength

CoefficientInterpretation
0.0 - 0.3Weak
0.3 - 0.7Moderate
0.7 - 1.0Strong

Visualizing Correlation

corr_matrix = df.corr()
# Use Matplotlib heatmap to visualize

Important: Correlation ≠ Causation. Just because two variables correlate doesn't mean one causes the other.

main.py
Loading...
OUTPUT
Click "Run Code" to execute…