cleaning up typos and inconsistencies in project 1
This commit is contained in:
@@ -8,8 +8,9 @@ DATE: today
|
||||
|
||||
The main aim of this project is to study in more detail various
|
||||
regression methods, including the Ordinary Least Squares (OLS) method,
|
||||
Ridge regression and finally Lasso regression.
|
||||
The methods are in turn combined with resampling techniques like the bootstrap method and cross validation.
|
||||
Ridge regression and finally Lasso regression. Ridge regression will be discussed during the Friday lecture of week 36 while Lasso Regression will be discussed during the lectures of week 37.
|
||||
|
||||
The methods are in turn combined with resampling techniques like the bootstrap method and cross validation. These are discussed during weeks 36 and 37.
|
||||
|
||||
We will first study how to fit polynomials to a specific
|
||||
two-dimensional function called "Franke's
|
||||
@@ -50,7 +51,7 @@ beyond the second-order polynomials metioned above and explore
|
||||
which polynomial fits the data best.
|
||||
|
||||
|
||||
The Python fucntion for the Franke function is included here (it performs also a three-dimensional plot of it)
|
||||
The Python code for the Franke function is included here (it performs also a three-dimensional plot of it)
|
||||
!bc pycod
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -95,7 +96,7 @@ plt.show()
|
||||
!ec
|
||||
|
||||
|
||||
=== Part a): Ordinary Least Square on the Franke function with resampling ===
|
||||
=== Part a): Ordinary Least Square (OLS) on the Franke function ===
|
||||
|
||||
We will generate our own dataset for a function
|
||||
$\mathrm{FrankeFunction}(x,y)$ with $x,y \in [0,1]$. The function
|
||||
@@ -107,7 +108,7 @@ distribution $\cal{N}(0,1)$.
|
||||
value decomposition from e.g., _numpy_ ) or use your code from
|
||||
homeworks 1 and 2 and perform a standard least square regression
|
||||
analysis using polynomials in $x$ and $y$ up to fifth order. Find the
|
||||
confidence intervals of the parameters $\beta$ by computing their
|
||||
"confidence intervals":"https://en.wikipedia.org/wiki/Confidence_interval" of the parameters (estimators) $\beta$ by computing their
|
||||
variances, evaluate the Mean Squared error (MSE)
|
||||
|
||||
!bt
|
||||
@@ -134,9 +135,14 @@ where we have defined the mean value of $\hat{y}$ as
|
||||
\]
|
||||
!et
|
||||
|
||||
Your code has to include a scaling of the data (for example by subtracting the mean value, see also homework set 2 for examples) and a split of the data in training and test data. For this part you can either write your own code or use for example the
|
||||
function for splitting training data provided by the library _Scikit-Learn_ (make sure you have installed it).
|
||||
This function is called $train\_test\_split$. Similarly, and see the solution to homework set 2, exercise 2, you can use the data normalization functionality of _Scikit-Learn_.
|
||||
Your code has to include a scaling of the data (for example by
|
||||
subtracting the mean value, see also "homework set 2":"https://compphysics.github.io/MachineLearning/doc/Projects/2020/hw2/html/hw2-bs.html" for examples) and
|
||||
a split of the data in training and test data. For this part you can
|
||||
either write your own code or use for example the function for
|
||||
splitting training data provided by the library _Scikit-Learn_ (make
|
||||
sure you have installed it). This function is called
|
||||
$train\_test\_split$. Similarly, and see the solution to "homework set 2, exercise 2":"https://compphysics.github.io/MachineLearning/doc/Projects/2020/hw2/html/hw2-bs.html", you can use the data normalization functionality of
|
||||
_Scikit-Learn_.
|
||||
|
||||
It is normal in essentially all Machine Learning studies to split the
|
||||
data in a training set and a test set (eventually also an additional
|
||||
@@ -150,7 +156,7 @@ approximately $2/3$ to $4/5$ of the data as training data.
|
||||
|
||||
|
||||
|
||||
=== Part b): Bias-variance trade-off ===
|
||||
=== Part b): Bias-variance trade-off and resamplng techniques ===
|
||||
|
||||
Our aim here is to study the bias-variance trade-off by implementing the _bootstrap_ resampling technique.
|
||||
|
||||
@@ -160,6 +166,14 @@ continuous predictions such as regression. However, many of the
|
||||
intuitions and ideas discussed here also carry over to classification
|
||||
tasks and basically all Machine Learning algorithms.
|
||||
|
||||
Before you perform an analysis of the bias-variance trade-off on your test data, make
|
||||
first a figure similar to Fig. 2.11 of Hastie, Tibshirani, and
|
||||
Friedman. Figure 2.11 of this reference displays only the test and training MSEs. The test MSE can be used to
|
||||
indicate possible regions of low/high bias and variance. You will most likely not get an
|
||||
equally smooth curve!
|
||||
|
||||
With this result we move on to the bias-variance trade-off analysis.
|
||||
|
||||
Consider a
|
||||
dataset $\mathcal{L}$ consisting of the data
|
||||
$\mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\}$.
|
||||
@@ -188,6 +202,7 @@ squared error via the so-called cost function
|
||||
C(\bm{X},\bm{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right].
|
||||
\]
|
||||
!et
|
||||
Here the expected value $\mathbb{E}$ is the sample value.
|
||||
|
||||
Show that you can rewrite this as
|
||||
!bt
|
||||
@@ -199,23 +214,23 @@ Show that you can rewrite this as
|
||||
Explain what the terms mean, which one is the bias and which one is
|
||||
the variance and discuss their interpretations.
|
||||
|
||||
Perform then a bias-variance analysis of the Franke function by
|
||||
studying the MSE value as function of the complexity of your model.
|
||||
|
||||
Discuss the bias and variance trade-off as function
|
||||
of your model complexity (the degree of the polynomial) and the number
|
||||
of data points, and possibly also your training and test data using the _bootstrap_ resampling method.
|
||||
|
||||
However, before you perform an analysis of the bias-variance trade-off on your test data, make
|
||||
first a figure similar to Fig. 2.11 of Hastie, Tibshirani, and
|
||||
Friedman. Figure 2.11 of this reference displays only the test and training MSEs (and bias-variance analysis of the test data) while indicating possible regions of low/high bias and variance. You will most likely not get an
|
||||
equally smooth curve! Note also that when you calculate the bias, in all applications you don't know the function values $f_i$. You would hence replace them with the actual data points $y_i$.
|
||||
Note also that when you calculate the bias, in all applications you don't know the function values $f_i$. You would hence replace them with the actual data points $y_i$.
|
||||
|
||||
After having produced a curve similar to Figure 2.11, perform then a bias-variance analysis of your test data. Here you should use the _bootstra_ resampling technique.
|
||||
|
||||
=== Part c) Cross-validation as resampling techniques, adding more complexity ===
|
||||
|
||||
|
||||
The aim here is to write our own code for another widely popular resampling technique, the so-called cross-validation method.
|
||||
Again, before you start with cross-validation approach, you should scale your data and split it in test and training data as you did earlier.
|
||||
The aim here is to write your own code for another widely popular
|
||||
resampling technique, the so-called cross-validation method. Again,
|
||||
before you start with cross-validation approach, you should scale your
|
||||
data and split it in test and training data as you did earlier.
|
||||
Perform a resampling of the data where you split the data in training
|
||||
data and test data using for example
|
||||
|
||||
@@ -224,7 +239,7 @@ data and test data using for example
|
||||
Implement the $k$-fold cross-validation algorithm (write your own
|
||||
code) and evaluate again the MSE function resulting
|
||||
from the test data. You can compare your own code with that from
|
||||
_Scikit-Learn_ if needed. You can alternatively write your own bootstrap code.
|
||||
_Scikit-Learn_ if needed.
|
||||
|
||||
Compare the MSE you get from your cross-validation code with the one you got from your _bootstrap_ code.
|
||||
You can also compare your own cross-validation code with the one provided by _Scikit-Learn_.
|
||||
|
||||
@@ -38,7 +38,7 @@ system doconce split_html $html.html --method=split --pagination --nav_button=bo
|
||||
|
||||
# Ordinary plain LaTeX document
|
||||
system doconce format pdflatex $name --print_latex_style=trac --latex_admon=paragraph $opt
|
||||
system doconce ptex2tex $name envir=print
|
||||
system doconce ptex2tex $name envir=verbatim
|
||||
# Add special packages
|
||||
doconce subst "% Add user's preamble" "\g<1>\n\\usepackage{simplewick}" $name.tex
|
||||
doconce replace 'section{' 'section*{' $name.tex
|
||||
|
||||
Reference in New Issue
Block a user