<jupyter_start><jupyter_text>Establishing a BaselineFor most human endeavors it helps to begin by establishing a baseline. This baseline may be used to track performance over time. For instance, if you have decided to lose weight, a baseline would be your starting weight. You could also track the exact number and type of calories you eat for a few weeks before beginning any sort of diet. Similar baselines can be made for lifting weights, running, learning data science, etc... Without establishing a baseline, tracking progress becomes more difficult. No previous baseline was establishedIn our previous work with the housing dataset, we never established a baseline. We went straight into modeling with a single-variable linear regression. Let's read in the housing dataset and reproduce this result.<jupyter_code>import pandas as pd
import numpy as np
housing = pd.read_csv('../data/housing_sample.csv')
housing.head()
X = housing[['GrLivArea']]
y = housing['SalePrice']

from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(X, y)
lr.score(X, y)<jupyter_output><empty_output><jupyter_text>How to establish a baseline?A typical baseline is going to be a very simple model that we can build without much thought. A common simple model for supervised regression is predicting the same value for each observation, such as the mean or median. A baseline is built into linear regressionBy definition, predicting the mean for every observation yields an $R^2$ of exactly 0. Remembering that the equation for $R^2$ is $1 - \frac{SSE_{model}}{SSE_{mean}}$, then using the mean as our model should make it clear that $R^2$ would be in fact 0.  The `dummy` moduleThere actually exists a formal estimator for building a baseline in scikit-learn. The `DummyRegressor`, found in the `dummy` module, defaults to predicting the mean for each observation. The input data is completed ignored during the `fit` method.<jupyter_code>from sklearn.dummy import DummyRegressor
dr = DummyRegressor()
dr.fit(X, y)
dr.predict(X)<jupyter_output><empty_output><jupyter_text>Let's verify that the mean of the sale price is what the `DummyRegressor` predicts.<jupyter_code>y.mean()<jupyter_output><empty_output><jupyter_text>Use the `score` method to verify that $R^2$ is 0.<jupyter_code>dr.score(X, y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06977739726027397, 'fraction_numerical': 0.003424657534246575, 'mean_word_length': 5.639204545454546, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '206976', 'license': 'MIT', 'n_tokens_mistral': 647, 'n_tokens_neox': 620, 'n_words': 305, 'path': 'jupyter_notebooks/machine_learning/mastering_machine_learning/02. Linear Regression/06. Establishing a Baseline.ipynb', 'repo_name': 'manual123/Nacho-Jupyter-Notebooks', 'size': '2336'}