{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"import sys\n",
"import os\n",
"if not any(path.endswith('textbook') for path in sys.path):\n",
" sys.path.append(os.path.abspath('../../..'))\n",
"from textbook_utils import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(ch:linear)=\n",
"# Linear Models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"At this point in the book,\n",
"we've covered the first three stages of the data science lifecycle in detail.\n",
"We've talked about asking questions and obtaining data.\n",
"We've also used exploratory data analysis ({numref}`Chapter %s `) \n",
"to understand the data.\n",
"and \n",
"In this chapter we extend the simple model introduced in {numref}`Chapter %s `,\n",
"to more complex *linear models*, which enable us to\n",
"model relationships between variables and which leads us into the last stage of the\n",
"lifecycle---understanding the world."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Simply put, linear models estimate how features vary together. \n",
"Being able to model relationships opens the door to all kinds of useful data analyses.\n",
"We can use these models to make predictions---for example,\n",
"data scientists use linear models to predict air quality based on air sensor measurements and weather conditions (see {numref}`Chapter %s `). \n",
"In that case study, understanding how the two measurements varied together\n",
"enabled us to calibrate the cheap sensors. \n",
"We can also use models to make inferences about the form of a relationship--for example, \n",
"we use a linear model in {numref}`Chapter %s ` to infer the coefficients for length and girth are 1 and 2, respectively, in the model for a donkey's weight: $1 \\times Length ~+ ~ 2 \\times Girth ~-~175$. \n",
"In that case study, the model enabled animal vets to prescribe medication for a sick donkey. \n",
"And, models can help in exploring relationships and providing insights--for example, we can explore the relationships between factors correlated with upward mobility, such as residential segregation, income inequality, and the quality of K-12 education. In this chapter, we carry out this descriptive analysis, which has been used by researchers to study inter-generational mobility. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this chapter, we start by describing the simple linear model, which\n",
"models the relationship between a single explanatory variable and an outcome variable.\n",
"We explain how to fit this model using the loss minimization approach\n",
"first introduced in {numref}`Chapter %s `.\n",
"Then, we introduce the multiple linear model, which models the relationship\n",
"between multiple explanatory variables and the outcome.\n",
"To fit this model, we use linear algebra to reveal the geometry of the modeling problem.\n",
"Finally, we go over feature engineering techniques that let us include categorical features as explanatory variables, and to transform features to model all sorts of linear relationships."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}