update
This commit is contained in:
@@ -136,17 +136,19 @@ September 2
|
||||
\subsection{Preamble: Note on writing reports, using reference material, AI and other tools}
|
||||
|
||||
We want you to answer the three different projects by handing in
|
||||
reports written like a standard scientific/technical report. The links
|
||||
at \href{{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}{\nolinkurl{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}
|
||||
Furthermore, at the same link,
|
||||
you can find examples of previous reports. How to write reports will
|
||||
also be discussed during the various lab sessions. Please do ask us if you are in doubt.
|
||||
reports written like a standard scientific/technical report. The
|
||||
links at
|
||||
\href{{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}{\nolinkurl{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}
|
||||
contain more information. There you can find examples of previous
|
||||
reports, the projects themselves, how we rade reports etc. How to
|
||||
write reports will also be discussed during the various lab
|
||||
sessions. Please do ask us if you are in doubt.
|
||||
|
||||
When using codes and material from other sources, you should refer to
|
||||
these in the bibliography of your report, indicating wherefrom you for
|
||||
example got the code, whether this is from the lecture notes,
|
||||
softwares like Scikit-Learn, TensorFlow, PyTorch or other sources such
|
||||
AI software. These should always be cited correctly. How to cite some
|
||||
softwares like Scikit-Learn, TensorFlow, PyTorch or other sources. These sources
|
||||
should always be cited correctly. How to cite some
|
||||
of the libraries is often indicated from their corresponding GitHub
|
||||
sites or websites, see for example how to cite Scikit-Learn at
|
||||
\href{{https://scikit-learn.org/dev/about.html}}{\nolinkurl{https://scikit-learn.org/dev/about.html}}.
|
||||
@@ -175,7 +177,7 @@ other data sets, make sure these are sets used for regression problems
|
||||
\subsection{Regression analysis and resampling methods}
|
||||
|
||||
The main aim of this project is to study in more detail various
|
||||
regression methods, including the Ordinary Least Squares (OLS) method.
|
||||
regression methods, including Ordinary Least Squares (OLS) reegression, Ridge regression and LASSO regression.
|
||||
In addition to the scientific part, in this course we want also to
|
||||
give you an experience in writing scientific reports.
|
||||
|
||||
@@ -189,24 +191,23 @@ f(x) = \frac{1}{1+25x^2}.
|
||||
|
||||
Our first step will be to perform an OLS regression analysis of this
|
||||
function, trying out a polynomial fit with an $x$ dependence of the
|
||||
form $[x,x^2,\dots]$. We can use a uniform distribution to set up the
|
||||
form $[x,x^2,\dots]$. You can use a uniform distribution to set up the
|
||||
arrays of values for $x \in [-1,1]$, or alternatively use a fixed step size.
|
||||
Thereafter we will repeat much of the
|
||||
same procedure using the Ridge and Lasso regression methods,
|
||||
introducing thus a dependence on the hyperparameter (penalty) $\lambda$.
|
||||
Thereafter we will repeat many of the same steps when using the Ridge and Lasso regression methods,
|
||||
introducing thereby a dependence on the hyperparameter (penalty) $\lambda$.
|
||||
|
||||
We will also include bootstrap as a resampling technique in order to
|
||||
study the so-called \textbf{bias-variance tradeoff}. After that we will
|
||||
include the cross-validation technique.
|
||||
include the so-called cross-validation technique.
|
||||
|
||||
\paragraph{Part a : Ordinary Least Square (OLS) for the Runge function.}
|
||||
We will generate our own dataset for a function
|
||||
We will generate our own dataset for abovementioned function
|
||||
$\mathrm{Runge}(x)$ function with $x\in [-1,1]$. You should explore also the addition
|
||||
of an added stochastic noise to this function using the normal
|
||||
distribution $N(0,1)$.
|
||||
|
||||
\emph{Write your own code} (using for example the pseudoinverse function \textbf{pinv} from \textbf{Numpy} ) and perform a standard \textbf{ordinary least square regression}
|
||||
analysis using polynomials in $x$ up to order $15$. Explore the dependence on the number of data points and the polynomial degree.
|
||||
analysis using polynomials in $x$ up to order $15$ or higher. Explore the dependence on the number of data points and the polynomial degree.
|
||||
|
||||
Evaluate the mean Squared error (MSE)
|
||||
|
||||
@@ -228,12 +229,12 @@ where we have defined the mean value of $\bm{y}$ as
|
||||
\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.
|
||||
\]
|
||||
|
||||
Plot the resulting scores (MSE and R$^2$) as functions of the polynomial degree (here up to polymial degree 20).
|
||||
Plot the resulting scores (MSE and R$^2$) as functions of the polynomial degree (here up to polymial degree 15).
|
||||
Plot also the parameters $\theta$ as you increase the order of the polynomial. Comment your results.
|
||||
|
||||
Your code has to include a scaling/centering of the data (for example by
|
||||
subtracting the mean value), and
|
||||
a split of the data in training and test data. For this exercise you can
|
||||
a split of the data in training and test data. For the scaling you can
|
||||
either write your own code or use for example the function for
|
||||
splitting training data provided by the library \textbf{Scikit-Learn} (make
|
||||
sure you have installed it). This function is called
|
||||
@@ -253,10 +254,10 @@ On scaling, we recommend reading the following section from the scikit-learn sof
|
||||
|
||||
\paragraph{Part b: Adding Ridge regression for the Runge function.}
|
||||
Write your own code for the Ridge method as done in the previous
|
||||
exercise. The lecture notes from week 35 and 36 contain more information. Furthermore, the exercise from week 36 is something you can reuse here.
|
||||
exercise. The lecture notes from week 35 and 36 contain more information. Furthermore, the results from the exercise set from week 36 is something you can reuse here.
|
||||
|
||||
Perform the same analysis as you did in the previous exercise but now for different values of $\lambda$. Compare and
|
||||
analyze your results with those obtained in part a) with the ordinary least squares method. Study the
|
||||
analyze your results with those obtained in part a) with the OLS method. Study the
|
||||
dependence on $\lambda$.
|
||||
|
||||
\paragraph{Part c: Writing your own gradient descent code.}
|
||||
@@ -274,14 +275,14 @@ We keep our focus on OLS and Ridge regression and update our code for
|
||||
the gradient descent method by including \textbf{momentum}, \textbf{ADAgrad},
|
||||
\textbf{RMSprop} and \textbf{ADAM} as methods fro iteratively updating your learning
|
||||
rate. Discuss the results and compare the different methods applied to
|
||||
the one-dimensional Runge function.
|
||||
the one-dimensional Runge function. The lecture notes from week 37 contain several examples on how to implement these methods.
|
||||
|
||||
\paragraph{Part e: Writing our own code for Lasso regression.}
|
||||
LASSO regression (see lecture slides from week 36 and week 37)
|
||||
represents our first encounter with a machine learning method which
|
||||
cannot be solved through analytical expressions. Use the gradient
|
||||
cannot be solved through analytical expressions (as in OLS and Ridge regression). Use the gradient
|
||||
descent methods you developed in parts c) and d) to solve the LASSO
|
||||
optimization problem. You can compare your results using
|
||||
optimization problem. You can compare your results with
|
||||
the functionalities of \textbf{Scikit-Learn}.
|
||||
|
||||
Discuss (critically) your results for the Runge function from OLS,
|
||||
@@ -289,13 +290,15 @@ Ridge and LASSO regression using the various gradient descent
|
||||
approaches.
|
||||
|
||||
\paragraph{Part f: Stochastic gradient descent.}
|
||||
Our last gradient step is to include stochastic gradient descent using the
|
||||
same methods to update the learning rates as in parts c-e).
|
||||
Compare and discuss your results with and without stochastic gradient and give a critical assessment of the various methods.
|
||||
Our last gradient step is to include stochastic gradient descent using
|
||||
the same methods to update the learning rates as in parts c-e).
|
||||
Compare and discuss your results with and without stochastic gradient
|
||||
and give a critical assessment of the various methods.
|
||||
|
||||
\paragraph{Part g: Bias-variance trade-off and resampling techniques.}
|
||||
Our aim here is to study the bias-variance trade-off by implementing the \textbf{bootstrap} resampling technique.
|
||||
\textbf{We will only use the simpler ordinary least squares here}.
|
||||
Our aim here is to study the bias-variance trade-off by implementing
|
||||
the \textbf{bootstrap} resampling technique. \textbf{We will only use the simpler
|
||||
ordinary least squares here}.
|
||||
|
||||
With a code which does OLS and includes resampling techniques,
|
||||
we will now discuss the bias-variance trade-off in the context of
|
||||
@@ -303,11 +306,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!
|
||||
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! You may also need to increase the
|
||||
polynomial order and play around with the number of data points as
|
||||
well (see also the exercise set from week 35).
|
||||
|
||||
With this result we move on to the bias-variance trade-off analysis.
|
||||
|
||||
@@ -315,7 +321,7 @@ Consider a
|
||||
dataset $\mathcal{L}$ consisting of the data
|
||||
$\mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\}$.
|
||||
|
||||
As in part d), we assume that the true data is generated from a noisy model
|
||||
We assume that the true data is generated from a noisy model
|
||||
|
||||
\[
|
||||
\bm{y}=f(\boldsymbol{x}) + \bm{\epsilon}.
|
||||
@@ -326,24 +332,27 @@ deviation $\sigma^2$.
|
||||
|
||||
In our derivation of the ordinary least squares method we defined then
|
||||
an approximation to the function $f$ in terms of the parameters
|
||||
$\bm{\beta}$ and the design matrix $\bm{X}$ which embody our model,
|
||||
that is $\bm{\tilde{y}}=\bm{X}\bm{\beta}$.
|
||||
$\bm{\theta}$ and the design matrix $\bm{X}$ which embody our model,
|
||||
that is $\bm{\tilde{y}}=\bm{X}\bm{\theta}$.
|
||||
|
||||
The parameters $\bm{\beta}$ are in turn found by optimizing the mean
|
||||
The parameters $\bm{\theta}$ are in turn found by optimizing the mean
|
||||
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].
|
||||
C(\bm{X},\bm{\theta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right].
|
||||
\]
|
||||
Here the expected value $\mathbb{E}$ is the sample value.
|
||||
|
||||
Show that you can rewrite this in terms of a term which contains the variance of the model itself (the so-called variance term), a
|
||||
term which measures the deviation from the true data and the mean value of the model (the bias term) and finally the variance of the noise.
|
||||
Show that you can rewrite this in terms of a term which contains the
|
||||
variance of the model itself (the so-called variance term), a term
|
||||
which measures the deviation from the true data and the mean value of
|
||||
the model (the bias term) and finally the variance of the noise.
|
||||
|
||||
That is, show that
|
||||
\[
|
||||
\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\mathrm{Bias}[\tilde{y}]+\mathrm{var}[\tilde{y}]+\sigma^2,
|
||||
\]
|
||||
with
|
||||
with (we approximate $f(\bm{x})\approx \bm{y}$)
|
||||
\[
|
||||
\mathrm{Bias}[\tilde{y}]=\mathbb{E}\left[\left(\bm{y}-\mathbb{E}\left[\bm{\tilde{y}}\right]\right)^2\right],
|
||||
\]
|
||||
@@ -351,8 +360,13 @@ and
|
||||
\[
|
||||
\mathrm{var}[\tilde{y}]=\mathbb{E}\left[\left(\tilde{\bm{y}}-\mathbb{E}\left[\bm{\tilde{y}}\right]\right)^2\right]=\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2.
|
||||
\]
|
||||
The answer to this exercise should be included in the theory part of the report. This exercise is also part of the weekly exercises of week 38.
|
||||
Explain what the terms mean and discuss their interpretations.
|
||||
|
||||
\textbf{Important note}: Since the function $f(x)$ is unknown, in order to be able to evalute the bias, we replace $f(\bm{x})$ in the expression for the bias with $\bm{y}$.
|
||||
|
||||
The answer to this exercise should be included in the theory part of
|
||||
the report. This exercise is also part of the weekly exercises of
|
||||
week 38. Explain what the terms mean and discuss their
|
||||
interpretations.
|
||||
|
||||
Perform then a bias-variance analysis of the Runge function by
|
||||
studying the MSE value as function of the complexity of your model.
|
||||
@@ -366,14 +380,15 @@ You can follow the code example in the jupyter-book at \href{{https://compphysic
|
||||
The aim here is to implement another widely popular
|
||||
resampling technique, the so-called cross-validation method.
|
||||
|
||||
Implement the $k$-fold cross-validation algorithm (feel free to use the functionality of \textbf{Scikit-Learn} or write your own code) and evaluate again the MSE function resulting
|
||||
from the test folds.
|
||||
Implement the $k$-fold cross-validation algorithm (feel free to use
|
||||
the functionality of \textbf{Scikit-Learn} or write your own code) and
|
||||
evaluate again the MSE function resulting from the test folds.
|
||||
|
||||
Compare the MSE you get from your cross-validation code with the one
|
||||
you got from your \textbf{bootstrap} code. Comment your results. Try $5-10$
|
||||
folds.
|
||||
you got from your \textbf{bootstrap} code from the previous exercise. Comment and interpret your results.
|
||||
|
||||
In addition to using the ordinary least squares method, you should include both Ridge and Lasso regression in the analysis.
|
||||
In addition to using the ordinary least squares method, you should
|
||||
include both Ridge and Lasso regression in the final analysis.
|
||||
|
||||
\subsection{Background literature}
|
||||
|
||||
|
||||
@@ -110,17 +110,19 @@ September 2
|
||||
\subsection*{Preamble: Note on writing reports, using reference material, AI and other tools}
|
||||
|
||||
We want you to answer the three different projects by handing in
|
||||
reports written like a standard scientific/technical report. The links
|
||||
at \href{{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}{\nolinkurl{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}
|
||||
Furthermore, at the same link,
|
||||
you can find examples of previous reports. How to write reports will
|
||||
also be discussed during the various lab sessions. Please do ask us if you are in doubt.
|
||||
reports written like a standard scientific/technical report. The
|
||||
links at
|
||||
\href{{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}{\nolinkurl{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Projects}}
|
||||
contain more information. There you can find examples of previous
|
||||
reports, the projects themselves, how we rade reports etc. How to
|
||||
write reports will also be discussed during the various lab
|
||||
sessions. Please do ask us if you are in doubt.
|
||||
|
||||
When using codes and material from other sources, you should refer to
|
||||
these in the bibliography of your report, indicating wherefrom you for
|
||||
example got the code, whether this is from the lecture notes,
|
||||
softwares like Scikit-Learn, TensorFlow, PyTorch or other sources such
|
||||
AI software. These should always be cited correctly. How to cite some
|
||||
softwares like Scikit-Learn, TensorFlow, PyTorch or other sources. These sources
|
||||
should always be cited correctly. How to cite some
|
||||
of the libraries is often indicated from their corresponding GitHub
|
||||
sites or websites, see for example how to cite Scikit-Learn at
|
||||
\href{{https://scikit-learn.org/dev/about.html}}{\nolinkurl{https://scikit-learn.org/dev/about.html}}.
|
||||
@@ -149,7 +151,7 @@ other data sets, make sure these are sets used for regression problems
|
||||
\subsection*{Regression analysis and resampling methods}
|
||||
|
||||
The main aim of this project is to study in more detail various
|
||||
regression methods, including the Ordinary Least Squares (OLS) method.
|
||||
regression methods, including Ordinary Least Squares (OLS) reegression, Ridge regression and LASSO regression.
|
||||
In addition to the scientific part, in this course we want also to
|
||||
give you an experience in writing scientific reports.
|
||||
|
||||
@@ -163,24 +165,23 @@ f(x) = \frac{1}{1+25x^2}.
|
||||
|
||||
Our first step will be to perform an OLS regression analysis of this
|
||||
function, trying out a polynomial fit with an $x$ dependence of the
|
||||
form $[x,x^2,\dots]$. We can use a uniform distribution to set up the
|
||||
form $[x,x^2,\dots]$. You can use a uniform distribution to set up the
|
||||
arrays of values for $x \in [-1,1]$, or alternatively use a fixed step size.
|
||||
Thereafter we will repeat much of the
|
||||
same procedure using the Ridge and Lasso regression methods,
|
||||
introducing thus a dependence on the hyperparameter (penalty) $\lambda$.
|
||||
Thereafter we will repeat many of the same steps when using the Ridge and Lasso regression methods,
|
||||
introducing thereby a dependence on the hyperparameter (penalty) $\lambda$.
|
||||
|
||||
We will also include bootstrap as a resampling technique in order to
|
||||
study the so-called \textbf{bias-variance tradeoff}. After that we will
|
||||
include the cross-validation technique.
|
||||
include the so-called cross-validation technique.
|
||||
|
||||
\paragraph{Part a : Ordinary Least Square (OLS) for the Runge function.}
|
||||
We will generate our own dataset for a function
|
||||
We will generate our own dataset for abovementioned function
|
||||
$\mathrm{Runge}(x)$ function with $x\in [-1,1]$. You should explore also the addition
|
||||
of an added stochastic noise to this function using the normal
|
||||
distribution $N(0,1)$.
|
||||
|
||||
\emph{Write your own code} (using for example the pseudoinverse function \textbf{pinv} from \textbf{Numpy} ) and perform a standard \textbf{ordinary least square regression}
|
||||
analysis using polynomials in $x$ up to order $15$. Explore the dependence on the number of data points and the polynomial degree.
|
||||
analysis using polynomials in $x$ up to order $15$ or higher. Explore the dependence on the number of data points and the polynomial degree.
|
||||
|
||||
Evaluate the mean Squared error (MSE)
|
||||
|
||||
@@ -202,12 +203,12 @@ where we have defined the mean value of $\bm{y}$ as
|
||||
\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.
|
||||
\]
|
||||
|
||||
Plot the resulting scores (MSE and R$^2$) as functions of the polynomial degree (here up to polymial degree 20).
|
||||
Plot the resulting scores (MSE and R$^2$) as functions of the polynomial degree (here up to polymial degree 15).
|
||||
Plot also the parameters $\theta$ as you increase the order of the polynomial. Comment your results.
|
||||
|
||||
Your code has to include a scaling/centering of the data (for example by
|
||||
subtracting the mean value), and
|
||||
a split of the data in training and test data. For this exercise you can
|
||||
a split of the data in training and test data. For the scaling you can
|
||||
either write your own code or use for example the function for
|
||||
splitting training data provided by the library \textbf{Scikit-Learn} (make
|
||||
sure you have installed it). This function is called
|
||||
@@ -227,10 +228,10 @@ On scaling, we recommend reading the following section from the scikit-learn sof
|
||||
|
||||
\paragraph{Part b: Adding Ridge regression for the Runge function.}
|
||||
Write your own code for the Ridge method as done in the previous
|
||||
exercise. The lecture notes from week 35 and 36 contain more information. Furthermore, the exercise from week 36 is something you can reuse here.
|
||||
exercise. The lecture notes from week 35 and 36 contain more information. Furthermore, the results from the exercise set from week 36 is something you can reuse here.
|
||||
|
||||
Perform the same analysis as you did in the previous exercise but now for different values of $\lambda$. Compare and
|
||||
analyze your results with those obtained in part a) with the ordinary least squares method. Study the
|
||||
analyze your results with those obtained in part a) with the OLS method. Study the
|
||||
dependence on $\lambda$.
|
||||
|
||||
\paragraph{Part c: Writing your own gradient descent code.}
|
||||
@@ -248,14 +249,14 @@ We keep our focus on OLS and Ridge regression and update our code for
|
||||
the gradient descent method by including \textbf{momentum}, \textbf{ADAgrad},
|
||||
\textbf{RMSprop} and \textbf{ADAM} as methods fro iteratively updating your learning
|
||||
rate. Discuss the results and compare the different methods applied to
|
||||
the one-dimensional Runge function.
|
||||
the one-dimensional Runge function. The lecture notes from week 37 contain several examples on how to implement these methods.
|
||||
|
||||
\paragraph{Part e: Writing our own code for Lasso regression.}
|
||||
LASSO regression (see lecture slides from week 36 and week 37)
|
||||
represents our first encounter with a machine learning method which
|
||||
cannot be solved through analytical expressions. Use the gradient
|
||||
cannot be solved through analytical expressions (as in OLS and Ridge regression). Use the gradient
|
||||
descent methods you developed in parts c) and d) to solve the LASSO
|
||||
optimization problem. You can compare your results using
|
||||
optimization problem. You can compare your results with
|
||||
the functionalities of \textbf{Scikit-Learn}.
|
||||
|
||||
Discuss (critically) your results for the Runge function from OLS,
|
||||
@@ -263,13 +264,15 @@ Ridge and LASSO regression using the various gradient descent
|
||||
approaches.
|
||||
|
||||
\paragraph{Part f: Stochastic gradient descent.}
|
||||
Our last gradient step is to include stochastic gradient descent using the
|
||||
same methods to update the learning rates as in parts c-e).
|
||||
Compare and discuss your results with and without stochastic gradient and give a critical assessment of the various methods.
|
||||
Our last gradient step is to include stochastic gradient descent using
|
||||
the same methods to update the learning rates as in parts c-e).
|
||||
Compare and discuss your results with and without stochastic gradient
|
||||
and give a critical assessment of the various methods.
|
||||
|
||||
\paragraph{Part g: Bias-variance trade-off and resampling techniques.}
|
||||
Our aim here is to study the bias-variance trade-off by implementing the \textbf{bootstrap} resampling technique.
|
||||
\textbf{We will only use the simpler ordinary least squares here}.
|
||||
Our aim here is to study the bias-variance trade-off by implementing
|
||||
the \textbf{bootstrap} resampling technique. \textbf{We will only use the simpler
|
||||
ordinary least squares here}.
|
||||
|
||||
With a code which does OLS and includes resampling techniques,
|
||||
we will now discuss the bias-variance trade-off in the context of
|
||||
@@ -277,11 +280,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!
|
||||
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! You may also need to increase the
|
||||
polynomial order and play around with the number of data points as
|
||||
well (see also the exercise set from week 35).
|
||||
|
||||
With this result we move on to the bias-variance trade-off analysis.
|
||||
|
||||
@@ -289,7 +295,7 @@ Consider a
|
||||
dataset $\mathcal{L}$ consisting of the data
|
||||
$\mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\}$.
|
||||
|
||||
As in part d), we assume that the true data is generated from a noisy model
|
||||
We assume that the true data is generated from a noisy model
|
||||
|
||||
\[
|
||||
\bm{y}=f(\boldsymbol{x}) + \bm{\epsilon}.
|
||||
@@ -300,24 +306,27 @@ deviation $\sigma^2$.
|
||||
|
||||
In our derivation of the ordinary least squares method we defined then
|
||||
an approximation to the function $f$ in terms of the parameters
|
||||
$\bm{\beta}$ and the design matrix $\bm{X}$ which embody our model,
|
||||
that is $\bm{\tilde{y}}=\bm{X}\bm{\beta}$.
|
||||
$\bm{\theta}$ and the design matrix $\bm{X}$ which embody our model,
|
||||
that is $\bm{\tilde{y}}=\bm{X}\bm{\theta}$.
|
||||
|
||||
The parameters $\bm{\beta}$ are in turn found by optimizing the mean
|
||||
The parameters $\bm{\theta}$ are in turn found by optimizing the mean
|
||||
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].
|
||||
C(\bm{X},\bm{\theta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right].
|
||||
\]
|
||||
Here the expected value $\mathbb{E}$ is the sample value.
|
||||
|
||||
Show that you can rewrite this in terms of a term which contains the variance of the model itself (the so-called variance term), a
|
||||
term which measures the deviation from the true data and the mean value of the model (the bias term) and finally the variance of the noise.
|
||||
Show that you can rewrite this in terms of a term which contains the
|
||||
variance of the model itself (the so-called variance term), a term
|
||||
which measures the deviation from the true data and the mean value of
|
||||
the model (the bias term) and finally the variance of the noise.
|
||||
|
||||
That is, show that
|
||||
\[
|
||||
\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\mathrm{Bias}[\tilde{y}]+\mathrm{var}[\tilde{y}]+\sigma^2,
|
||||
\]
|
||||
with
|
||||
with (we approximate $f(\bm{x})\approx \bm{y}$)
|
||||
\[
|
||||
\mathrm{Bias}[\tilde{y}]=\mathbb{E}\left[\left(\bm{y}-\mathbb{E}\left[\bm{\tilde{y}}\right]\right)^2\right],
|
||||
\]
|
||||
@@ -325,8 +334,13 @@ and
|
||||
\[
|
||||
\mathrm{var}[\tilde{y}]=\mathbb{E}\left[\left(\tilde{\bm{y}}-\mathbb{E}\left[\bm{\tilde{y}}\right]\right)^2\right]=\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2.
|
||||
\]
|
||||
The answer to this exercise should be included in the theory part of the report. This exercise is also part of the weekly exercises of week 38.
|
||||
Explain what the terms mean and discuss their interpretations.
|
||||
|
||||
\textbf{Important note}: Since the function $f(x)$ is unknown, in order to be able to evalute the bias, we replace $f(\bm{x})$ in the expression for the bias with $\bm{y}$.
|
||||
|
||||
The answer to this exercise should be included in the theory part of
|
||||
the report. This exercise is also part of the weekly exercises of
|
||||
week 38. Explain what the terms mean and discuss their
|
||||
interpretations.
|
||||
|
||||
Perform then a bias-variance analysis of the Runge function by
|
||||
studying the MSE value as function of the complexity of your model.
|
||||
@@ -340,14 +354,15 @@ You can follow the code example in the jupyter-book at \href{{https://compphysic
|
||||
The aim here is to implement another widely popular
|
||||
resampling technique, the so-called cross-validation method.
|
||||
|
||||
Implement the $k$-fold cross-validation algorithm (feel free to use the functionality of \textbf{Scikit-Learn} or write your own code) and evaluate again the MSE function resulting
|
||||
from the test folds.
|
||||
Implement the $k$-fold cross-validation algorithm (feel free to use
|
||||
the functionality of \textbf{Scikit-Learn} or write your own code) and
|
||||
evaluate again the MSE function resulting from the test folds.
|
||||
|
||||
Compare the MSE you get from your cross-validation code with the one
|
||||
you got from your \textbf{bootstrap} code. Comment your results. Try $5-10$
|
||||
folds.
|
||||
you got from your \textbf{bootstrap} code from the previous exercise. Comment and interpret your results.
|
||||
|
||||
In addition to using the ordinary least squares method, you should include both Ridge and Lasso regression in the analysis.
|
||||
In addition to using the ordinary least squares method, you should
|
||||
include both Ridge and Lasso regression in the final analysis.
|
||||
|
||||
\subsection*{Background literature}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user