1
$\begingroup$

I write down a script to calculate correlation to remove highly correlated variable before feature selection and ML model building.

library('caret')

df1 = read.csv("stack.csv")

print (df1)

     GA     PN     PC   MBP    GR    AP
1 0.033  6.652  6.681 0.194 0.874 3.177
2 0.034  9.039  6.224 0.194 1.137 3.400
3 0.035 10.936 10.304 1.015 0.911 4.900
4 0.022 10.110  9.603 1.374 0.848 4.566
5 0.035  2.963 17.156 0.599 0.823 9.406
6 0.033 10.872 10.244 1.015 0.574 4.871
7 0.035 21.694 22.389 1.015 0.859 9.259
8 0.035 10.936 10.304 1.015 0.911 4.500


df2 = cor(df1)
hc = findCorrelation(df2, cutoff=0.3) # putt any value as a "cutoff" 
hc = sort(hc)
reduced_Data = df1[,-c(hc)]
print (reduced_Data)

     GA     PN    GR    AP
1 0.033  6.652 0.874 3.177
2 0.034  9.039 1.137 3.400
3 0.035 10.936 0.911 4.900
4 0.022 10.110 0.848 4.566
5 0.035  2.963 0.823 9.406
6 0.033 10.872 0.574 4.871
7 0.035 21.694 0.859 9.259
8 0.035 10.936 0.911 4.500

My question is that to remove the correlated feature should I used normalized data.

preObj <- preProcess(nd[,2:(x-1) ], method=c("center", "scale"))
normalized_Data <- predict(preObj, nd[,2:(x-1)])

or I can use the raw data to calculate the correlation.

Thank you.

$\endgroup$
7
$\begingroup$

Since the formula for calculating the correlation coefficient standardizes the variables, changes in scale or units of measurement will not affect its value. For this reason, normalizing will NOT affect the correlation.

$\endgroup$
  • $\begingroup$ Which means I am wasting my time and computational resources in normalizing data before correlation calculation. I can directly use the raw data. $\endgroup$ – jax Aug 22 '19 at 14:56
  • 3
    $\begingroup$ if your purpose for normalizing is solely compute the correlation then yes it is useless. $\endgroup$ – mik1904 Aug 22 '19 at 14:58
  • $\begingroup$ Yes, here my sole purpose was only for correlation, thank you for your comment. $\endgroup$ – jax Aug 22 '19 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.