@@ -314,7 +314,7 @@ approximately \( 2/3 \) to \( 4/5 \) of the data as training data.
Implement the \( k \)-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the \( R^2 \) functions resulting
+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.
diff --git a/doc/Projects/2019/Project1/html/Project1-bs.html b/doc/Projects/2019/Project1/html/Project1-bs.html
index 12a5c36b1..4d61541a4 100644
--- a/doc/Projects/2019/Project1/html/Project1-bs.html
+++ b/doc/Projects/2019/Project1/html/Project1-bs.html
@@ -159,7 +159,7 @@ MathJax.Hub.Config({
Department of Physics, University of Oslo, Norway
-
Aug 29, 2019
+
Sep 13, 2019
@@ -314,7 +314,7 @@ approximately \( 2/3 \) to \( 4/5 \) of the data as training data.
Implement the \( k \)-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the \( R^2 \) functions resulting
+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.
diff --git a/doc/Projects/2019/Project1/html/Project1.html b/doc/Projects/2019/Project1/html/Project1.html
index be362272d..eaf0f1a1c 100644
--- a/doc/Projects/2019/Project1/html/Project1.html
+++ b/doc/Projects/2019/Project1/html/Project1.html
@@ -116,7 +116,7 @@ MathJax.Hub.Config({
Department of Physics, University of Oslo, Norway
-
Aug 29, 2019
+
Sep 13, 2019
Regression analysis and resampling methods
@@ -269,7 +269,7 @@ approximately \( 2/3 \) to \( 4/5 \) of the data as training data.
Implement the \( k \)-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the \( R^2 \) functions resulting
+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.
diff --git a/doc/Projects/2019/Project1/ipynb/ipynb-Project1-src.tar.gz b/doc/Projects/2019/Project1/ipynb/ipynb-Project1-src.tar.gz
index 3498e5f42..67731d4f9 100644
Binary files a/doc/Projects/2019/Project1/ipynb/ipynb-Project1-src.tar.gz and b/doc/Projects/2019/Project1/ipynb/ipynb-Project1-src.tar.gz differ
diff --git a/doc/Projects/2019/Project1/pdf/Project1.p.tex b/doc/Projects/2019/Project1/pdf/Project1.p.tex
index 3d4e28d4e..bc823e0e1 100644
--- a/doc/Projects/2019/Project1/pdf/Project1.p.tex
+++ b/doc/Projects/2019/Project1/pdf/Project1.p.tex
@@ -155,7 +155,7 @@ Project 1 on Machine Learning, deadline September 30, 2019
% --- begin date ---
\begin{center}
-Aug 29, 2019
+Sep 13, 2019
\end{center}
% --- end date ---
@@ -298,7 +298,7 @@ approximately $2/3$ to $4/5$ of the data as training data.
Implement the $k$-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the $R^2$ functions resulting
+code) and evaluate again the MSE function resulting
from the test data. You can compare your own code with that from
\textbf{Scikit-Learn} if needed.
diff --git a/doc/Projects/2019/Project1/pdf/Project1.pdf b/doc/Projects/2019/Project1/pdf/Project1.pdf
index 134041fb0..39ea8532d 100644
Binary files a/doc/Projects/2019/Project1/pdf/Project1.pdf and b/doc/Projects/2019/Project1/pdf/Project1.pdf differ
diff --git a/doc/Projects/2019/Project1/pdf/Project1.tex b/doc/Projects/2019/Project1/pdf/Project1.tex
index ff83c2665..746f0a7cf 100644
--- a/doc/Projects/2019/Project1/pdf/Project1.tex
+++ b/doc/Projects/2019/Project1/pdf/Project1.tex
@@ -125,7 +125,7 @@ Project 1 on Machine Learning, deadline September 30, 2019
% --- begin date ---
\begin{center}
-Aug 29, 2019
+Sep 13, 2019
\end{center}
% --- end date ---
@@ -226,7 +226,7 @@ We will generate our own dataset for a function
$\mathrm{FrankeFunction}(x,y)$ with $x,y \in [0,1]$. The function
$f(x,y)$ is the Franke function. You should explore also the addition
an added stochastic noise to this function using the normal
-distribution $\cal{N}(0,1)$.
+distribution $N(0,1)$.
Write your own code (using either a matrix inversion or a singular
value decomposition from e.g., \textbf{numpy} ) or use your code from
@@ -268,7 +268,7 @@ approximately $2/3$ to $4/5$ of the data as training data.
Implement the $k$-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the $R^2$ functions resulting
+code) and evaluate again the MSE function resulting
from the test data. You can compare your own code with that from
\textbf{Scikit-Learn} if needed.
diff --git a/doc/Projects/2019/Project1/pdf/Project1.tex~ b/doc/Projects/2019/Project1/pdf/Project1.tex~
index 625b611c3..241e7b781 100644
--- a/doc/Projects/2019/Project1/pdf/Project1.tex~
+++ b/doc/Projects/2019/Project1/pdf/Project1.tex~
@@ -125,7 +125,7 @@ Project 1 on Machine Learning, deadline September 30, 2019
% --- begin date ---
\begin{center}
-Aug 29, 2019
+Sep 13, 2019
\end{center}
% --- end date ---
@@ -268,7 +268,7 @@ approximately $2/3$ to $4/5$ of the data as training data.
Implement the $k$-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the $R^2$ functions resulting
+code) and evaluate again the MSE function resulting
from the test data. You can compare your own code with that from
\textbf{Scikit-Learn} if needed.
diff --git a/doc/pub/Regression/html/._Regression-bs000.html b/doc/pub/Regression/html/._Regression-bs000.html
index 6bf1b9e0f..1449392b9 100644
--- a/doc/pub/Regression/html/._Regression-bs000.html
+++ b/doc/pub/Regression/html/._Regression-bs000.html
@@ -198,12 +198,12 @@ Automatically generated HTML file from DocOnce source
('Resampling methods: Bootstrap approach', 2, None, '___sec86'),
('Resampling methods: Bootstrap steps', 2, None, '___sec87'),
('Code example for the Bootstrap method', 2, None, '___sec88'),
- ('Cross-validation', 2, None, '___sec89'),
- ('Various steps in cross-validation', 2, None, '___sec90'),
+ ('Various steps in cross-validation', 2, None, '___sec89'),
('How to set up the cross-validation for Ridge and/or Lasso',
2,
None,
- '___sec91'),
+ '___sec90'),
+ ('Cross-validation in brief', 2, None, '___sec91'),
('Code Example for Cross-validation and $k$-fold '
'Cross-validation',
2,
@@ -370,9 +370,9 @@ MathJax.Hub.Config({
+When the repetitive splitting of the data set is done randomly,
+samples may accidently end up in a fast majority of the splits in
+either training or test set. Such samples may have an unbalanced
+influence on either model building or prediction evaluation. To avoid
+this \( k \)-fold cross-validation structures the data splitting. The
+samples are divided into \( k \) more or less equally sized exhaustive and
+mutually exclusive subsets. In turn (at each split) one of these
+subsets plays the role of the test set while the union of the
+remaining subsets constitutes the training set. Such a splitting
+warrants a balanced representation of each sample in both training and
+test set over the splits. Still the division into the \( k \) subsets
+involves a degree of randomness. This may be fully excluded when
+choosing \( k=n \). This particular case is referred to as leave-one-out
+cross-validation (LOOCV).
diff --git a/doc/pub/Regression/html/._Regression-bs091.html b/doc/pub/Regression/html/._Regression-bs091.html
index 82ac178e7..023855f4b 100644
--- a/doc/pub/Regression/html/._Regression-bs091.html
+++ b/doc/pub/Regression/html/._Regression-bs091.html
@@ -198,12 +198,12 @@ Automatically generated HTML file from DocOnce source
('Resampling methods: Bootstrap approach', 2, None, '___sec86'),
('Resampling methods: Bootstrap steps', 2, None, '___sec87'),
('Code example for the Bootstrap method', 2, None, '___sec88'),
- ('Cross-validation', 2, None, '___sec89'),
- ('Various steps in cross-validation', 2, None, '___sec90'),
+ ('Various steps in cross-validation', 2, None, '___sec89'),
('How to set up the cross-validation for Ridge and/or Lasso',
2,
None,
- '___sec91'),
+ '___sec90'),
+ ('Cross-validation in brief', 2, None, '___sec91'),
('Code Example for Cross-validation and $k$-fold '
'Cross-validation',
2,
@@ -370,9 +370,9 @@ MathJax.Hub.Config({
How to set up the cross-validation for Ridge and/or Lasso
-
-When the repetitive splitting of the data set is done randomly,
-samples may accidently end up in a fast majority of the splits in
-either training or test set. Such samples may have an unbalanced
-influence on either model building or prediction evaluation. To avoid
-this \( k \)-fold cross-validation structures the data splitting. The
-samples are divided into \( k \) more or less equally sized exhaustive and
-mutually exclusive subsets. In turn (at each split) one of these
-subsets plays the role of the test set while the union of the
-remaining subsets constitutes the training set. Such a splitting
-warrants a balanced representation of each sample in both training and
-test set over the splits. Still the division into the \( k \) subsets
-involves a degree of randomness. This may be fully excluded when
-choosing \( k=n \). This particular case is referred to as leave-one-out
-cross-validation (LOOCV).
+
+
Define a range of interest for the penalty parameter.
+
Divide the data set into training and test set comprising samples \( \{1, \ldots, n\} \setminus i \) and \( \{ i \} \), respectively.
+
Fit the linear regression model by means of ridge estimation for each \( \lambda \) in the grid using the training set, and the corresponding estimate of the error variance \( \boldsymbol{\sigma}_{-i}^2(\lambda) \), as
Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \boldsymbol{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \boldsymbol{X}_{i, \ast} \boldsymbol{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.
+
Repeat the first three steps such that each sample plays the role of the test set once.
+
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
How to set up the cross-validation for Ridge and/or Lasso
+
Cross-validation in brief
-
-
Define a range of interest for the penalty parameter.
-
Divide the data set into training and test set comprising samples \( \{1, \ldots, n\} \setminus i \) and \( \{ i \} \), respectively.
-
Fit the linear regression model by means of ridge estimation for each \( \lambda \) in the grid using the training set, and the corresponding estimate of the error variance \( \boldsymbol{\sigma}_{-i}^2(\lambda) \), as
-
+
+For the various values of \( k \)
-$$
-\begin{align*}
-\boldsymbol{\beta}_{-i}(\lambda) & = ( \boldsymbol{X}_{-i, \ast}^{T}
-\boldsymbol{X}_{-i, \ast} + \lambda \boldsymbol{I}_{pp})^{-1}
-\boldsymbol{X}_{-i, \ast}^{T} \boldsymbol{y}_{-i}
-\end{align*}
-$$
+
+
shuffle the dataset randomly.
+
Split the dataset into \( k \) groups.
+
For each unique group:
+
+
Decide which group to use as set for test data
+
Take the remaining groups as a training data set
+
Fit a model on the training set and evaluate it on the test set
+
Retain the evaluation score and discard the model
+
-
-
Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \boldsymbol{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \boldsymbol{X}_{i, \ast} \boldsymbol{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.
-
Repeat the first three steps such that each sample plays the role of the test set once.
-
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter by computing the cross-validated log-likelihood. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.
-
+
Summarize the model using the sample of model evaluation scores
+
diff --git a/doc/pub/Regression/html/._Regression-bs093.html b/doc/pub/Regression/html/._Regression-bs093.html
index e5ba761c9..2ee6416bb 100644
--- a/doc/pub/Regression/html/._Regression-bs093.html
+++ b/doc/pub/Regression/html/._Regression-bs093.html
@@ -198,12 +198,12 @@ Automatically generated HTML file from DocOnce source
('Resampling methods: Bootstrap approach', 2, None, '___sec86'),
('Resampling methods: Bootstrap steps', 2, None, '___sec87'),
('Code example for the Bootstrap method', 2, None, '___sec88'),
- ('Cross-validation', 2, None, '___sec89'),
- ('Various steps in cross-validation', 2, None, '___sec90'),
+ ('Various steps in cross-validation', 2, None, '___sec89'),
('How to set up the cross-validation for Ridge and/or Lasso',
2,
None,
- '___sec91'),
+ '___sec90'),
+ ('Cross-validation in brief', 2, None, '___sec91'),
('Code Example for Cross-validation and $k$-fold '
'Cross-validation',
2,
@@ -370,9 +370,9 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
-
Sep 12, 2019
+
Sep 13, 2019
@@ -3524,12 +3524,7 @@ plt.show()
-
Cross-validation
-
-
-
-
-
Various steps in cross-validation
+
Various steps in cross-validation
When the repetitive splitting of the data set is done randomly,
@@ -3550,7 +3545,7 @@ cross-validation (LOOCV).
-
How to set up the cross-validation for Ridge and/or Lasso
+
How to set up the cross-validation for Ridge and/or Lasso
Define a range of interest for the penalty parameter.
@@ -3571,7 +3566,7 @@ $$
Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \boldsymbol{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \boldsymbol{X}_{i, \ast} \boldsymbol{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.
Repeat the first three steps such that each sample plays the role of the test set once.
-
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter by computing the cross-validated log-likelihood. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
+
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
$$
@@ -3580,11 +3575,28 @@ $$
\end{align*}
$$
+
-
-
The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.
-
+
+
Cross-validation in brief
+
+
+For the various values of \( k \)
+
+
+
shuffle the dataset randomly.
+
Split the dataset into \( k \) groups.
+
For each unique group:
+
+
+
Decide which group to use as set for test data
+
Take the remaining groups as a training data set
+
Fit a model on the training set and evaluate it on the test set
+
Retain the evaluation score and discard the model
+
+
Summarize the model using the sample of model evaluation scores
+
diff --git a/doc/pub/Regression/html/Regression-solarized.html b/doc/pub/Regression/html/Regression-solarized.html
index 69e7d4aa5..a89648175 100644
--- a/doc/pub/Regression/html/Regression-solarized.html
+++ b/doc/pub/Regression/html/Regression-solarized.html
@@ -218,12 +218,12 @@ div { text-align: justify; text-justify: inter-word; }
('Resampling methods: Bootstrap approach', 2, None, '___sec86'),
('Resampling methods: Bootstrap steps', 2, None, '___sec87'),
('Code example for the Bootstrap method', 2, None, '___sec88'),
- ('Cross-validation', 2, None, '___sec89'),
- ('Various steps in cross-validation', 2, None, '___sec90'),
+ ('Various steps in cross-validation', 2, None, '___sec89'),
('How to set up the cross-validation for Ridge and/or Lasso',
2,
None,
- '___sec91'),
+ '___sec90'),
+ ('Cross-validation in brief', 2, None, '___sec91'),
('Code Example for Cross-validation and $k$-fold '
'Cross-validation',
2,
@@ -305,7 +305,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
When the repetitive splitting of the data set is done randomly,
@@ -3478,7 +3473,7 @@ cross-validation (LOOCV).
-
How to set up the cross-validation for Ridge and/or Lasso
+
How to set up the cross-validation for Ridge and/or Lasso
Define a range of interest for the penalty parameter.
@@ -3498,7 +3493,7 @@ $$
Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \boldsymbol{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \boldsymbol{X}_{i, \ast} \boldsymbol{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.
Repeat the first three steps such that each sample plays the role of the test set once.
-
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter by computing the cross-validated log-likelihood. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
+
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
$$
@@ -3507,10 +3502,28 @@ $$
\end{align*}
$$
+
+
-
-
The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.
-
+
Cross-validation in brief
+
+
+For the various values of \( k \)
+
+
+
shuffle the dataset randomly.
+
Split the dataset into \( k \) groups.
+
For each unique group:
+
+
+
Decide which group to use as set for test data
+
Take the remaining groups as a training data set
+
Fit a model on the training set and evaluate it on the test set
+
Retain the evaluation score and discard the model
+
+
+
Summarize the model using the sample of model evaluation scores
+
diff --git a/doc/pub/Regression/html/Regression.html b/doc/pub/Regression/html/Regression.html
index 85e22501f..4787663dc 100644
--- a/doc/pub/Regression/html/Regression.html
+++ b/doc/pub/Regression/html/Regression.html
@@ -223,12 +223,12 @@ div { text-align: justify; text-justify: inter-word; }
('Resampling methods: Bootstrap approach', 2, None, '___sec86'),
('Resampling methods: Bootstrap steps', 2, None, '___sec87'),
('Code example for the Bootstrap method', 2, None, '___sec88'),
- ('Cross-validation', 2, None, '___sec89'),
- ('Various steps in cross-validation', 2, None, '___sec90'),
+ ('Various steps in cross-validation', 2, None, '___sec89'),
('How to set up the cross-validation for Ridge and/or Lasso',
2,
None,
- '___sec91'),
+ '___sec90'),
+ ('Cross-validation in brief', 2, None, '___sec91'),
('Code Example for Cross-validation and $k$-fold '
'Cross-validation',
2,
@@ -310,7 +310,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
When the repetitive splitting of the data set is done randomly,
@@ -3483,7 +3478,7 @@ cross-validation (LOOCV).
-
How to set up the cross-validation for Ridge and/or Lasso
+
How to set up the cross-validation for Ridge and/or Lasso
Define a range of interest for the penalty parameter.
@@ -3503,7 +3498,7 @@ $$
Evaluate the prediction performance of these models on the test set by \( \log\{L[y_i, \boldsymbol{X}_{i, \ast}; \boldsymbol{\beta}_{-i}(\lambda), \boldsymbol{\sigma}_{-i}^2(\lambda)]\} \). Or, by the prediction error \( |y_i - \boldsymbol{X}_{i, \ast} \boldsymbol{\beta}_{-i}(\lambda)| \), the relative error, the error squared or the R2 score function.
Repeat the first three steps such that each sample plays the role of the test set once.
-
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter by computing the cross-validated log-likelihood. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
+
Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
$$
@@ -3512,10 +3507,28 @@ $$
\end{align*}
$$
+
+
-
-
The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.
-
+
Cross-validation in brief
+
+
+For the various values of \( k \)
+
+
+
shuffle the dataset randomly.
+
Split the dataset into \( k \) groups.
+
For each unique group:
+
+
+
Decide which group to use as set for test data
+
Take the remaining groups as a training data set
+
Fit a model on the training set and evaluate it on the test set
+
Retain the evaluation score and discard the model
+
+
+
Summarize the model using the sample of model evaluation scores
+
diff --git a/doc/pub/Regression/ipynb/Regression.ipynb b/doc/pub/Regression/ipynb/Regression.ipynb
index d878532e1..106554667 100644
--- a/doc/pub/Regression/ipynb/Regression.ipynb
+++ b/doc/pub/Regression/ipynb/Regression.ipynb
@@ -10,7 +10,7 @@
" \n",
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
"\n",
- "Date: **Sep 12, 2019**\n",
+ "Date: **Sep 13, 2019**\n",
"\n",
"Copyright 1999-2019, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -4638,9 +4638,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Cross-validation\n",
- "\n",
- "\n",
"\n",
"## Various steps in cross-validation\n",
"\n",
@@ -4690,7 +4687,7 @@
"\n",
"* Repeat the first three steps such that each sample plays the role of the test set once.\n",
"\n",
- "* Average the prediction performances of the test sets at each grid point of the penalty bias/parameter by computing the *cross-validated log-likelihood*. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as"
+ "* Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as"
]
},
{
@@ -4708,7 +4705,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "* The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.\n",
+ "## Cross-validation in brief\n",
+ "\n",
+ "For the various values of $k$\n",
+ "\n",
+ "1. shuffle the dataset randomly.\n",
+ "\n",
+ "2. Split the dataset into $k$ groups.\n",
+ "\n",
+ "3. For each unique group:\n",
+ "\n",
+ "a. Decide which group to use as set for test data\n",
+ "\n",
+ "b. Take the remaining groups as a training data set\n",
+ "\n",
+ "c. Fit a model on the training set and evaluate it on the test set\n",
+ "\n",
+ "d. Retain the evaluation score and discard the model\n",
+ "\n",
+ "\n",
+ "5. Summarize the model using the sample of model evaluation scores\n",
"\n",
"## Code Example for Cross-validation and $k$-fold Cross-validation\n",
"\n",
diff --git a/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz b/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz
index 86606cba5..b57d74aad 100644
Binary files a/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz and b/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz differ
diff --git a/doc/pub/Regression/pdf/Regression-minted.pdf b/doc/pub/Regression/pdf/Regression-minted.pdf
index 01daa0706..9ee6ecba2 100644
Binary files a/doc/pub/Regression/pdf/Regression-minted.pdf and b/doc/pub/Regression/pdf/Regression-minted.pdf differ
diff --git a/doc/src/Projects/2019/Project1/Project1-bs.html b/doc/src/Projects/2019/Project1/Project1-bs.html
deleted file mode 100644
index 12a5c36b1..000000000
--- a/doc/src/Projects/2019/Project1/Project1-bs.html
+++ /dev/null
@@ -1,598 +0,0 @@
-
-
-
-
-
-
-
-
-Project 1 on Machine Learning, deadline September 30, 2019
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-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.
-
-
-We will first study how to fit polynomials to a specific
-two-dimensional function called Franke's
-function. This
-is a function which has been widely used when testing various
-interpolation and fitting algorithms. Furthermore, after having
-established the model and the method, we will employ resamling
-techniques such as cross-validation in order to perform a
-proper assessment of our models. We will also study in detail the
-so-called Bias-Variance trade off.
-
-
-The Franke function, which is a weighted sum of four exponentials reads as follows
-$$
-\begin{align*}
-f(x,y) &= \frac{3}{4}\exp{\left(-\frac{(9x-2)^2}{4} - \frac{(9y-2)^2}{4}\right)}+\frac{3}{4}\exp{\left(-\frac{(9x+1)^2}{49}- \frac{(9y+1)}{10}\right)} \\
-&+\frac{1}{2}\exp{\left(-\frac{(9x-7)^2}{4} - \frac{(9y-3)^2}{4}\right)} -\frac{1}{5}\exp{\left(-(9x-4)^2 - (9y-7)^2\right) }.
-\end{align*}
-$$
-
-
-The function will be defined for \( x,y\in [0,1] \). Our first step will
-be to perform an OLS regression analysis of this function, trying out
-a polynomial fit with an \( x \) and \( y \) dependence of the form \( [x, y,
-x^2, y^2, xy, \dots] \). We will also include cross-validation as
-resampling technique. As in homeworks 1 and 2, we can use a uniform
-distribution to set up the arrays of values for \( x \) and \( y \), or as in
-the example below just a set of fixed
-values for \( x \) and \( y \) with a given step
-size. We will fit a
-function (for example a polynomial) of \( x \) and \( y \). Thereafter we
-will repeat much of the same procedure using the Ridge and Lasso
-regression methods, introducing thus a dependence on the bias
-(penalty) \( \lambda \).
-
-
-Finally we are going to use (real) digital terrain data and try to
-reproduce these data using the same methods. We will also try to go
-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)
-
-
-
-
frommpl_toolkits.mplot3dimport Axes3D
-importmatplotlib.pyplotasplt
-frommatplotlibimport cm
-frommatplotlib.tickerimport LinearLocator, FormatStrFormatter
-importnumpyasnp
-fromrandomimport random, seed
-
-fig = plt.figure()
-ax = fig.gca(projection='3d')
-
-# Make data.
-x = np.arange(0, 1, 0.05)
-y = np.arange(0, 1, 0.05)
-x, y = np.meshgrid(x,y)
-
-
-defFrankeFunction(x,y):
- term1 =0.75*np.exp(-(0.25*(9*x-2)**2) -0.25*((9*y-2)**2))
- term2 =0.75*np.exp(-((9*x+1)**2)/49.0-0.1*(9*y+1))
- term3 =0.5*np.exp(-(9*x-7)**2/4.0-0.25*((9*y-3)**2))
- term4 =-0.2*np.exp(-(9*x-4)**2- (9*y-7)**2)
- return term1 + term2 + term3 + term4
-
-
-z = FrankeFunction(x, y)
-
-# Plot the surface.
-surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm,
- linewidth=0, antialiased=False)
-
-# Customize the z axis.
-ax.set_zlim(-0.10, 1.40)
-ax.zaxis.set_major_locator(LinearLocator(10))
-ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
-
-# Add a color bar which maps values to colors.
-fig.colorbar(surf, shrink=0.5, aspect=5)
-
-plt.show()
-
-
-
Part a): Ordinary Least Square on the Franke function with resampling
-
-
-We will generate our own dataset for a function
-\( \mathrm{FrankeFunction}(x,y) \) with \( x,y \in [0,1] \). The function
-\( f(x,y) \) is the Franke function. You should explore also the addition
-an added stochastic noise to this function using the normal
-distribution \( \cal{N}(0,1) \).
-
-
-Write your own code (using either a matrix inversion or a singular
-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
-variances, evaluate the Mean Squared error (MSE)
-
-$$ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n}
-\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2,
-$$
-
-
-and the \( R^2 \) score function. If \( \tilde{\hat{y}}_i \) is the predicted
-value of the \( i-th \) sample and \( y_i \) is the corresponding true value,
-then the score \( R^2 \) is defined as
-
-$$
-R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2},
-$$
-
-
-where we have defined the mean value of \( \hat{y} \) as
-
-$$
-\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.
-$$
-
-
Part b) Resampling techniques, adding more complexity
-
-
-Perform a resampling of the data where you split the data in training
-data and test data. Here you can write your own function or use the
-function for splitting training data provided by Scikit-Learn.
-This function is called \( train\_test\_split \).
-
-
-It is normal in essentially all Machine Learning studies to split the
-data in a training set and a test set (sometimes also an additional
-validation set). There
-is no explicit recipe for how much data should be included as training
-data and say test data. An accepted rule of thumb is to use
-approximately \( 2/3 \) to \( 4/5 \) of the data as training data.
-
-
-Implement the \( k \)-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the \( R^2 \) functions resulting
-from the test data. You can compare your own code with that from
-Scikit-Learn if needed.
-
-
Part c): Bias-variance tradeoff
-
-
-With a code which does OLS and includes resampling techniques,
-we will now discuss the bias-variance tradeoff in the context of
-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.
-
-
-Consider a
-dataset \( \mathcal{L} \) consisting of the data
-\( \mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \).
-
-
-Let us assume that the true data is generated from a noisy model
-
-$$
-\boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon}.
-$$
-
-
-Here \( \epsilon \) is normally distributed with mean zero and standard
-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
-\( \boldsymbol{\beta} \) and the design matrix \( \boldsymbol{X} \) which embody our model,
-that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \).
-
-
-The parameters \( \boldsymbol{\beta} \) are in turn found by optimizing the means
-squared error via the so-called cost function
-
-$$
-C(\boldsymbol{X},\boldsymbol{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right].
-$$
-
-
-Show that you can rewrite this as
-$$
-\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\sigma^2.
-$$
-
-
-Explain what the terms mean, which one is the bias and which one is
-the variance and discuss their interpretations.
-
-
-Discuss the bias and variance tradeoff 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.
-
-
-Try to make a figure similar to Fig. 2.11 of Hastie, Tibshirani, and
-Friedman, see the references below. You will most likely not get an
-equally smooth curve!
-
-
Part d): Ridge Regression on the Franke function with resampling
-
-
-Write your own code for the Ridge method, either using matrix
-inversion or the singular value decomposition as done in the previous
-exercise or howework 2 (see also chapter 3.4 of Hastie et al.,
-equations (3.43) and (3.44)). Perform the same analysis as in the
-previous exercises (for the same polynomials and include resampling
-techniques) but now for different values of \( \lambda \). Compare and
-analyze your results with those obtained in parts a-c). Study the
-dependence on \( \lambda \).
-
-
-Study also the bias-variance tradeoff as function of various values of
-the parameter \( \lambda \). Comment your results.
-
-
Part e): Lasso Regression on the Franke function with resampling
-
-
-This part is essentially a repeat of the previous two ones, but now
-with Lasso regression. Write either your own code or, in this case,
-you can also use the functionalities of Scikit-Learn (recommended).
-Give a
-critical discussion of the three methods and a judgement of which
-model fits the data best.
-
-
Part f): Introducing real data
-
-
-With our codes functioning and having been tested properly on a
-simpler function we are now ready to look at real data. We will
-essentially repeat in part g) what was done in parts a-e). However, we
-need first to download the data and prepare properly the inputs to our
-codes. We are going to download digital terrain data from the website
-https://earthexplorer.usgs.gov/,
-
-
-In order to obtain data for a specific region, you need to register as
-a user (free) at this website and then decide upon which area you want
-to fetch the digital terrain data from. In order to be able to read
-the data properly, you need to specify that the format should be SRTM
-Arc-Second Global and download the data as a GeoTIF file. The
-files are then stored in tif format which can be imported into a
-Python program using
-
-
-
-
-
scipy.misc.imread
-
-
-Here is a simple part of a Python code which reads and plots the data
-from such files
-
-
-
-
-
importnumpyasnp
-fromimageioimport imread
-importmatplotlib.pyplotasplt
-frommpl_toolkits.mplot3dimport Axes3D
-frommatplotlibimport cm
-
-# Load the terrain
-terrain1 = imread('SRTM_data_Norway_1.tif')
-# Show the terrain
-plt.figure()
-plt.title('Terrain over Norway 1')
-plt.imshow(terrain1, cmap='gray')
-plt.xlabel('X')
-plt.ylabel('Y')
-plt.show()
-
-
-If you should have problems in downloading the digital terrain data,
-we provide two examples under the data folder of project 1. One is
-from a region close to Stavanger in Norway and the other Møsvatn
-Austfjell, again in Norway.
-Feel free to produce your own terrain data.
-
-
Part g) OLS, Ridge and Lasso regression with resampling
-
-
-Our final part deals with the parameterization of your digital terrain
-data. We will apply all three methods for linear regression as in
-parts a-c), the same type (or higher order) of polynomial
-approximation and the same resampling techniques to evaluate which
-model fits the data best.
-
-
-At the end, you should pesent a critical evaluation of your results
-and discuss the applicability of these regression methods to the type
-of data presented here.
-
-
-Here follows a brief recipe and recommendation on how to write a report for each
-project.
-
-
-
Give a short description of the nature of the problem and the eventual numerical methods you have used.
-
Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.
-
Include the source code of your program. Comment your program properly.
-
If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.
-
Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.
-
Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.
-
Try to give an interpretation of you results in your answers to the problems.
-
Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.
-
Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
-
-
-
Format for electronic delivery of report and programs
-
-
-The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:
-
-
-
Use Devilry to hand in your projects, log in at http://devilry.ifi.uio.no with your normal UiO username and password and choose either 'fysstk3155' or 'fysstk4155'. There you can load up the files within the deadline.
-
Upload only the report file! For the source code file(s) you have developed please provide us with your link to your github domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.
-
In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.
-
In this and all later projects, you should include tests (for example unit tests) of your code(s).
-
Comments from us on your projects, approval or not, corrections to be made etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
-
-
-Finally,
-we encourage you to collaborate. Optimal working groups consist of
-2-3 students. You can then hand in a common report.
-
-
Software and needed installations
-
-
-If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages,
-we recommend that you install the following Python packages via pip as
-
-
-See below for a discussion of tensorflow and scikit-learn.
-
-
-For OSX users we recommend also, after having installed Xcode, to install brew. Brew allows
-for a seamless installation of additional software via for example
-
-
-
brew install python3
-
-
-For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
-you can use pip as well and simply install Python as
-
-
-
sudo apt-get install python3 (or python for python2.7)
-
-
-etc etc.
-
-
-If you don't want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up all relevant dependencies for Python, namely
-
-
-
Anaconda Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system conda
-
Enthought canopy is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
-
-
-Popular software packages written in Python for ML are
-
-
-
-These are all freely available at their respective GitHub sites. They
-encompass communities of developers in the thousands or more. And the number
-of code developers and contributors keeps increasing.
-
-
-
-
-
-
-
-
diff --git a/doc/src/Projects/2019/Project1/Project1.do.txt b/doc/src/Projects/2019/Project1/Project1.do.txt
index e0918ffa5..fb28bcdb7 100644
--- a/doc/src/Projects/2019/Project1/Project1.do.txt
+++ b/doc/src/Projects/2019/Project1/Project1.do.txt
@@ -151,7 +151,7 @@ approximately $2/3$ to $4/5$ of the data as training data.
Implement the $k$-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the $R^2$ functions resulting
+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.
diff --git a/doc/src/Projects/2019/Project1/Project1.html b/doc/src/Projects/2019/Project1/Project1.html
deleted file mode 100644
index be362272d..000000000
--- a/doc/src/Projects/2019/Project1/Project1.html
+++ /dev/null
@@ -1,537 +0,0 @@
-
-
-
-
-
-
-
-
-Project 1 on Machine Learning, deadline September 30, 2019
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Project 1 on Machine Learning, deadline September 30, 2019
-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.
-
-
-We will first study how to fit polynomials to a specific
-two-dimensional function called Franke's
-function. This
-is a function which has been widely used when testing various
-interpolation and fitting algorithms. Furthermore, after having
-established the model and the method, we will employ resamling
-techniques such as cross-validation in order to perform a
-proper assessment of our models. We will also study in detail the
-so-called Bias-Variance trade off.
-
-
-The Franke function, which is a weighted sum of four exponentials reads as follows
-$$
-\begin{align*}
-f(x,y) &= \frac{3}{4}\exp{\left(-\frac{(9x-2)^2}{4} - \frac{(9y-2)^2}{4}\right)}+\frac{3}{4}\exp{\left(-\frac{(9x+1)^2}{49}- \frac{(9y+1)}{10}\right)} \\
-&+\frac{1}{2}\exp{\left(-\frac{(9x-7)^2}{4} - \frac{(9y-3)^2}{4}\right)} -\frac{1}{5}\exp{\left(-(9x-4)^2 - (9y-7)^2\right) }.
-\end{align*}
-$$
-
-
-The function will be defined for \( x,y\in [0,1] \). Our first step will
-be to perform an OLS regression analysis of this function, trying out
-a polynomial fit with an \( x \) and \( y \) dependence of the form \( [x, y,
-x^2, y^2, xy, \dots] \). We will also include cross-validation as
-resampling technique. As in homeworks 1 and 2, we can use a uniform
-distribution to set up the arrays of values for \( x \) and \( y \), or as in
-the example below just a set of fixed
-values for \( x \) and \( y \) with a given step
-size. We will fit a
-function (for example a polynomial) of \( x \) and \( y \). Thereafter we
-will repeat much of the same procedure using the Ridge and Lasso
-regression methods, introducing thus a dependence on the bias
-(penalty) \( \lambda \).
-
-
-Finally we are going to use (real) digital terrain data and try to
-reproduce these data using the same methods. We will also try to go
-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)
-
-
-
-
frommpl_toolkits.mplot3dimport Axes3D
-importmatplotlib.pyplotasplt
-frommatplotlibimport cm
-frommatplotlib.tickerimport LinearLocator, FormatStrFormatter
-importnumpyasnp
-fromrandomimport random, seed
-
-fig = plt.figure()
-ax = fig.gca(projection='3d')
-
-# Make data.
-x = np.arange(0, 1, 0.05)
-y = np.arange(0, 1, 0.05)
-x, y = np.meshgrid(x,y)
-
-
-defFrankeFunction(x,y):
- term1 =0.75*np.exp(-(0.25*(9*x-2)**2) -0.25*((9*y-2)**2))
- term2 =0.75*np.exp(-((9*x+1)**2)/49.0-0.1*(9*y+1))
- term3 =0.5*np.exp(-(9*x-7)**2/4.0-0.25*((9*y-3)**2))
- term4 =-0.2*np.exp(-(9*x-4)**2- (9*y-7)**2)
- return term1 + term2 + term3 + term4
-
-
-z = FrankeFunction(x, y)
-
-# Plot the surface.
-surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm,
- linewidth=0, antialiased=False)
-
-# Customize the z axis.
-ax.set_zlim(-0.10, 1.40)
-ax.zaxis.set_major_locator(LinearLocator(10))
-ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
-
-# Add a color bar which maps values to colors.
-fig.colorbar(surf, shrink=0.5, aspect=5)
-
-plt.show()
-
-
-
Part a): Ordinary Least Square on the Franke function with resampling
-
-
-We will generate our own dataset for a function
-\( \mathrm{FrankeFunction}(x,y) \) with \( x,y \in [0,1] \). The function
-\( f(x,y) \) is the Franke function. You should explore also the addition
-an added stochastic noise to this function using the normal
-distribution \( \cal{N}(0,1) \).
-
-
-Write your own code (using either a matrix inversion or a singular
-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
-variances, evaluate the Mean Squared error (MSE)
-
-$$ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n}
-\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2,
-$$
-
-
-and the \( R^2 \) score function. If \( \tilde{\hat{y}}_i \) is the predicted
-value of the \( i-th \) sample and \( y_i \) is the corresponding true value,
-then the score \( R^2 \) is defined as
-
-$$
-R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2},
-$$
-
-
-where we have defined the mean value of \( \hat{y} \) as
-
-$$
-\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.
-$$
-
-
Part b) Resampling techniques, adding more complexity
-
-
-Perform a resampling of the data where you split the data in training
-data and test data. Here you can write your own function or use the
-function for splitting training data provided by Scikit-Learn.
-This function is called \( train\_test\_split \).
-
-
-It is normal in essentially all Machine Learning studies to split the
-data in a training set and a test set (sometimes also an additional
-validation set). There
-is no explicit recipe for how much data should be included as training
-data and say test data. An accepted rule of thumb is to use
-approximately \( 2/3 \) to \( 4/5 \) of the data as training data.
-
-
-Implement the \( k \)-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the \( R^2 \) functions resulting
-from the test data. You can compare your own code with that from
-Scikit-Learn if needed.
-
-
Part c): Bias-variance tradeoff
-
-
-With a code which does OLS and includes resampling techniques,
-we will now discuss the bias-variance tradeoff in the context of
-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.
-
-
-Consider a
-dataset \( \mathcal{L} \) consisting of the data
-\( \mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\} \).
-
-
-Let us assume that the true data is generated from a noisy model
-
-$$
-\boldsymbol{y}=f(\boldsymbol{x}) + \boldsymbol{\epsilon}.
-$$
-
-
-Here \( \epsilon \) is normally distributed with mean zero and standard
-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
-\( \boldsymbol{\beta} \) and the design matrix \( \boldsymbol{X} \) which embody our model,
-that is \( \boldsymbol{\tilde{y}}=\boldsymbol{X}\boldsymbol{\beta} \).
-
-
-The parameters \( \boldsymbol{\beta} \) are in turn found by optimizing the means
-squared error via the so-called cost function
-
-$$
-C(\boldsymbol{X},\boldsymbol{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right].
-$$
-
-
-Show that you can rewrite this as
-$$
-\mathbb{E}\left[(\boldsymbol{y}-\boldsymbol{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\boldsymbol{\tilde{y}}\right])^2+\sigma^2.
-$$
-
-
-Explain what the terms mean, which one is the bias and which one is
-the variance and discuss their interpretations.
-
-
-Discuss the bias and variance tradeoff 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.
-
-
-Try to make a figure similar to Fig. 2.11 of Hastie, Tibshirani, and
-Friedman, see the references below. You will most likely not get an
-equally smooth curve!
-
-
Part d): Ridge Regression on the Franke function with resampling
-
-
-Write your own code for the Ridge method, either using matrix
-inversion or the singular value decomposition as done in the previous
-exercise or howework 2 (see also chapter 3.4 of Hastie et al.,
-equations (3.43) and (3.44)). Perform the same analysis as in the
-previous exercises (for the same polynomials and include resampling
-techniques) but now for different values of \( \lambda \). Compare and
-analyze your results with those obtained in parts a-c). Study the
-dependence on \( \lambda \).
-
-
-Study also the bias-variance tradeoff as function of various values of
-the parameter \( \lambda \). Comment your results.
-
-
Part e): Lasso Regression on the Franke function with resampling
-
-
-This part is essentially a repeat of the previous two ones, but now
-with Lasso regression. Write either your own code or, in this case,
-you can also use the functionalities of Scikit-Learn (recommended).
-Give a
-critical discussion of the three methods and a judgement of which
-model fits the data best.
-
-
Part f): Introducing real data
-
-
-With our codes functioning and having been tested properly on a
-simpler function we are now ready to look at real data. We will
-essentially repeat in part g) what was done in parts a-e). However, we
-need first to download the data and prepare properly the inputs to our
-codes. We are going to download digital terrain data from the website
-https://earthexplorer.usgs.gov/,
-
-
-In order to obtain data for a specific region, you need to register as
-a user (free) at this website and then decide upon which area you want
-to fetch the digital terrain data from. In order to be able to read
-the data properly, you need to specify that the format should be SRTM
-Arc-Second Global and download the data as a GeoTIF file. The
-files are then stored in tif format which can be imported into a
-Python program using
-
-
-
-
-
scipy.misc.imread
-
-
-Here is a simple part of a Python code which reads and plots the data
-from such files
-
-
-
-
-
importnumpyasnp
-fromimageioimport imread
-importmatplotlib.pyplotasplt
-frommpl_toolkits.mplot3dimport Axes3D
-frommatplotlibimport cm
-
-# Load the terrain
-terrain1 = imread('SRTM_data_Norway_1.tif')
-# Show the terrain
-plt.figure()
-plt.title('Terrain over Norway 1')
-plt.imshow(terrain1, cmap='gray')
-plt.xlabel('X')
-plt.ylabel('Y')
-plt.show()
-
-
-If you should have problems in downloading the digital terrain data,
-we provide two examples under the data folder of project 1. One is
-from a region close to Stavanger in Norway and the other Møsvatn
-Austfjell, again in Norway.
-Feel free to produce your own terrain data.
-
-
Part g) OLS, Ridge and Lasso regression with resampling
-
-
-Our final part deals with the parameterization of your digital terrain
-data. We will apply all three methods for linear regression as in
-parts a-c), the same type (or higher order) of polynomial
-approximation and the same resampling techniques to evaluate which
-model fits the data best.
-
-
-At the end, you should pesent a critical evaluation of your results
-and discuss the applicability of these regression methods to the type
-of data presented here.
-
-
-Here follows a brief recipe and recommendation on how to write a report for each
-project.
-
-
-
Give a short description of the nature of the problem and the eventual numerical methods you have used.
-
Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.
-
Include the source code of your program. Comment your program properly.
-
If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.
-
Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.
-
Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.
-
Try to give an interpretation of you results in your answers to the problems.
-
Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.
-
Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
-
-
-
Format for electronic delivery of report and programs
-
-
-The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:
-
-
-
Use Devilry to hand in your projects, log in at http://devilry.ifi.uio.no with your normal UiO username and password and choose either 'fysstk3155' or 'fysstk4155'. There you can load up the files within the deadline.
-
Upload only the report file! For the source code file(s) you have developed please provide us with your link to your github domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.
-
In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.
-
In this and all later projects, you should include tests (for example unit tests) of your code(s).
-
Comments from us on your projects, approval or not, corrections to be made etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
-
-
-Finally,
-we encourage you to collaborate. Optimal working groups consist of
-2-3 students. You can then hand in a common report.
-
-
Software and needed installations
-
-
-If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages,
-we recommend that you install the following Python packages via pip as
-
-
-See below for a discussion of tensorflow and scikit-learn.
-
-
-For OSX users we recommend also, after having installed Xcode, to install brew. Brew allows
-for a seamless installation of additional software via for example
-
-
-
brew install python3
-
-
-For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
-you can use pip as well and simply install Python as
-
-
-
sudo apt-get install python3 (or python for python2.7)
-
-
-etc etc.
-
-
-If you don't want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up all relevant dependencies for Python, namely
-
-
-
Anaconda Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system conda
-
Enthought canopy is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
-
-
-Popular software packages written in Python for ML are
-
-
-
-These are all freely available at their respective GitHub sites. They
-encompass communities of developers in the thousands or more. And the number
-of code developers and contributors keeps increasing.
-
-
-
-
-
-
-
-
diff --git a/doc/src/Projects/2019/Project1/Project1.p.tex b/doc/src/Projects/2019/Project1/Project1.p.tex
deleted file mode 100644
index 3d4e28d4e..000000000
--- a/doc/src/Projects/2019/Project1/Project1.p.tex
+++ /dev/null
@@ -1,560 +0,0 @@
-%%
-%% Automatically generated file from DocOnce source
-%% (https://github.com/hplgit/doconce/)
-%%
-%%
-% #ifdef PTEX2TEX_EXPLANATION
-%%
-%% The file follows the ptex2tex extended LaTeX format, see
-%% ptex2tex: http://code.google.com/p/ptex2tex/
-%%
-%% Run
-%% ptex2tex myfile
-%% or
-%% doconce ptex2tex myfile
-%%
-%% to turn myfile.p.tex into an ordinary LaTeX file myfile.tex.
-%% (The ptex2tex program: http://code.google.com/p/ptex2tex)
-%% Many preprocess options can be added to ptex2tex or doconce ptex2tex
-%%
-%% ptex2tex -DMINTED myfile
-%% doconce ptex2tex myfile envir=minted
-%%
-%% ptex2tex will typeset code environments according to a global or local
-%% .ptex2tex.cfg configure file. doconce ptex2tex will typeset code
-%% according to options on the command line (just type doconce ptex2tex to
-%% see examples). If doconce ptex2tex has envir=minted, it enables the
-%% minted style without needing -DMINTED.
-% #endif
-
-% #define PREAMBLE
-
-% #ifdef PREAMBLE
-%-------------------- begin preamble ----------------------
-
-\documentclass[%
-oneside, % oneside: electronic viewing, twoside: printing
-final, % draft: marks overfull hboxes, figures with paths
-10pt]{article}
-
-\listfiles % print all files needed to compile this document
-
-\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
-\usepackage[table]{xcolor}
-\usepackage{bm,ltablex,microtype}
-
-\usepackage[pdftex]{graphicx}
-
-\usepackage{ptex2tex}
-% #ifdef MINTED
-\usepackage{minted}
-\usemintedstyle{default}
-% #endif
-
-\usepackage[T1]{fontenc}
-%\usepackage[latin1]{inputenc}
-\usepackage{ucs}
-\usepackage[utf8x]{inputenc}
-
-\usepackage{lmodern} % Latin Modern fonts derived from Computer Modern
-
-% Hyperlinks in PDF:
-\definecolor{linkcolor}{rgb}{0,0,0.4}
-\usepackage{hyperref}
-\hypersetup{
- breaklinks=true,
- colorlinks=true,
- linkcolor=linkcolor,
- urlcolor=linkcolor,
- citecolor=black,
- filecolor=black,
- %filecolor=blue,
- pdfmenubar=true,
- pdftoolbar=true,
- bookmarksdepth=3 % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
- }
-%\hyperbaseurl{} % hyperlinks are relative to this root
-
-\setcounter{tocdepth}{2} % levels in table of contents
-
-% --- fancyhdr package for fancy headers ---
-\usepackage{fancyhdr}
-\fancyhf{} % sets both header and footer to nothing
-\renewcommand{\headrulewidth}{0pt}
-\fancyfoot[LE,RO]{\thepage}
-% Ensure copyright on titlepage (article style) and chapter pages (book style)
-\fancypagestyle{plain}{
- \fancyhf{}
- \fancyfoot[C]{{\footnotesize \copyright\ 1999-2019, "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
-% \renewcommand{\footrulewidth}{0mm}
- \renewcommand{\headrulewidth}{0mm}
-}
-% Ensure copyright on titlepages with \thispagestyle{empty}
-\fancypagestyle{empty}{
- \fancyhf{}
- \fancyfoot[C]{{\footnotesize \copyright\ 1999-2019, "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
- \renewcommand{\footrulewidth}{0mm}
- \renewcommand{\headrulewidth}{0mm}
-}
-
-\pagestyle{fancy}
-
-
-% prevent orhpans and widows
-\clubpenalty = 10000
-\widowpenalty = 10000
-
-% --- end of standard preamble for documents ---
-
-
-% insert custom LaTeX commands...
-
-\raggedbottom
-\makeindex
-\usepackage[totoc]{idxlayout} % for index in the toc
-\usepackage[nottoc]{tocbibind} % for references/bibliography in the toc
-
-%-------------------- end preamble ----------------------
-
-\begin{document}
-
-% matching end for #ifdef PREAMBLE
-% #endif
-
-\newcommand{\exercisesection}[1]{\subsection*{#1}}
-
-
-% ------------------- main content ----------------------
-
-
-
-% ----------------- title -------------------------
-
-\thispagestyle{empty}
-
-\begin{center}
-{\LARGE\bf
-\begin{spacing}{1.25}
-Project 1 on Machine Learning, deadline September 30, 2019
-\end{spacing}
-}
-\end{center}
-
-% ----------------- author(s) -------------------------
-
-\begin{center}
-{\bf \href{{http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html}}{Data Analysis and Machine Learning FYS-STK3155/FYS4155}}
-\end{center}
-
- \begin{center}
-% List of all institutions:
-\centerline{{\small Department of Physics, University of Oslo, Norway}}
-\end{center}
-
-% ----------------- end author(s) -------------------------
-
-% --- begin date ---
-\begin{center}
-Aug 29, 2019
-\end{center}
-% --- end date ---
-
-\vspace{1cm}
-
-
-\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,
-Ridge regression and finally Lasso regression.
-The methods are in turn combined with resampling techniques.
-
-We will first study how to fit polynomials to a specific
-two-dimensional function called \href{{http://www.dtic.mil/dtic/tr/fulltext/u2/a081688.pdf}}{Franke's
-function}. This
-is a function which has been widely used when testing various
-interpolation and fitting algorithms. Furthermore, after having
-established the model and the method, we will employ resamling
-techniques such as cross-validation in order to perform a
-proper assessment of our models. We will also study in detail the
-so-called Bias-Variance trade off.
-
-
-The Franke function, which is a weighted sum of four exponentials reads as follows
-\begin{align*}
-f(x,y) &= \frac{3}{4}\exp{\left(-\frac{(9x-2)^2}{4} - \frac{(9y-2)^2}{4}\right)}+\frac{3}{4}\exp{\left(-\frac{(9x+1)^2}{49}- \frac{(9y+1)}{10}\right)} \\
-&+\frac{1}{2}\exp{\left(-\frac{(9x-7)^2}{4} - \frac{(9y-3)^2}{4}\right)} -\frac{1}{5}\exp{\left(-(9x-4)^2 - (9y-7)^2\right) }.
-\end{align*}
-
-The function will be defined for $x,y\in [0,1]$. Our first step will
-be to perform an OLS regression analysis of this function, trying out
-a polynomial fit with an $x$ and $y$ dependence of the form $[x, y,
-x^2, y^2, xy, \dots]$. We will also include cross-validation as
-resampling technique. As in homeworks 1 and 2, we can use a uniform
-distribution to set up the arrays of values for $x$ and $y$, or as in
-the example below just a set of fixed
-values for $x$ and $y$ with a given step
-size. We will fit a
-function (for example a polynomial) of $x$ and $y$. Thereafter we
-will repeat much of the same procedure using the Ridge and Lasso
-regression methods, introducing thus a dependence on the bias
-(penalty) $\lambda$.
-
-Finally we are going to use (real) digital terrain data and try to
-reproduce these data using the same methods. We will also try to go
-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)
-\bpycod
-from mpl_toolkits.mplot3d import Axes3D
-import matplotlib.pyplot as plt
-from matplotlib import cm
-from matplotlib.ticker import LinearLocator, FormatStrFormatter
-import numpy as np
-from random import random, seed
-
-fig = plt.figure()
-ax = fig.gca(projection='3d')
-
-# Make data.
-x = np.arange(0, 1, 0.05)
-y = np.arange(0, 1, 0.05)
-x, y = np.meshgrid(x,y)
-
-
-def FrankeFunction(x,y):
- term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
- term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
- term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
- term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
- return term1 + term2 + term3 + term4
-
-
-z = FrankeFunction(x, y)
-
-# Plot the surface.
-surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm,
- linewidth=0, antialiased=False)
-
-# Customize the z axis.
-ax.set_zlim(-0.10, 1.40)
-ax.zaxis.set_major_locator(LinearLocator(10))
-ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
-
-# Add a color bar which maps values to colors.
-fig.colorbar(surf, shrink=0.5, aspect=5)
-
-plt.show()
-
-\epycod
-
-
-\paragraph{Part a): Ordinary Least Square on the Franke function with resampling.}
-We will generate our own dataset for a function
-$\mathrm{FrankeFunction}(x,y)$ with $x,y \in [0,1]$. The function
-$f(x,y)$ is the Franke function. You should explore also the addition
-an added stochastic noise to this function using the normal
-distribution $\cal{N}(0,1)$.
-
-Write your own code (using either a matrix inversion or a singular
-value decomposition from e.g., \textbf{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
-variances, evaluate the Mean Squared error (MSE)
-
-\[ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n}
-\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2,
-\]
-
-and the $R^2$ score function. If $\tilde{\hat{y}}_i$ is the predicted
-value of the $i-th$ sample and $y_i$ is the corresponding true value,
-then the score $R^2$ is defined as
-
-\[
-R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2},
-\]
-
-where we have defined the mean value of $\hat{y}$ as
-
-\[
-\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.
-\]
-
-\paragraph{Part b) Resampling techniques, adding more complexity.}
-Perform a resampling of the data where you split the data in training
-data and test data. Here you can write your own function or use the
-function for splitting training data provided by \textbf{Scikit-Learn}.
-This function is called $train\_test\_split$.
-
-It is normal in essentially all Machine Learning studies to split the
-data in a training set and a test set (sometimes also an additional
-validation set). There
-is no explicit recipe for how much data should be included as training
-data and say test data. An accepted rule of thumb is to use
-approximately $2/3$ to $4/5$ of the data as training data.
-
-
-Implement the $k$-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the $R^2$ functions resulting
-from the test data. You can compare your own code with that from
-\textbf{Scikit-Learn} if needed.
-
-
-
-
-\paragraph{Part c): Bias-variance tradeoff.}
-With a code which does OLS and includes resampling techniques,
-we will now discuss the bias-variance tradeoff in the context of
-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.
-
-Consider a
-dataset $\mathcal{L}$ consisting of the data
-$\mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\}$.
-
-Let us assume that the true data is generated from a noisy model
-
-\[
-\bm{y}=f(\boldsymbol{x}) + \bm{\epsilon}.
-\]
-
-Here $\epsilon$ is normally distributed with mean zero and standard
-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}$.
-
-The parameters $\bm{\beta}$ are in turn found by optimizing the means
-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].
-\]
-
-Show that you can rewrite this as
-\[
-\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2+\sigma^2.
-\]
-
-Explain what the terms mean, which one is the bias and which one is
-the variance and discuss their interpretations.
-
-
-Discuss the bias and variance tradeoff 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.
-
-Try to make a figure similar to Fig.~2.11 of Hastie, Tibshirani, and
-Friedman, see the references below. You will most likely not get an
-equally smooth curve!
-
-\paragraph{Part d): Ridge Regression on the Franke function with resampling.}
-Write your own code for the Ridge method, either using matrix
-inversion or the singular value decomposition as done in the previous
-exercise or howework 2 (see also chapter 3.4 of Hastie \emph{et al.},
-equations (3.43) and (3.44)). Perform the same analysis as in the
-previous exercises (for the same polynomials and include resampling
-techniques) but now for different values of $\lambda$. Compare and
-analyze your results with those obtained in parts a-c). Study the
-dependence on $\lambda$.
-
-Study also the bias-variance tradeoff as function of various values of
-the parameter $\lambda$. Comment your results.
-
-\paragraph{Part e): Lasso Regression on the Franke function with resampling.}
-This part is essentially a repeat of the previous two ones, but now
-with Lasso regression. Write either your own code or, in this case,
-you can also use the functionalities of \textbf{Scikit-Learn} (recommended).
-Give a
-critical discussion of the three methods and a judgement of which
-model fits the data best.
-
-\paragraph{Part f): Introducing real data.}
-With our codes functioning and having been tested properly on a
-simpler function we are now ready to look at real data. We will
-essentially repeat in part g) what was done in parts a-e). However, we
-need first to download the data and prepare properly the inputs to our
-codes. We are going to download digital terrain data from the website
-\href{{https://earthexplorer.usgs.gov/}}{\nolinkurl{https://earthexplorer.usgs.gov/}},
-
-In order to obtain data for a specific region, you need to register as
-a user (free) at this website and then decide upon which area you want
-to fetch the digital terrain data from. In order to be able to read
-the data properly, you need to specify that the format should be \textbf{SRTM
-Arc-Second Global} and download the data as a \textbf{GeoTIF} file. The
-files are then stored in \emph{tif} format which can be imported into a
-Python program using
-
-\bpycod
-scipy.misc.imread
-\epycod
-
-Here is a simple part of a Python code which reads and plots the data
-from such files
-
-\bpycod
-import numpy as np
-from imageio import imread
-import matplotlib.pyplot as plt
-from mpl_toolkits.mplot3d import Axes3D
-from matplotlib import cm
-
-# Load the terrain
-terrain1 = imread('SRTM_data_Norway_1.tif')
-# Show the terrain
-plt.figure()
-plt.title('Terrain over Norway 1')
-plt.imshow(terrain1, cmap='gray')
-plt.xlabel('X')
-plt.ylabel('Y')
-plt.show()
-\epycod
-
-If you should have problems in downloading the digital terrain data,
-we provide two examples under the data folder of project 1. One is
-from a region close to Stavanger in Norway and the other Møsvatn
-Austfjell, again in Norway.
-Feel free to produce your own terrain data.
-
-\paragraph{Part g) OLS, Ridge and Lasso regression with resampling.}
-Our final part deals with the parameterization of your digital terrain
-data. We will apply all three methods for linear regression as in
-parts a-c), the same type (or higher order) of polynomial
-approximation and the same resampling techniques to evaluate which
-model fits the data best.
-
-At the end, you should pesent a critical evaluation of your results
-and discuss the applicability of these regression methods to the type
-of data presented here.
-
-
-
-
-\subsection{Background literature}
-
-\begin{enumerate}
-\item For a discussion and derivation of the variances and mean squared errors using linear regression, see the \href{{https://arxiv.org/abs/1509.09169}}{Lecture notes on ridge regression by Wessel N. van Wieringen}
-
-\item The textbook of \href{{https://www.springer.com/gp/book/9780387848570}}{Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer}, chapters 3 and 7 are the most relevant ones for the analysis here.
-\end{enumerate}
-
-\noindent
-\subsection{Introduction to numerical projects}
-
-Here follows a brief recipe and recommendation on how to write a report for each
-project.
-
-\begin{itemize}
- \item Give a short description of the nature of the problem and the eventual numerical methods you have used.
-
- \item Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.
-
- \item Include the source code of your program. Comment your program properly.
-
- \item If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.
-
- \item Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.
-
- \item Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.
-
- \item Try to give an interpretation of you results in your answers to the problems.
-
- \item Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.
-
- \item Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
-\end{itemize}
-
-\noindent
-\subsection{Format for electronic delivery of report and programs}
-
-The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:
-
-\begin{itemize}
- \item Use Devilry to hand in your projects, log in at \href{{http://devilry.ifi.uio.no}}{\nolinkurl{http://devilry.ifi.uio.no}} with your normal UiO username and password and choose either 'fysstk3155' or 'fysstk4155'. There you can load up the files within the deadline.
-
- \item Upload \textbf{only} the report file! For the source code file(s) you have developed please provide us with your link to your github domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.
-
- \item In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.
-
- \item In this and all later projects, you should include tests (for example unit tests) of your code(s).
-
- \item Comments from us on your projects, approval or not, corrections to be made etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
-\end{itemize}
-
-\noindent
-Finally,
-we encourage you to collaborate. Optimal working groups consist of
-2-3 students. You can then hand in a common report.
-
-
-
-\subsection{Software and needed installations}
-
-If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages,
-we recommend that you install the following Python packages via \textbf{pip} as
-\begin{enumerate}
-\item pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow
-\end{enumerate}
-
-\noindent
-For Python3, replace \textbf{pip} with \textbf{pip3}.
-
-See below for a discussion of \textbf{tensorflow} and \textbf{scikit-learn}.
-
-For OSX users we recommend also, after having installed Xcode, to install \textbf{brew}. Brew allows
-for a seamless installation of additional software via for example
-\begin{enumerate}
-\item brew install python3
-\end{enumerate}
-
-\noindent
-For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
-you can use \textbf{pip} as well and simply install Python as
-\begin{enumerate}
-\item sudo apt-get install python3 (or python for python2.7)
-\end{enumerate}
-
-\noindent
-etc etc.
-
-If you don't want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up all relevant dependencies for Python, namely
-\begin{enumerate}
-\item \href{{https://docs.anaconda.com/}}{Anaconda} Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system \textbf{conda}
-
-\item \href{{https://www.enthought.com/product/canopy/}}{Enthought canopy} is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
-\end{enumerate}
-
-\noindent
-Popular software packages written in Python for ML are
-
-\begin{itemize}
-\item \href{{http://scikit-learn.org/stable/}}{Scikit-learn},
-
-\item \href{{https://www.tensorflow.org/}}{Tensorflow},
-
-\item \href{{http://pytorch.org/}}{PyTorch} and
-
-\item \href{{https://keras.io/}}{Keras}.
-\end{itemize}
-
-\noindent
-These are all freely available at their respective GitHub sites. They
-encompass communities of developers in the thousands or more. And the number
-of code developers and contributors keeps increasing.
-
-
-
-
-
-% ------------------- end of main content ---------------
-
-% #ifdef PREAMBLE
-\end{document}
-% #endif
-
diff --git a/doc/src/Projects/2019/Project1/Project1.pdf b/doc/src/Projects/2019/Project1/Project1.pdf
deleted file mode 100644
index 75bfa811c..000000000
Binary files a/doc/src/Projects/2019/Project1/Project1.pdf and /dev/null differ
diff --git a/doc/src/Projects/2019/Project1/Project1.tex b/doc/src/Projects/2019/Project1/Project1.tex
deleted file mode 100644
index 625b611c3..000000000
--- a/doc/src/Projects/2019/Project1/Project1.tex
+++ /dev/null
@@ -1,528 +0,0 @@
-%%
-%% Automatically generated file from DocOnce source
-%% (https://github.com/hplgit/doconce/)
-%%
-%%
-
-
-%-------------------- begin preamble ----------------------
-
-\documentclass[%
-oneside, % oneside: electronic viewing, twoside: printing
-final, % draft: marks overfull hboxes, figures with paths
-10pt]{article}
-
-\listfiles % print all files needed to compile this document
-
-\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
-\usepackage[table]{xcolor}
-\usepackage{bm,ltablex,microtype}
-
-\usepackage[pdftex]{graphicx}
-
-\usepackage{fancyvrb} % packages needed for verbatim environments
-
-\usepackage[T1]{fontenc}
-%\usepackage[latin1]{inputenc}
-\usepackage{ucs}
-\usepackage[utf8x]{inputenc}
-
-\usepackage{lmodern} % Latin Modern fonts derived from Computer Modern
-
-% Hyperlinks in PDF:
-\definecolor{linkcolor}{rgb}{0,0,0.4}
-\usepackage{hyperref}
-\hypersetup{
- breaklinks=true,
- colorlinks=true,
- linkcolor=linkcolor,
- urlcolor=linkcolor,
- citecolor=black,
- filecolor=black,
- %filecolor=blue,
- pdfmenubar=true,
- pdftoolbar=true,
- bookmarksdepth=3 % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
- }
-%\hyperbaseurl{} % hyperlinks are relative to this root
-
-\setcounter{tocdepth}{2} % levels in table of contents
-
-% --- fancyhdr package for fancy headers ---
-\usepackage{fancyhdr}
-\fancyhf{} % sets both header and footer to nothing
-\renewcommand{\headrulewidth}{0pt}
-\fancyfoot[LE,RO]{\thepage}
-% Ensure copyright on titlepage (article style) and chapter pages (book style)
-\fancypagestyle{plain}{
- \fancyhf{}
- \fancyfoot[C]{{\footnotesize \copyright\ 1999-2019, "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
-% \renewcommand{\footrulewidth}{0mm}
- \renewcommand{\headrulewidth}{0mm}
-}
-% Ensure copyright on titlepages with \thispagestyle{empty}
-\fancypagestyle{empty}{
- \fancyhf{}
- \fancyfoot[C]{{\footnotesize \copyright\ 1999-2019, "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
- \renewcommand{\footrulewidth}{0mm}
- \renewcommand{\headrulewidth}{0mm}
-}
-
-\pagestyle{fancy}
-
-
-% prevent orhpans and widows
-\clubpenalty = 10000
-\widowpenalty = 10000
-
-% --- end of standard preamble for documents ---
-
-
-% insert custom LaTeX commands...
-
-\raggedbottom
-\makeindex
-\usepackage[totoc]{idxlayout} % for index in the toc
-\usepackage[nottoc]{tocbibind} % for references/bibliography in the toc
-
-%-------------------- end preamble ----------------------
-
-\begin{document}
-
-% matching end for #ifdef PREAMBLE
-
-\newcommand{\exercisesection}[1]{\subsection*{#1}}
-
-
-% ------------------- main content ----------------------
-
-
-
-% ----------------- title -------------------------
-
-\thispagestyle{empty}
-
-\begin{center}
-{\LARGE\bf
-\begin{spacing}{1.25}
-Project 1 on Machine Learning, deadline September 30, 2019
-\end{spacing}
-}
-\end{center}
-
-% ----------------- author(s) -------------------------
-
-\begin{center}
-{\bf \href{{http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html}}{Data Analysis and Machine Learning FYS-STK3155/FYS4155}}
-\end{center}
-
- \begin{center}
-% List of all institutions:
-\centerline{{\small Department of Physics, University of Oslo, Norway}}
-\end{center}
-
-% ----------------- end author(s) -------------------------
-
-% --- begin date ---
-\begin{center}
-Aug 29, 2019
-\end{center}
-% --- end date ---
-
-\vspace{1cm}
-
-
-\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,
-Ridge regression and finally Lasso regression.
-The methods are in turn combined with resampling techniques.
-
-We will first study how to fit polynomials to a specific
-two-dimensional function called \href{{http://www.dtic.mil/dtic/tr/fulltext/u2/a081688.pdf}}{Franke's
-function}. This
-is a function which has been widely used when testing various
-interpolation and fitting algorithms. Furthermore, after having
-established the model and the method, we will employ resamling
-techniques such as cross-validation in order to perform a
-proper assessment of our models. We will also study in detail the
-so-called Bias-Variance trade off.
-
-
-The Franke function, which is a weighted sum of four exponentials reads as follows
-\begin{align*}
-f(x,y) &= \frac{3}{4}\exp{\left(-\frac{(9x-2)^2}{4} - \frac{(9y-2)^2}{4}\right)}+\frac{3}{4}\exp{\left(-\frac{(9x+1)^2}{49}- \frac{(9y+1)}{10}\right)} \\
-&+\frac{1}{2}\exp{\left(-\frac{(9x-7)^2}{4} - \frac{(9y-3)^2}{4}\right)} -\frac{1}{5}\exp{\left(-(9x-4)^2 - (9y-7)^2\right) }.
-\end{align*}
-
-The function will be defined for $x,y\in [0,1]$. Our first step will
-be to perform an OLS regression analysis of this function, trying out
-a polynomial fit with an $x$ and $y$ dependence of the form $[x, y,
-x^2, y^2, xy, \dots]$. We will also include cross-validation as
-resampling technique. As in homeworks 1 and 2, we can use a uniform
-distribution to set up the arrays of values for $x$ and $y$, or as in
-the example below just a set of fixed
-values for $x$ and $y$ with a given step
-size. We will fit a
-function (for example a polynomial) of $x$ and $y$. Thereafter we
-will repeat much of the same procedure using the Ridge and Lasso
-regression methods, introducing thus a dependence on the bias
-(penalty) $\lambda$.
-
-Finally we are going to use (real) digital terrain data and try to
-reproduce these data using the same methods. We will also try to go
-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)
-\begin{print}
-from mpl_toolkits.mplot3d import Axes3D
-import matplotlib.pyplot as plt
-from matplotlib import cm
-from matplotlib.ticker import LinearLocator, FormatStrFormatter
-import numpy as np
-from random import random, seed
-
-fig = plt.figure()
-ax = fig.gca(projection='3d')
-
-# Make data.
-x = np.arange(0, 1, 0.05)
-y = np.arange(0, 1, 0.05)
-x, y = np.meshgrid(x,y)
-
-
-def FrankeFunction(x,y):
- term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
- term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
- term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
- term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
- return term1 + term2 + term3 + term4
-
-
-z = FrankeFunction(x, y)
-
-# Plot the surface.
-surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm,
- linewidth=0, antialiased=False)
-
-# Customize the z axis.
-ax.set_zlim(-0.10, 1.40)
-ax.zaxis.set_major_locator(LinearLocator(10))
-ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
-
-# Add a color bar which maps values to colors.
-fig.colorbar(surf, shrink=0.5, aspect=5)
-
-plt.show()
-
-\end{print}
-
-
-\paragraph{Part a): Ordinary Least Square on the Franke function with resampling.}
-We will generate our own dataset for a function
-$\mathrm{FrankeFunction}(x,y)$ with $x,y \in [0,1]$. The function
-$f(x,y)$ is the Franke function. You should explore also the addition
-an added stochastic noise to this function using the normal
-distribution $\cal{N}(0,1)$.
-
-Write your own code (using either a matrix inversion or a singular
-value decomposition from e.g., \textbf{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
-variances, evaluate the Mean Squared error (MSE)
-
-\[ MSE(\hat{y},\hat{\tilde{y}}) = \frac{1}{n}
-\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2,
-\]
-
-and the $R^2$ score function. If $\tilde{\hat{y}}_i$ is the predicted
-value of the $i-th$ sample and $y_i$ is the corresponding true value,
-then the score $R^2$ is defined as
-
-\[
-R^2(\hat{y}, \tilde{\hat{y}}) = 1 - \frac{\sum_{i=0}^{n - 1} (y_i - \tilde{y}_i)^2}{\sum_{i=0}^{n - 1} (y_i - \bar{y})^2},
-\]
-
-where we have defined the mean value of $\hat{y}$ as
-
-\[
-\bar{y} = \frac{1}{n} \sum_{i=0}^{n - 1} y_i.
-\]
-
-\paragraph{Part b) Resampling techniques, adding more complexity.}
-Perform a resampling of the data where you split the data in training
-data and test data. Here you can write your own function or use the
-function for splitting training data provided by \textbf{Scikit-Learn}.
-This function is called $train\_test\_split$.
-
-It is normal in essentially all Machine Learning studies to split the
-data in a training set and a test set (sometimes also an additional
-validation set). There
-is no explicit recipe for how much data should be included as training
-data and say test data. An accepted rule of thumb is to use
-approximately $2/3$ to $4/5$ of the data as training data.
-
-
-Implement the $k$-fold cross-validation algorithm (write your own
-code) and evaluate again the MSE and the $R^2$ functions resulting
-from the test data. You can compare your own code with that from
-\textbf{Scikit-Learn} if needed.
-
-
-
-
-\paragraph{Part c): Bias-variance tradeoff.}
-With a code which does OLS and includes resampling techniques,
-we will now discuss the bias-variance tradeoff in the context of
-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.
-
-Consider a
-dataset $\mathcal{L}$ consisting of the data
-$\mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\}$.
-
-Let us assume that the true data is generated from a noisy model
-
-\[
-\bm{y}=f(\boldsymbol{x}) + \bm{\epsilon}.
-\]
-
-Here $\epsilon$ is normally distributed with mean zero and standard
-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}$.
-
-The parameters $\bm{\beta}$ are in turn found by optimizing the means
-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].
-\]
-
-Show that you can rewrite this as
-\[
-\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2+\sigma^2.
-\]
-
-Explain what the terms mean, which one is the bias and which one is
-the variance and discuss their interpretations.
-
-
-Discuss the bias and variance tradeoff 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.
-
-Try to make a figure similar to Fig.~2.11 of Hastie, Tibshirani, and
-Friedman, see the references below. You will most likely not get an
-equally smooth curve!
-
-\paragraph{Part d): Ridge Regression on the Franke function with resampling.}
-Write your own code for the Ridge method, either using matrix
-inversion or the singular value decomposition as done in the previous
-exercise or howework 2 (see also chapter 3.4 of Hastie \emph{et al.},
-equations (3.43) and (3.44)). Perform the same analysis as in the
-previous exercises (for the same polynomials and include resampling
-techniques) but now for different values of $\lambda$. Compare and
-analyze your results with those obtained in parts a-c). Study the
-dependence on $\lambda$.
-
-Study also the bias-variance tradeoff as function of various values of
-the parameter $\lambda$. Comment your results.
-
-\paragraph{Part e): Lasso Regression on the Franke function with resampling.}
-This part is essentially a repeat of the previous two ones, but now
-with Lasso regression. Write either your own code or, in this case,
-you can also use the functionalities of \textbf{Scikit-Learn} (recommended).
-Give a
-critical discussion of the three methods and a judgement of which
-model fits the data best.
-
-\paragraph{Part f): Introducing real data.}
-With our codes functioning and having been tested properly on a
-simpler function we are now ready to look at real data. We will
-essentially repeat in part g) what was done in parts a-e). However, we
-need first to download the data and prepare properly the inputs to our
-codes. We are going to download digital terrain data from the website
-\href{{https://earthexplorer.usgs.gov/}}{\nolinkurl{https://earthexplorer.usgs.gov/}},
-
-In order to obtain data for a specific region, you need to register as
-a user (free) at this website and then decide upon which area you want
-to fetch the digital terrain data from. In order to be able to read
-the data properly, you need to specify that the format should be \textbf{SRTM
-Arc-Second Global} and download the data as a \textbf{GeoTIF} file. The
-files are then stored in \emph{tif} format which can be imported into a
-Python program using
-
-\begin{print}
-scipy.misc.imread
-\end{print}
-
-Here is a simple part of a Python code which reads and plots the data
-from such files
-
-\begin{print}
-import numpy as np
-from imageio import imread
-import matplotlib.pyplot as plt
-from mpl_toolkits.mplot3d import Axes3D
-from matplotlib import cm
-
-# Load the terrain
-terrain1 = imread('SRTM_data_Norway_1.tif')
-# Show the terrain
-plt.figure()
-plt.title('Terrain over Norway 1')
-plt.imshow(terrain1, cmap='gray')
-plt.xlabel('X')
-plt.ylabel('Y')
-plt.show()
-\end{print}
-
-If you should have problems in downloading the digital terrain data,
-we provide two examples under the data folder of project 1. One is
-from a region close to Stavanger in Norway and the other Møsvatn
-Austfjell, again in Norway.
-Feel free to produce your own terrain data.
-
-\paragraph{Part g) OLS, Ridge and Lasso regression with resampling.}
-Our final part deals with the parameterization of your digital terrain
-data. We will apply all three methods for linear regression as in
-parts a-c), the same type (or higher order) of polynomial
-approximation and the same resampling techniques to evaluate which
-model fits the data best.
-
-At the end, you should pesent a critical evaluation of your results
-and discuss the applicability of these regression methods to the type
-of data presented here.
-
-
-
-
-\subsection*{Background literature}
-
-\begin{enumerate}
-\item For a discussion and derivation of the variances and mean squared errors using linear regression, see the \href{{https://arxiv.org/abs/1509.09169}}{Lecture notes on ridge regression by Wessel N. van Wieringen}
-
-\item The textbook of \href{{https://www.springer.com/gp/book/9780387848570}}{Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer}, chapters 3 and 7 are the most relevant ones for the analysis here.
-\end{enumerate}
-
-\noindent
-\subsection*{Introduction to numerical projects}
-
-Here follows a brief recipe and recommendation on how to write a report for each
-project.
-
-\begin{itemize}
- \item Give a short description of the nature of the problem and the eventual numerical methods you have used.
-
- \item Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.
-
- \item Include the source code of your program. Comment your program properly.
-
- \item If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.
-
- \item Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.
-
- \item Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.
-
- \item Try to give an interpretation of you results in your answers to the problems.
-
- \item Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.
-
- \item Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
-\end{itemize}
-
-\noindent
-\subsection*{Format for electronic delivery of report and programs}
-
-The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:
-
-\begin{itemize}
- \item Use Devilry to hand in your projects, log in at \href{{http://devilry.ifi.uio.no}}{\nolinkurl{http://devilry.ifi.uio.no}} with your normal UiO username and password and choose either 'fysstk3155' or 'fysstk4155'. There you can load up the files within the deadline.
-
- \item Upload \textbf{only} the report file! For the source code file(s) you have developed please provide us with your link to your github domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.
-
- \item In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.
-
- \item In this and all later projects, you should include tests (for example unit tests) of your code(s).
-
- \item Comments from us on your projects, approval or not, corrections to be made etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
-\end{itemize}
-
-\noindent
-Finally,
-we encourage you to collaborate. Optimal working groups consist of
-2-3 students. You can then hand in a common report.
-
-
-
-\subsection*{Software and needed installations}
-
-If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages,
-we recommend that you install the following Python packages via \textbf{pip} as
-\begin{enumerate}
-\item pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow
-\end{enumerate}
-
-\noindent
-For Python3, replace \textbf{pip} with \textbf{pip3}.
-
-See below for a discussion of \textbf{tensorflow} and \textbf{scikit-learn}.
-
-For OSX users we recommend also, after having installed Xcode, to install \textbf{brew}. Brew allows
-for a seamless installation of additional software via for example
-\begin{enumerate}
-\item brew install python3
-\end{enumerate}
-
-\noindent
-For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
-you can use \textbf{pip} as well and simply install Python as
-\begin{enumerate}
-\item sudo apt-get install python3 (or python for python2.7)
-\end{enumerate}
-
-\noindent
-etc etc.
-
-If you don't want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up all relevant dependencies for Python, namely
-\begin{enumerate}
-\item \href{{https://docs.anaconda.com/}}{Anaconda} Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system \textbf{conda}
-
-\item \href{{https://www.enthought.com/product/canopy/}}{Enthought canopy} is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
-\end{enumerate}
-
-\noindent
-Popular software packages written in Python for ML are
-
-\begin{itemize}
-\item \href{{http://scikit-learn.org/stable/}}{Scikit-learn},
-
-\item \href{{https://www.tensorflow.org/}}{Tensorflow},
-
-\item \href{{http://pytorch.org/}}{PyTorch} and
-
-\item \href{{https://keras.io/}}{Keras}.
-\end{itemize}
-
-\noindent
-These are all freely available at their respective GitHub sites. They
-encompass communities of developers in the thousands or more. And the number
-of code developers and contributors keeps increasing.
-
-
-
-
-
-% ------------------- end of main content ---------------
-
-\end{document}
-
diff --git a/doc/src/Projects/2019/Project1/README.txt b/doc/src/Projects/2019/Project1/README.txt
deleted file mode 100644
index 08cc9f17c..000000000
--- a/doc/src/Projects/2019/Project1/README.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-This IPython notebook Project1.ipynb does not require any additional
-programs.
diff --git a/doc/src/Projects/2019/Project1/ipynb-Project1-src.tar.gz b/doc/src/Projects/2019/Project1/ipynb-Project1-src.tar.gz
deleted file mode 100644
index 3498e5f42..000000000
Binary files a/doc/src/Projects/2019/Project1/ipynb-Project1-src.tar.gz and /dev/null differ
diff --git a/doc/src/Regression/Regression.do.txt b/doc/src/Regression/Regression.do.txt
index c42997483..f3517e5fa 100644
--- a/doc/src/Regression/Regression.do.txt
+++ b/doc/src/Regression/Regression.do.txt
@@ -2809,9 +2809,6 @@ plt.show()
!ec
-!split
-===== Cross-validation =====
-
!split
===== Various steps in cross-validation =====
@@ -2851,14 +2848,26 @@ cross-validation (LOOCV).
* Repeat the first three steps such that each sample plays the role of the test set once.
-* Average the prediction performances of the test sets at each grid point of the penalty bias/parameter by computing the *cross-validated log-likelihood*. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
+* Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as
!bt
\begin{align*}
\frac{1}{n} \sum_{i = 1}^n \log\{L[y_i, \mathbf{X}_{i, \ast}; \bm{\beta}_{-i}(\lambda), \bm{\sigma}_{-i}^2(\lambda)]\}.
\end{align*}
!et
-* The value of the penalty parameter that maximizes the cross-validated log-likelihood is the value of choice. Or we can use the MSE or the R2 score functions.
+!split
+===== Cross-validation in brief =====
+
+For the various values of $k$
+
+o shuffle the dataset randomly.
+o Split the dataset into $k$ groups.
+o For each unique group:
+ o Decide which group to use as set for test data
+ o Take the remaining groups as a training data set
+ o Fit a model on the training set and evaluate it on the test set
+ o Retain the evaluation score and discard the model
+o Summarize the model using the sample of model evaluation scores