简体   繁体   中英

Am i using statsmodel statsmodels.stats.outliers_influence.variance_inflation_factor right?

Currently, am detecting multicollinearity using VIF. However, there are little to no examples online that i can use as reference, thus i tried using it by myself.

cat_var = df[["BsmtExposure","MSZoning","Exterior1st","MSSubClass","GarageType","GarageFinish"]].apply(preprocessing.LabelEncoder().fit_transform)
dfX = df[["OverallQual","ExterQual","GrLivArea","1stFlrSF","GarageCars","BsmtQual","HeatingQC","YearBuilt"]]
data_categorical = dfX.join(cat_var)
sm_data_categorical = sm.add_constant(data_categorical)
vifDf = sm_data_categorical
vifDf = vifDf.drop(["OverallQual","YearBuilt"],axis=1)
feature = vifDf.columns
print(feature)
vif = [variance_inflation_factor(vifDf[feature].values,feature.get_loc(var)) for var in feature]
print(vif)

Output:
[139.09182494163923, 1.9269169697717614, 1.794083234373851, 1.828696948899336, 1.6357605533337554, 1.680843256052908, 1.4734276288799137, 1.2599932369972506, 1.0704636681342352, 1.1139451723386682, 1.2658662212832537, 1.4714527943918547, 1.2728931548738207]

I have used statsmodels.add_constant too.

Aaron, there is R package called mcTest, which does multi-Collinearity diagnostics for the variables. For more information for implementing, here is a link( http://rfaqs.com/mctest-r-package-detection-collinearity-among-regressors ). Hope it helps.

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