简体   繁体   中英

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?

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

Check out patsy'sstateful transforms and standardize .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM