Page11/14
Statistical Analysis & Correlation Β· Page 1 of 1
Correlation & Covariance
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
| Coefficient | Interpretation |
|---|---|
| 0.0 - 0.3 | Weak |
| 0.3 - 0.7 | Moderate |
| 0.7 - 1.0 | Strong |
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β¦