Revised first two weeks from feedback

This commit is contained in:
KarlHenrik
2025-08-13 12:54:12 +02:00
parent 3425395c86
commit f88eefcf7a
16 changed files with 89 additions and 140 deletions
+17 -35
View File
@@ -224,12 +224,16 @@
"source": [
"With the expression for $\\boldsymbol{\\hat{\\beta}_{OLS}}$, you now have what you need to implement OLS regression with your input data and target data $\\boldsymbol{y}$. But before you can do that, you need to set up you input data as a feature matrix $\\boldsymbol{X}$.\n",
"\n",
"In a feature matrix, each row is a datapoint and each column is a feature of that data. If you want to predict someones spending based on their income and number of children, for instance, you would create a row for each person in your dataset, and in each column put a 1 for the intercept, the montly income and the number of children."
"In a feature matrix, each row is a datapoint and each column is a feature of that data. If you want to predict someones spending based on their income and number of children, for instance, you would create a row for each person in your dataset, with the montly income and the number of children as columns.\n",
"\n",
"We typically also include an intercept in our models. The intercept is a value that is added to our prediction regardless of the value of the other features. The intercept tries to account for constant effects in our data that are not dependant on anything else. In our current example, the intercept could account for living expenses which are typical regardless of income or childcare expenses.\n",
"\n",
"We calculate the optimal intercept by including a feature with the constant value of 1 in our model, which is then multplied by some parameter $\\beta_0$ from the OLS method into the optimal intercept value (which will be $\\beta_0$). In practice, we include the intercept in our model by adding a column of ones to the start of our feature matrix."
]
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": null,
"id": "e5ff2a69",
"metadata": {},
"outputs": [],
@@ -239,7 +243,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": null,
"id": "a3cf2792",
"metadata": {},
"outputs": [],
@@ -260,7 +264,7 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": null,
"id": "5ad87a65",
"metadata": {},
"outputs": [],
@@ -281,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": null,
"id": "8f3f68aa",
"metadata": {},
"outputs": [],
@@ -312,7 +316,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": null,
"id": "d7476c84",
"metadata": {},
"outputs": [],
@@ -332,7 +336,7 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": null,
"id": "91496e40",
"metadata": {},
"outputs": [],
@@ -358,7 +362,7 @@
},
{
"cell_type": "code",
"execution_count": 67,
"execution_count": null,
"id": "034f502c",
"metadata": {},
"outputs": [],
@@ -376,7 +380,7 @@
},
{
"cell_type": "code",
"execution_count": 68,
"execution_count": null,
"id": "29171358",
"metadata": {},
"outputs": [],
@@ -396,21 +400,10 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": null,
"id": "1e346f4c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Ellipsis"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"..."
]
@@ -425,21 +418,10 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": null,
"id": "ceb57457",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Ellipsis"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"..."
]