I'm working with an essentially linear unsupervised modeling approach which (predictably) has problems when there is (multi)-collinearity. To avoid this, I've written some code which removes variables one-by-one based on which reduces VIF the most. I.e.
The function VIF(X, i)
returns the VIF of the column i
of X
when regressed against the other columns. Also, assume we have.
max_VIF = max([VIF(X, i) for i in columns of X])
while max_VIF > threshold:
best_VIF = infinity
remove_col = None
for i in columns of X:
Y = X without column i
Y_VIF = max([VIF(Y, i) for i in columns of Y])
if Y_VIF < best_VIF:
best_VIF = Y_VIF
remove_col = i
remove i from X
max_VIF = best_VIF
This, unfortunately, requires me to calculate the VIF several times which is a VERY slow process. Is there a better way to do this?
Edit: making pseudo code more clear.