{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"# Reference: https://jupyterbook.org/interactive/hiding.html\n",
"# Use {hide, remove}-{input, output, cell} tags to hiding content\n",
"\n",
"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": [
"# Summary"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this case study, we demonstrated the different purposes of modeling: description, inference, and prediction. For description, we sought a simple, understandable model. We hand crafted this model, beginning with our findings from the exploratory phase of the analysis. Every action we took to include a feature in the model, collapse categories, or transform a feature amounts to a decision we made while investigating the data. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In modeling a natural phenomenon such as the weight of a donkey, we would ideally make use of physical and statistical models. In this case, the physical model is the representation of a donkey by a cylinder.\n",
"A inquisitive reader might have pointed out that we could have used this representation directly to estimate the weight of a donkey (cylinder) from its length and girth (since girth is $2\\pi r$):\n",
"\n",
"$$ weight \\propto girth^2 \\times length$$ "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This physical model suggests that the log transformed weight is approximately linear in girth and length:\n",
"\n",
"$$ \\log(weight) \\propto \\log(girth) + \\log(length)$$ "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Given this physical model, you might wonder why we did not use logarithmic or square transformations in our model. We leave you to investigate such a model in greater detail. But generally, if the range of values measured is small, then the log function is roughly linear. To keep our model simple, we chose not to make these transformations given the strength of the statistical model seen by the high correlation between the girth and weight of the donkeys."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Recall that we added categorical variables to our model using one-hot encoding,\n",
"and that we took out one variable for each category we transformed.\n",
"Actually, leaving in all the variables wouldn't change the model's\n",
"predictions---the model would still have the same test set error.\n",
"But, this model would be over parameterized, which means that fitting the model\n",
"multiple times could produce different values for $ \\hat{\\theta} $.\n",
"This is problematic for inference, since it stops us from having a useful and\n",
"consistent interpretation of the model.\n",
"When dropping a one-hot encoded variable, we chose to\n",
"drop the central or most common one so that vets don't need to make \n",
"adjustments to the model for common cases. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We did a lot of *data dredging* in this modeling exercise. We examined all possible models built from linear combinations of the numeric features, and we examined coefficients of dummy variables to decide whether to collapse categories.\n",
"When we create models using an iterative approach like this, \n",
"it is extremely important that we set aside data to assess the model. \n",
"Evaluating the model on new data reassures us that the model we chose works well.\n",
"The data that we set aside did not enter into any decision making when building the model so it gives us a good sense of how well the model works for making predictions."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, this case study shows how fitting models is often a balance between simplicity and complexity, and a balance between physical and statistical models.\n",
"As data scientists, we needed to make human judgment calls at each step in the analysis. In other words, modeling is both an art and a science. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"celltoolbar": "Tags",
"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
}