import numpy as np
import pandas as pd
import statsmodels.api as sm
from scipy import stats
df = pd.read_csv("diabetes2.csv")
df.head()
X = df.iloc[:,:-1]
y = df.iloc[:,-1]
X.head()
y.head()
names = X.columns
names
for i in range(0,len(names)):
y1 = X.loc[:,X.columns == names[i]]
x = X.loc[:,X.columns != names[i]]
model = sm.OLS(y1,x)
output = model.fit()
r_squared = output.rsquared
vif = round(1/(1-r_squared),2)
if vif>=5:
print("We can exclude this feature as the Variance Inflation Factor for column {} is {}".format(names[i],vif))
print("The R-Squared value for column {} is {} with all the other columns as features".format(names[i],r_squared))
else:
print("We can include this feature as the Variance Inflation Factor for column {} is {}".format(names[i],vif))
print("The R-Squared value for column {} is {} with all the other columns as features".format(names[i],r_squared))