more updates
This commit is contained in:
@@ -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