Search code examples
pythonstatsmodelssklearn-pandasstandardized

Standardize features to calculate variance inflation factors


I'm calculating variance inflation factors

from patsy import dmatrices
from statsmodels.stats.outliers_influence import variance_inflation_factor
y, X = dmatrices('A ~ B + C + D + E + F + G, data=df, return_type='dataframe')

vif = pd.DataFrame()
vif['VIF'] = [variance_inflation_factor(X.values, i) for i in range(X.shape[1])]
vif['variable'] = X.columns
vif

How can I now standardize the features using StandardScaler() and then re-calculate the variance inflation factors of the standardized features?


Solution

  • Using "patsy import dmatrices" already scales and standardizes the features. Therefore there is no need to do a second step with StandardScaler()