Skip to content

Instantly share code, notes, and snippets.

@WillKoehrsen
Created June 19, 2018 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WillKoehrsen/2c9e80002670e9dadf2b3e9d0985dd16 to your computer and use it in GitHub Desktop.
Save WillKoehrsen/2c9e80002670e9dadf2b3e9d0985dd16 to your computer and use it in GitHub Desktop.
# 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