Created
May 18, 2020 03:02
-
-
Save dyerrington/0db6de7e1e31ab4b83c53a6ffb6ca2cf to your computer and use it in GitHub Desktop.
This file contains 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 pandas as pd | |
import numpy as np | |
from sklearn.datasets import load_wine | |
# Load example wine dataset from sklearn | |
data = load_wine() | |
# Create a basic DataFrame | |
df = pd.DataFrame(data['data'], columns = data['feature_names']) | |
# Create a Pearson matrix | |
df_corr = df.corr() | |
# Set the diagonal elements (identity) to 0 | |
df_corr.values[tuple([np.arange(df_corr.shape[0])]) * 2] = 1 | |
## BTW it's also possible to this with a numpy built-in like so | |
# np.fill_diagonal(df_corr.values, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment