<jupyter_start><jupyter_text>Multicollinearity & VIFsUsing the notebook here, answer the quiz questioons below regarding multicollinearity.To get started let's read in the necessary libraries and the data that will be used.<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
from patsy import dmatrices
import statsmodels.api as sm;
from statsmodels.stats.outliers_influence import variance_inflation_factor
%matplotlib inline

df = pd.read_csv('./house_prices.csv')
df.head()<jupyter_output><empty_output><jupyter_text>`1.`Use [seaborn](https://seaborn.pydata.org/examples/scatterplot_matrix.html) to look at pairwise relationships for all of the quantitative, explanatory variables in the dataset by running the cell below.  You might also investigate how to add color (**hue**) for the house style or neighborhood.  Use the plot to answer the first quiz questions below.<jupyter_code>sns.pairplot(df[['bedrooms', 'bathrooms', 'area']]);<jupyter_output><empty_output><jupyter_text>`2.` Earlier, you fit linear models between each individual predictor variable and price, as well as using all of the variables and the price in a multiple linear regression model. Each of the individual models showed a positive relationship - that is, when bathrooms, bedrooms, or area increase, we predict the price of a home to increase. Fit a linear model to predict a home **price** using **bedrooms**, **bathrooms**, and **area**. Use the summary to answer the second quiz question below. **Don't forget an intercept.**<jupyter_code>df['intercept'] = 1

lm = sm.OLS(df['price'], df[['intercept', 'area', 'bedrooms', 'bathrooms']])
results = lm.fit()
results.summary()<jupyter_output><empty_output><jupyter_text>`3.` Calculate the VIFs for each variable in your model.  Use quiz 3 below to provide insights about the results of your VIFs.  [Here](https://etav.github.io/python/vif_factor_python.html) is the helpful post again, in case you need it!<jupyter_code>y, X = dmatrices('price ~ area + bedrooms + bathrooms', df, return_type='dataframe')

vif = pd.DataFrame()
vif['VIF Factor'] = [variance_inflation_factor(X.values, i) for i in range(X.shape[1])]
vif['features'] = X.columns
vif<jupyter_output><empty_output><jupyter_text>`4.` Remove bathrooms from your above model.  Refit the multiple linear regression model and re-compute the VIFs.  Use the final quiz below to provide insights about your results.<jupyter_code>y, X = dmatrices('price ~ area + bedrooms', df, return_type='dataframe')

vif = pd.DataFrame()
vif['VIF Factor'] = [variance_inflation_factor(X.values, i) for i in range(X.shape[1])]
vif['features'] = X.columns
vif<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10597014925373134, 'fraction_numerical': 0.0029850746268656717, 'mean_word_length': 6.073878627968337, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '321255', 'license': 'MIT', 'n_tokens_mistral': 845, 'n_tokens_neox': 806, 'n_words': 295, 'path': 'Regression/Multicollinearity & VIFs.ipynb', 'repo_name': 'ColdTeapot273K/data-stuff', 'size': '2680'}