Detecting Multicollinearity with VIF

PHOTO EMBED

Tue Mar 02 2021 21:59:16 GMT+0000 (Coordinated Universal Time)

Saved by @Adorism80

from statsmodels.stats.outliers_influence import variance_inflation_factor 
  
# creating dummies for gender 
data['Gender'] = data['Gender'].map({'Male':0, 'Female':1}) 
  
# the independent variables set 
X = data[['Gender', 'Height', 'Weight']] 
  
# VIF dataframe 
vif_data = pd.DataFrame() 
vif_data["feature"] = X.columns 
  
# calculating VIF for each feature 
vif_data["VIF"] = [variance_inflation_factor(X.values, i) 
                          for i in range(len(X.columns))] 
  
print(vif_data)
content_copyCOPY

https://www.geeksforgeeks.org/detecting-multicollinearity-with-vif-python/