Created
June 19, 2018 19:39
-
-
Save WillKoehrsen/2c9e80002670e9dadf2b3e9d0985dd16 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
# Threshold for removing correlated variables | |
threshold = 0.9 | |
# Absolute value correlation matrix | |
corr_matrix = app.corr().abs() | |
# Upper triangle of correlations | |
upper = corr_matrix.where(np.triu(np.ones(corr_matrix.shape), k=1).astype(np.bool)) | |
# Select columns with correlations above threshold | |
to_drop = [column for column in upper.columns if any(upper[column] > threshold)] | |
# Remove the columns | |
app = app.drop(columns = to_drop) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment