Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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)
Add Comment
Please, Sign In to add comment