<jupyter_start><jupyter_text>The **variance inflation factor** (VIF) quantifies the extent of correlation between one predictor and the other predictors in a model. It is used for diagnosing collinearity/multicollinearity. Higher values signify that it is difficult to impossible to assess accurately the contribution of predictors to a model.$$VIF = \frac {1} {1 - R^2}$$  The higher the value, the greater the correlation of the variable with other variables.<jupyter_code>import numpy as np
import pandas as pd
import statsmodels.api as sm
import warnings
from pandas import DataFrame,Series
from scipy import stats
from sklearn.datasets import load_boston
warnings.filterwarnings('ignore')
boston = load_boston()
print (boston.DESCR)
X = boston["data"]
Y = boston["target"]
names = list(boston["feature_names"])
inp_df = pd.DataFrame(X, columns=names)
inp_df.head()
for i in range(0, len(names)):
    y = inp_df.loc[:, inp_df.columns == names[i]]
    x = inp_df.loc[:, inp_df.columns != names[i]]
    model = sm.OLS(y, x)
    results = model.fit()
    rsq = results.rsquared
    vif = round(1 / (1 - rsq), 2)
    print(
        "R Square value of {} column is {} keeping all other columns as features".format(
            names[i], (round(rsq, 2))
        )
    )
    print(
        "Variance Inflation Factor of {} column is {} \n".format(
            names[i], vif)
        )<jupyter_output>R Square value of CRIM column is 0.52 keeping all other columns as features
Variance Inflation Factor of CRIM column is 2.1 

R Square value of ZN column is 0.65 keeping all other columns as features
Variance Inflation Factor of ZN column is 2.84 

R Square value of INDUS column is 0.93 keeping all other columns as features
Variance Inflation Factor of INDUS column is 14.49 

R Square value of CHAS column is 0.13 keeping all other columns as features
Variance Inflation Factor of CHAS column is 1.15 

R Square value of NOX column is 0.99 keeping all other columns as features
Variance Inflation Factor of NOX column is 73.89 

R Square value of RM column is 0.99 keeping all other columns as features
Variance Inflation Factor of RM column is 77.95 

R Square value of AGE column is 0.95 keeping all other columns as features
Variance Inflation Factor of AGE column is 21.39 

R Square value of DIS column is 0.93 keeping all other columns as features
Variance Inflation Factor of DIS column is [...]
{'fraction_non_alphanumeric': 0.0720233139050791, 'fraction_numerical': 0.02331390507910075, 'mean_word_length': 3.7773359840954273, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '492010', 'license': 'MIT', 'n_tokens_mistral': 766, 'n_tokens_neox': 692, 'n_words': 329, 'path': '08. Regression/09. Variance Inflation Factor for Multicolinearity.ipynb', 'repo_name': 'luckyrabbit85/Understanding-Machine-Learning', 'size': '2402'}