more updates
This commit is contained in:
@@ -423,6 +423,7 @@ MathJax.Hub.Config({
|
||||
<p>
|
||||
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 (<em>code example thanks to Øyvind Sigmundson Schøyen</em>). 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.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -502,7 +503,7 @@ intercept <span style="color: #666666">=</span> np<span style="color: #666666">.
|
||||
ypredictOwn <span style="color: #666666">=</span> X <span style="color: #666666">@</span> beta
|
||||
ypredictSKL <span style="color: #666666">=</span> skl<span style="color: #666666">.</span>predict(X)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">f"MSE with Manual intercept"</span>)
|
||||
<span style="color: #008000">print</span>(MSE(y,ypredictOwn))
|
||||
<span style="color: #008000">print</span>(MSE(y,ypredictOwn<span style="color: #666666">+</span>intercept))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">f"MSE with Sklearn intercept"</span>)
|
||||
<span style="color: #008000">print</span>(MSE(y,ypredictSKL))
|
||||
|
||||
|
||||
@@ -508,6 +508,15 @@ plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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.
|
||||
|
||||
<p>
|
||||
If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
|
||||
@@ -676,6 +676,7 @@ What does this mean? And why do we insist on all this? Let us look at some examp
|
||||
<p>
|
||||
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 (<em>code example thanks to Øyvind Sigmundson Schøyen</em>). 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.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -755,7 +756,7 @@ intercept = np.mean(y_offset - X_offset @ beta)
|
||||
ypredictOwn = X @ beta
|
||||
ypredictSKL = skl.predict(X)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">f"MSE with Manual intercept"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y,ypredictOwn))
|
||||
<span style="color: #658b00">print</span>(MSE(y,ypredictOwn+intercept))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">f"MSE with Sklearn intercept"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y,ypredictSKL))
|
||||
|
||||
@@ -954,6 +955,14 @@ plt.ylabel(<span style="color: #CD5555">'MSE'</span>)
|
||||
plt.legend()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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.
|
||||
|
||||
<p>
|
||||
If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
@@ -810,6 +810,7 @@ What does this mean? And why do we insist on all this? Let us look at some examp
|
||||
<p>
|
||||
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 (<em>code example thanks to Øyvind Sigmundson Schøyen</em>). 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.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
@@ -889,7 +890,7 @@ intercept = np.mean(y_offset - X_offset @ beta)
|
||||
ypredictOwn = X @ beta
|
||||
ypredictSKL = skl.predict(X)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">f"MSE with Manual intercept"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y,ypredictOwn))
|
||||
<span style="color: #658b00">print</span>(MSE(y,ypredictOwn+intercept))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">f"MSE with Sklearn intercept"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y,ypredictSKL))
|
||||
|
||||
@@ -1088,6 +1089,15 @@ plt.ylabel(<span style="color: #CD5555">'MSE'</span>)
|
||||
plt.legend()
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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.
|
||||
|
||||
<p>
|
||||
If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
|
||||
@@ -815,6 +815,7 @@ What does this mean? And why do we insist on all this? Let us look at some examp
|
||||
<p>
|
||||
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 (<em>code example thanks to Øyvind Sigmundson Schøyen</em>). 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.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -894,7 +895,7 @@ intercept <span style="color: #666666">=</span> np<span style="color: #666666">.
|
||||
ypredictOwn <span style="color: #666666">=</span> X <span style="color: #666666">@</span> beta
|
||||
ypredictSKL <span style="color: #666666">=</span> skl<span style="color: #666666">.</span>predict(X)
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">f"MSE with Manual intercept"</span>)
|
||||
<span style="color: #008000">print</span>(MSE(y,ypredictOwn))
|
||||
<span style="color: #008000">print</span>(MSE(y,ypredictOwn<span style="color: #666666">+</span>intercept))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">f"MSE with Sklearn intercept"</span>)
|
||||
<span style="color: #008000">print</span>(MSE(y,ypredictSKL))
|
||||
|
||||
@@ -1093,6 +1094,15 @@ plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'
|
||||
plt<span style="color: #666666">.</span>legend()
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
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.
|
||||
|
||||
<p>
|
||||
If we stay with ordinary least squares, there is no dependence on the value of the intercept when we perform the fitting.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
|
||||
Binary file not shown.
@@ -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",
|
||||
|
||||
@@ -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 =====
|
||||
|
||||
Reference in New Issue
Block a user