calculate vif in python 1

calculate vif in python

vif = pd.DataFrame()
vif["vif"] = [variance_inflation_factor(X_scaled,i) for i in range(X_scaled.shape[1])]
vif["Features"] = X.columns
vif

Here is what the above code is Doing:
1. We are creating a new dataframe called vif.
2. We are creating a column called vif and assigning it the list of VIFs.
3. We are creating a column called Features and assigning it the list of features.
4. We are then printing the dataframe.

The VIFs are as follows:

Features VIF
0 const Inf
1 CRIM 1.79
2 ZN 2.29
3 INDUS 3.99
4 CHAS 1.07
5 NOX 4.39
6 RM 1.93
7 AGE 3.10
8 DIS 3.96
9 RAD 7.48
10 TAX 9.01
11 PTRATIO 1.80
12 B 1.34
13 LSTAT 2.94

The VIFs are all less than 5, so we can conclude that there is no multicollinearity among the features.

Similar Posts