diff --git a/doc/pub/week38/html/._week38-bs014.html b/doc/pub/week38/html/._week38-bs014.html index 4c330102a..affee3cad 100644 --- a/doc/pub/week38/html/._week38-bs014.html +++ b/doc/pub/week38/html/._week38-bs014.html @@ -423,6 +423,7 @@ MathJax.Hub.Config({
This code shows a simple first-order fit to a data set using the above transformed data, where we consider the role of the intercept first, by either excluding it or including it (code example thanks to Øyvind Sigmundson Schøyen). Here our scaling of the data is done by subtracting the mean values only. Note also that we do not split the data into training and test. +
@@ -502,7 +503,7 @@ intercept = np.
ypredictOwn = X @ beta
ypredictSKL = skl.predict(X)
print(f"MSE with Manual intercept")
-print(MSE(y,ypredictOwn))
+print(MSE(y,ypredictOwn+intercept))
print(f"MSE with Sklearn intercept")
print(MSE(y,ypredictSKL))
diff --git a/doc/pub/week38/html/._week38-bs016.html b/doc/pub/week38/html/._week38-bs016.html
index bf1accacd..c70295620 100644
--- a/doc/pub/week38/html/._week38-bs016.html
+++ b/doc/pub/week38/html/._week38-bs016.html
@@ -508,6 +508,15 @@ plt.ylabel('
plt.legend()
plt.show()
+
+We see here, when compared to the code which includes explicitely the
+intercept column, that our MSE value is actually smaller. This is
+because the regularization term does not include the intercept value \( \beta_0 \) in the
+fitting. This applies to Lasso regularization as well.
+
+
+If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
+
diff --git a/doc/pub/week38/html/week38-reveal.html b/doc/pub/week38/html/week38-reveal.html
index 9e09c6fa9..433918261 100644
--- a/doc/pub/week38/html/week38-reveal.html
+++ b/doc/pub/week38/html/week38-reveal.html
@@ -676,6 +676,7 @@ What does this mean? And why do we insist on all this? Let us look at some examp
This code shows a simple first-order fit to a data set using the above transformed data, where we consider the role of the intercept first, by either excluding it or including it (code example thanks to Øyvind Sigmundson Schøyen). Here our scaling of the data is done by subtracting the mean values only.
Note also that we do not split the data into training and test.
+
@@ -755,7 +756,7 @@ intercept = np.mean(y_offset - X_offset @ beta)
ypredictOwn = X @ beta
ypredictSKL = skl.predict(X)
print(f"MSE with Manual intercept")
-print(MSE(y,ypredictOwn))
+print(MSE(y,ypredictOwn+intercept))
print(f"MSE with Sklearn intercept")
print(MSE(y,ypredictSKL))
@@ -954,6 +955,14 @@ plt.ylabel('MSE')
plt.legend()
plt.show()
+
+We see here, when compared to the code which includes explicitely the
+intercept column, that our MSE value is actually smaller. This is
+because the regularization term does not include the intercept value \( \beta_0 \) in the
+fitting. This applies to Lasso regularization as well.
+
+
+If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
diff --git a/doc/pub/week38/html/week38-solarized.html b/doc/pub/week38/html/week38-solarized.html
index d4666dff6..c3c51e05f 100644
--- a/doc/pub/week38/html/week38-solarized.html
+++ b/doc/pub/week38/html/week38-solarized.html
@@ -810,6 +810,7 @@ What does this mean? And why do we insist on all this? Let us look at some examp
This code shows a simple first-order fit to a data set using the above transformed data, where we consider the role of the intercept first, by either excluding it or including it (code example thanks to Øyvind Sigmundson Schøyen). Here our scaling of the data is done by subtracting the mean values only.
Note also that we do not split the data into training and test.
+
@@ -889,7 +890,7 @@ intercept = np.mean(y_offset - X_offset @ beta)
ypredictOwn = X @ beta
ypredictSKL = skl.predict(X)
print(f"MSE with Manual intercept")
-print(MSE(y,ypredictOwn))
+print(MSE(y,ypredictOwn+intercept))
print(f"MSE with Sklearn intercept")
print(MSE(y,ypredictSKL))
@@ -1088,6 +1089,15 @@ plt.ylabel('MSE')
plt.legend()
plt.show()
+
+We see here, when compared to the code which includes explicitely the
+intercept column, that our MSE value is actually smaller. This is
+because the regularization term does not include the intercept value \( \beta_0 \) in the
+fitting. This applies to Lasso regularization as well.
+
+
+If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
+
This code shows a simple first-order fit to a data set using the above transformed data, where we consider the role of the intercept first, by either excluding it or including it (code example thanks to Øyvind Sigmundson Schøyen). Here our scaling of the data is done by subtracting the mean values only.
Note also that we do not split the data into training and test.
+
@@ -894,7 +895,7 @@ intercept = np.
ypredictOwn = X @ beta
ypredictSKL = skl.predict(X)
print(f"MSE with Manual intercept")
-print(MSE(y,ypredictOwn))
+print(MSE(y,ypredictOwn+intercept))
print(f"MSE with Sklearn intercept")
print(MSE(y,ypredictSKL))
@@ -1093,6 +1094,15 @@ plt.ylabel('
plt.legend()
plt.show()
+
+We see here, when compared to the code which includes explicitely the
+intercept column, that our MSE value is actually smaller. This is
+because the regularization term does not include the intercept value \( \beta_0 \) in the
+fitting. This applies to Lasso regularization as well.
+
+
+If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
+
diff --git a/doc/pub/week38/html/week38.html b/doc/pub/week38/html/week38.html
index ec13a9371..0ce1a3258 100644
--- a/doc/pub/week38/html/week38.html
+++ b/doc/pub/week38/html/week38.html
@@ -815,6 +815,7 @@ What does this mean? And why do we insist on all this? Let us look at some examp
diff --git a/doc/pub/week38/ipynb/ipynb-week38-src.tar.gz b/doc/pub/week38/ipynb/ipynb-week38-src.tar.gz
index a57f336d8..2db2f457a 100644
Binary files a/doc/pub/week38/ipynb/ipynb-week38-src.tar.gz and b/doc/pub/week38/ipynb/ipynb-week38-src.tar.gz differ
diff --git a/doc/pub/week38/ipynb/week38.ipynb b/doc/pub/week38/ipynb/week38.ipynb
index 51f9a0764..41daa5489 100644
--- a/doc/pub/week38/ipynb/week38.ipynb
+++ b/doc/pub/week38/ipynb/week38.ipynb
@@ -818,7 +818,7 @@
"ypredictOwn = X @ beta\n",
"ypredictSKL = skl.predict(X)\n",
"print(f\"MSE with Manual intercept\")\n",
- "print(MSE(y,ypredictOwn))\n",
+ "print(MSE(y,ypredictOwn+intercept))\n",
"print(f\"MSE with Sklearn intercept\")\n",
"print(MSE(y,ypredictSKL))\n",
"\n",
@@ -1039,6 +1039,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "We see here, when compared to the code which includes explicitely the\n",
+ "intercept column, that our MSE value is actually smaller. This is\n",
+ "because the regularization term does not include the intercept value $\\beta_0$ in the\n",
+ "fitting. This applies to Lasso regularization as well.\n",
+ "\n",
+ "If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.\n",
+ "\n",
"## More complicated Example: The Ising model\n",
"\n",
"The one-dimensional Ising model with nearest neighbor interaction, no\n",
diff --git a/doc/src/week38/week38.do.txt b/doc/src/week38/week38.do.txt
index 31ed19ca7..0c1e5acc2 100644
--- a/doc/src/week38/week38.do.txt
+++ b/doc/src/week38/week38.do.txt
@@ -457,6 +457,7 @@ What does this mean? And why do we insist on all this? Let us look at some examp
This code shows a simple first-order fit to a data set using the above transformed data, where we consider the role of the intercept first, by either excluding it or including it (*code example thanks to Øyvind Sigmundson Schøyen*). Here our scaling of the data is done by subtracting the mean values only.
Note also that we do not split the data into training and test.
+
!bc pycod
import numpy as np
import matplotlib.pyplot as plt
@@ -534,7 +535,7 @@ print(f"Sklearn fitted beta (without intercept): {skl.coef_}")
ypredictOwn = X @ beta
ypredictSKL = skl.predict(X)
print(f"MSE with Manual intercept")
-print(MSE(y,ypredictOwn))
+print(MSE(y,ypredictOwn+intercept))
print(f"MSE with Sklearn intercept")
print(MSE(y,ypredictSKL))
@@ -729,7 +730,12 @@ plt.show()
!ec
+We see here, when compared to the code which includes explicitely the
+intercept column, that our MSE value is actually smaller. This is
+because the regularization term does not include the intercept value $\beta_0$ in the
+fitting. This applies to Lasso regularization as well.
+If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
!split
===== More complicated Example: The Ising model =====