<jupyter_start><jupyter_text>Interpreting CoefficientsIt is important that not only can you fit complex linear models, but that you then know which variables you can interpret. In this notebook, you will fit a few different models and use the quizzes below to match the appropriate interpretations to your coefficients when possible.In some of the cases, the coefficients of your linear regression models wouldn't be kept due to the lack of significance, that is not the aim of this notebook - **this is strictly to assure you are comfortable with how to interpret coefficients (when they are interpretable at all**.<jupyter_code>import numpy as np
import pandas as pd
import statsmodels.api as sm;

df = pd.read_csv('./house_prices.csv')
df.head()<jupyter_output>/opt/conda/lib/python3.6/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
  from pandas.core import datetools<jupyter_text>We will be fitting a number of different models to this dataset throughout this notebook.  For each model, there is a quiz question that will allow you to match the interpretations of the model coefficients to the corresponding values.  If there is no 'nice' interpretation, this is also an option! Model 1`1.` For the first model, fit a model to predict `price` using `neighborhood`, `style`, and the `area` of the home.  Use the output to match the correct values to the corresponding interpretation in quiz 1 below.  Don't forget an intercept!  You will also need to build your dummy variables, and don't forget to drop one of the columns when you are fitting your linear model. It may be easiest to connect your interpretations to the values in the first quiz by creating the baselines as neighborhood **C** and home style **lodge**.<jupyter_code># Adding the intercept, and creating our dummy variables
df['intercept'] = 1
df[['A', 'B', 'C']] = pd.get_dummies(df['neighborhood'])
df[['lodge', 'ranch', 'victorian']] = pd.get_dummies(df['style'])

df.head(6)
lm = sm.OLS(df['price'], df[['intercept', 'A', 'B', 'ranch', 'victorian', 'area']])
results = lm.fit()
results.summary()
df.groupby('style').mean()[['price', 'area']]<jupyter_output><empty_output><jupyter_text>Model 2`2.` Now let's try a second model for predicting price.  This time, use `area` and `area squared` to predict price.  Also use the `style` of the home.  You will again need to use your dummy variables, and add an intercept to the model.  Use the results of your model to answer quiz 2.<jupyter_code># Adding the intercept, and creating our dummy variables
df['area_squared'] = df['area']*df['area']
df.head()
lm2 = sm.OLS(df['price'], df[['intercept', 'area', 'area_squared', 'ranch', 'victorian']])
results2 = lm2.fit()
results2.summary()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09819569743233865, 'fraction_numerical': 0.005551700208188758, 'mean_word_length': 5.336263736263736, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '56030', 'license': 'MIT', 'n_tokens_mistral': 844, 'n_tokens_neox': 803, 'n_words': 380, 'path': 'Practical_Statistics/Practical_Statistics/13_MLR/Interpreting Model Coefficients.ipynb', 'repo_name': 'christineton/Udacity_Data_Analysis_Nanodegree', 'size': '2882'}