Guest User

Untitled

a guest
Jun 21st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. # Threshold for removing correlated variables
  2. threshold = 0.9
  3.  
  4. # Absolute value correlation matrix
  5. corr_matrix = app.corr().abs()
  6.  
  7. # Upper triangle of correlations
  8. upper = corr_matrix.where(np.triu(np.ones(corr_matrix.shape), k=1).astype(np.bool))
  9.  
  10. # Select columns with correlations above threshold
  11. to_drop = [column for column in upper.columns if any(upper[column] > threshold)]
  12.  
  13. # Remove the columns
  14. app = app.drop(columns = to_drop)
Add Comment
Please, Sign In to add comment