Created
January 16, 2021 16:56
-
-
Save AyishaR/4a42dd1ab67655bb7176b307d5258fc9 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
# There are many column pairs with high correlation, thus acting as duplicates. | |
# We can drop a column if there is a correlation = 1 or -1 | |
final_columns = list(df.columns) # maintaining a temporary list to remove columns from | |
for i in range(corr.shape[0]): | |
for j in range(i+1, corr.shape[0]): | |
#print(abs(corr.iloc[i,j]), list(df.columns)[i], list(df.columns)[j]) | |
if abs(corr.iloc[i, j]) > 0.98: # if very high correlation | |
if list(df.columns)[j] in final_columns: # if not aldready removed | |
final_columns.remove(list(df.columns)[j]) # remove | |
df = df[final_columns] # selecting only the required columns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment