Last active
February 20, 2025 09:36
-
-
Save eugen-hoppe/6009fc3bc061592dcd338d83371ec2a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import pandas as pd | |
| import seaborn as sns | |
| import phik # pip install phik==0.12.4 | |
| # see: https://phik.readthedocs.io/en/latest/ | |
| def correlation_mtx(df_: pd.DataFrame, *columns: list[str], title: str = "") -> None: | |
| # src: https://gist.github.com/eugen-hoppe/6009fc3bc061592dcd338d83371ec2a2 | |
| phik_data = pd.get_dummies( | |
| df_[[*columns]], | |
| drop_first=True, | |
| ) | |
| phik_matrix = phik_data[phik_data.columns].phik_matrix( | |
| interval_cols=phik_data.columns | |
| ) | |
| plt.figure(figsize=(10, 8)) | |
| sns.heatmap( | |
| phik_matrix, cmap="Blues", annot=True, fmt=".1f", annot_kws={"size": 6} | |
| ) | |
| plt.title("Correlation Matrix" if not title else title, fontsize=14) | |
| plt.xticks(fontsize=8) | |
| plt.yticks(fontsize=8) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment