more updates

This commit is contained in:
Morten Hjorth-Jensen
2021-09-23 09:17:15 +02:00
parent d69f43cbaf
commit ee68e6816a
8 changed files with 58 additions and 6 deletions
+7 -1
View File
@@ -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 =====