diff --git a/doc/pub/week37/html/._week37-bs000.html b/doc/pub/week37/html/._week37-bs000.html index 8082be385..6902b10c3 100644 --- a/doc/pub/week37/html/._week37-bs000.html +++ b/doc/pub/week37/html/._week37-bs000.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs001.html b/doc/pub/week37/html/._week37-bs001.html index 79bd2e925..a2e0eeb5c 100644 --- a/doc/pub/week37/html/._week37-bs001.html +++ b/doc/pub/week37/html/._week37-bs001.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • @@ -292,7 +297,7 @@ MathJax.Hub.Config({
  • Lecture from last week on calculations of expectation values
  • Exercise for week 37
  • Work on project 1
  • -
  • See also additional note on scaling (jupyter-notebook) sent separately. This will be discussed during the first hour of each session.
  • +
  • See also additional note on scaling (jupyter-notebook) sent separately. This will be discussed during the first hour of each session. This note is added at the end of these slides.
  • For more discussions of Ridge regression and calculation of averages, Wessel van Wieringen's article is highly recommended.
  • @@ -302,9 +307,9 @@ MathJax.Hub.Config({
    diff --git a/doc/pub/week37/html/._week37-bs004.html b/doc/pub/week37/html/._week37-bs004.html index 066f99576..14b101fd7 100644 --- a/doc/pub/week37/html/._week37-bs004.html +++ b/doc/pub/week37/html/._week37-bs004.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs005.html b/doc/pub/week37/html/._week37-bs005.html index e010be5c5..a59c13440 100644 --- a/doc/pub/week37/html/._week37-bs005.html +++ b/doc/pub/week37/html/._week37-bs005.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs006.html b/doc/pub/week37/html/._week37-bs006.html index 0ab887889..ea6933881 100644 --- a/doc/pub/week37/html/._week37-bs006.html +++ b/doc/pub/week37/html/._week37-bs006.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs007.html b/doc/pub/week37/html/._week37-bs007.html index d9c3f8dbe..20be97c3b 100644 --- a/doc/pub/week37/html/._week37-bs007.html +++ b/doc/pub/week37/html/._week37-bs007.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs008.html b/doc/pub/week37/html/._week37-bs008.html index 2d8447080..1e8a42fe8 100644 --- a/doc/pub/week37/html/._week37-bs008.html +++ b/doc/pub/week37/html/._week37-bs008.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs009.html b/doc/pub/week37/html/._week37-bs009.html index 7d9e9ace0..50ad45797 100644 --- a/doc/pub/week37/html/._week37-bs009.html +++ b/doc/pub/week37/html/._week37-bs009.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs010.html b/doc/pub/week37/html/._week37-bs010.html index b570822b6..2ad6f637b 100644 --- a/doc/pub/week37/html/._week37-bs010.html +++ b/doc/pub/week37/html/._week37-bs010.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs011.html b/doc/pub/week37/html/._week37-bs011.html index 3eaafe8e9..0f13609aa 100644 --- a/doc/pub/week37/html/._week37-bs011.html +++ b/doc/pub/week37/html/._week37-bs011.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs012.html b/doc/pub/week37/html/._week37-bs012.html index c015911a9..f1875746e 100644 --- a/doc/pub/week37/html/._week37-bs012.html +++ b/doc/pub/week37/html/._week37-bs012.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs013.html b/doc/pub/week37/html/._week37-bs013.html index ea2a5ef7e..223843c49 100644 --- a/doc/pub/week37/html/._week37-bs013.html +++ b/doc/pub/week37/html/._week37-bs013.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs014.html b/doc/pub/week37/html/._week37-bs014.html index 2ad30cc12..3bb56e561 100644 --- a/doc/pub/week37/html/._week37-bs014.html +++ b/doc/pub/week37/html/._week37-bs014.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs015.html b/doc/pub/week37/html/._week37-bs015.html index 735e52977..93d468e77 100644 --- a/doc/pub/week37/html/._week37-bs015.html +++ b/doc/pub/week37/html/._week37-bs015.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs016.html b/doc/pub/week37/html/._week37-bs016.html index 18e4be95f..a2a76f658 100644 --- a/doc/pub/week37/html/._week37-bs016.html +++ b/doc/pub/week37/html/._week37-bs016.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs017.html b/doc/pub/week37/html/._week37-bs017.html index 37129607a..d88306171 100644 --- a/doc/pub/week37/html/._week37-bs017.html +++ b/doc/pub/week37/html/._week37-bs017.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs018.html b/doc/pub/week37/html/._week37-bs018.html index b9e639345..7eac3c3b0 100644 --- a/doc/pub/week37/html/._week37-bs018.html +++ b/doc/pub/week37/html/._week37-bs018.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs019.html b/doc/pub/week37/html/._week37-bs019.html index c3a711988..84a9d7240 100644 --- a/doc/pub/week37/html/._week37-bs019.html +++ b/doc/pub/week37/html/._week37-bs019.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs020.html b/doc/pub/week37/html/._week37-bs020.html index a78a6728f..0a0e64823 100644 --- a/doc/pub/week37/html/._week37-bs020.html +++ b/doc/pub/week37/html/._week37-bs020.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs021.html b/doc/pub/week37/html/._week37-bs021.html index 4fe568dcc..956ac8462 100644 --- a/doc/pub/week37/html/._week37-bs021.html +++ b/doc/pub/week37/html/._week37-bs021.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs022.html b/doc/pub/week37/html/._week37-bs022.html index 1a71eb132..4f9f709e4 100644 --- a/doc/pub/week37/html/._week37-bs022.html +++ b/doc/pub/week37/html/._week37-bs022.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs023.html b/doc/pub/week37/html/._week37-bs023.html index 97e3a7f5a..4c86f6e3a 100644 --- a/doc/pub/week37/html/._week37-bs023.html +++ b/doc/pub/week37/html/._week37-bs023.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs024.html b/doc/pub/week37/html/._week37-bs024.html index 4c6442272..4988dd16b 100644 --- a/doc/pub/week37/html/._week37-bs024.html +++ b/doc/pub/week37/html/._week37-bs024.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs025.html b/doc/pub/week37/html/._week37-bs025.html index dc4d403c5..f9eb84d36 100644 --- a/doc/pub/week37/html/._week37-bs025.html +++ b/doc/pub/week37/html/._week37-bs025.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs026.html b/doc/pub/week37/html/._week37-bs026.html index 61f46a9a9..34480554f 100644 --- a/doc/pub/week37/html/._week37-bs026.html +++ b/doc/pub/week37/html/._week37-bs026.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs027.html b/doc/pub/week37/html/._week37-bs027.html index 9198ae859..d616291fe 100644 --- a/doc/pub/week37/html/._week37-bs027.html +++ b/doc/pub/week37/html/._week37-bs027.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs028.html b/doc/pub/week37/html/._week37-bs028.html index dd893fd08..56172e442 100644 --- a/doc/pub/week37/html/._week37-bs028.html +++ b/doc/pub/week37/html/._week37-bs028.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs029.html b/doc/pub/week37/html/._week37-bs029.html index 9fd0db0fb..a8ccc4ae4 100644 --- a/doc/pub/week37/html/._week37-bs029.html +++ b/doc/pub/week37/html/._week37-bs029.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs030.html b/doc/pub/week37/html/._week37-bs030.html index 9f04ef298..7bcdfc3b4 100644 --- a/doc/pub/week37/html/._week37-bs030.html +++ b/doc/pub/week37/html/._week37-bs030.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs031.html b/doc/pub/week37/html/._week37-bs031.html index 778b85b7a..8d5522a96 100644 --- a/doc/pub/week37/html/._week37-bs031.html +++ b/doc/pub/week37/html/._week37-bs031.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs032.html b/doc/pub/week37/html/._week37-bs032.html index 7dd34d435..fa71a4509 100644 --- a/doc/pub/week37/html/._week37-bs032.html +++ b/doc/pub/week37/html/._week37-bs032.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs033.html b/doc/pub/week37/html/._week37-bs033.html index f1e1ec47b..bec9fcdc1 100644 --- a/doc/pub/week37/html/._week37-bs033.html +++ b/doc/pub/week37/html/._week37-bs033.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs034.html b/doc/pub/week37/html/._week37-bs034.html index 4e93a3e15..a9dadb858 100644 --- a/doc/pub/week37/html/._week37-bs034.html +++ b/doc/pub/week37/html/._week37-bs034.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs035.html b/doc/pub/week37/html/._week37-bs035.html index 5a4d29bfb..426d19a67 100644 --- a/doc/pub/week37/html/._week37-bs035.html +++ b/doc/pub/week37/html/._week37-bs035.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs036.html b/doc/pub/week37/html/._week37-bs036.html index 0905cbfcc..842ddadc6 100644 --- a/doc/pub/week37/html/._week37-bs036.html +++ b/doc/pub/week37/html/._week37-bs036.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs037.html b/doc/pub/week37/html/._week37-bs037.html index 8829ea157..addbbeec7 100644 --- a/doc/pub/week37/html/._week37-bs037.html +++ b/doc/pub/week37/html/._week37-bs037.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs038.html b/doc/pub/week37/html/._week37-bs038.html index 791e92139..386800081 100644 --- a/doc/pub/week37/html/._week37-bs038.html +++ b/doc/pub/week37/html/._week37-bs038.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs039.html b/doc/pub/week37/html/._week37-bs039.html index ac051d273..2e7903a29 100644 --- a/doc/pub/week37/html/._week37-bs039.html +++ b/doc/pub/week37/html/._week37-bs039.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs040.html b/doc/pub/week37/html/._week37-bs040.html index 99939da47..a868af694 100644 --- a/doc/pub/week37/html/._week37-bs040.html +++ b/doc/pub/week37/html/._week37-bs040.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs041.html b/doc/pub/week37/html/._week37-bs041.html index 4424b0e30..2fb8ef012 100644 --- a/doc/pub/week37/html/._week37-bs041.html +++ b/doc/pub/week37/html/._week37-bs041.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs042.html b/doc/pub/week37/html/._week37-bs042.html index 2f52f314c..1d0a439c6 100644 --- a/doc/pub/week37/html/._week37-bs042.html +++ b/doc/pub/week37/html/._week37-bs042.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs043.html b/doc/pub/week37/html/._week37-bs043.html index 0417ce3df..1992b6649 100644 --- a/doc/pub/week37/html/._week37-bs043.html +++ b/doc/pub/week37/html/._week37-bs043.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs044.html b/doc/pub/week37/html/._week37-bs044.html index 49d6712e7..18c6a1d8d 100644 --- a/doc/pub/week37/html/._week37-bs044.html +++ b/doc/pub/week37/html/._week37-bs044.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs045.html b/doc/pub/week37/html/._week37-bs045.html index f67ed982c..2f9b55ddc 100644 --- a/doc/pub/week37/html/._week37-bs045.html +++ b/doc/pub/week37/html/._week37-bs045.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs046.html b/doc/pub/week37/html/._week37-bs046.html index bf4f7de79..e30e6ea4b 100644 --- a/doc/pub/week37/html/._week37-bs046.html +++ b/doc/pub/week37/html/._week37-bs046.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs047.html b/doc/pub/week37/html/._week37-bs047.html index 4f56d3f72..cd159efc3 100644 --- a/doc/pub/week37/html/._week37-bs047.html +++ b/doc/pub/week37/html/._week37-bs047.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs048.html b/doc/pub/week37/html/._week37-bs048.html index a3e322167..05b151949 100644 --- a/doc/pub/week37/html/._week37-bs048.html +++ b/doc/pub/week37/html/._week37-bs048.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/._week37-bs049.html b/doc/pub/week37/html/._week37-bs049.html index beebc529a..ba772ae3f 100644 --- a/doc/pub/week37/html/._week37-bs049.html +++ b/doc/pub/week37/html/._week37-bs049.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/week37-bs.html b/doc/pub/week37/html/week37-bs.html index 8082be385..6902b10c3 100644 --- a/doc/pub/week37/html/week37-bs.html +++ b/doc/pub/week37/html/week37-bs.html @@ -185,7 +185,11 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -272,6 +276,7 @@ MathJax.Hub.Config({
  • Code Example for Cross-validation and \( k \)-fold Cross-validation
  • More examples on bootstrap and cross-validation and errors
  • The same example but now with cross-validation
  • +
  • Notes on scaling with examples
  • diff --git a/doc/pub/week37/html/week37-reveal.html b/doc/pub/week37/html/week37-reveal.html index eebe47125..56a0c5bee 100644 --- a/doc/pub/week37/html/week37-reveal.html +++ b/doc/pub/week37/html/week37-reveal.html @@ -210,7 +210,7 @@ MathJax.Hub.Config({

  • Work on project 1
  • -

  • See also additional note on scaling (jupyter-notebook) sent separately. This will be discussed during the first hour of each session.
  • +

  • See also additional note on scaling (jupyter-notebook) sent separately. This will be discussed during the first hour of each session. This note is added at the end of these slides.
  • For more discussions of Ridge regression and calculation of averages, Wessel van Wieringen's article is highly recommended.
  • @@ -221,11 +221,11 @@ MathJax.Hub.Config({

    +

    Notes on scaling with examples

    + +

    The programs here use both ordinrary least squares (OLS) and Ridge +regression with one value only for the hyperparameter \( \lambda \). The +first example has no scaling and includes the intercept as well and we +are trying to fit a second-order polynomial. The second code takes out +the intercept and subtracts the mean values of each column of the +design matrix and the mean value of the outputs. +

    + +

    The third and final code uses Scikit-Learn as library in order to +calculate the optimal parameters for OLS and Ridge regression. Note +that it is highly recommended to not include the intercept in Ridge +and Lasso regression, in order to avoid penalizing the optimization by +the intercept. The second and third codes do thus not include the +intercept. In the second code we do the scaling ourselves while the +last code uses the standard scaler option included in Scikit-Learn, known as centering (where +we subtract the mean values). +

    + + + +
    +
    +
    +
    +
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.linear_model import LinearRegression
    +from sklearn.preprocessing import PolynomialFeatures
    +from sklearn.model_selection import train_test_split
    +from sklearn.preprocessing import StandardScaler
    +
    +def MSE(y_data,y_model):
    +    n = np.size(y_model)
    +    return np.sum((y_data-y_model)**2)/n
    +
    +def OLS_fit_beta(X, y):
    +    return np.linalg.pinv(X.T @ X) @ X.T @ y
    +
    +def Ridge_fit_beta(X, y,L,d):
    +    I = np.eye(d,d)
    +    return np.linalg.pinv(X.T @ X + L*I) @ X.T @ y
    +
    +# Same random numbers for each test.
    +np.random.seed(2018)
    +n = 100
    +d = 3
    +# hyperparameter lambda
    +Lambda = 0.01
    +
    +# Make data set, simple second-order polynomial
    +x = np.linspace(-3, 3, n)
    +y = 2.0 + 0.5*x + 5.0*(x**2)+ np.random.randn(n)
    +
    +# The design matrix X includes the intercept and no scaling is made
    +X = np.zeros((len(x), d))
    +for p in range(d):     
    +    X[:, p] = x ** (p) 
    +
    +
    +#Split data, no scaling is used and we include the intercept
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +
    +#Calculate beta, own code
    +beta_OLS = OLS_fit_beta(X_train, y_train)
    +beta_Ridge = Ridge_fit_beta(X_train, y_train,Lambda,d)
    +print(beta_OLS)
    +print(beta_Ridge)
    +#predict value
    +ytilde_test_OLS = X_test @ beta_OLS
    +ytilde_test_Ridge = X_test @ beta_Ridge
    +
    +#Calculate MSE
    +print("  ")
    +print("test MSE of OLS:")
    +print(MSE(y_test,ytilde_test_OLS))
    +print("  ")
    +print("test MSE of Ridge")
    +print(MSE(y_test,ytilde_test_Ridge))
    +
    +plt.scatter(x,y,label='Data')
    +plt.plot(x, X @ beta_OLS,'*', label="OLS_Fit")
    +plt.plot(x, X @ beta_Ridge, label="Ridge_Fit")
    +plt.grid()
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    In this example we do not include the intercept and we scale the data by subtracting the mean values. This follows the discussion in the lecture material. +see also the weekly slides for week 36. +It is recommended whrn we use Ridge and Lasso regression to not include the intercept in the optimization process. +

    + +

    Before we discuss the code, we repeat some of the basic math from the slides of week 36.

    + +

    Let us try to understand what this may imply mathematically when we +subtract the mean values, also known as zero centering or simply centering. For +simplicity, we will focus on ordinary regression, as done in the above example. +

    + +

    The cost/loss function for regression is

    +

     
    +$$ +C(\beta_0, \beta_1, ... , \beta_{p-1}) = \frac{1}{n}\sum_{i=0}^{n} \left(y_i - \beta_0 - \sum_{j=1}^{p-1} X_{ij}\beta_j\right)^2,. +$$ +

     
    + +

    Recall also that we use the squared value. This expression can lead to an +increased penalty for higher differences between predicted and +output/target values. +

    + +

    What we have done is to single out the \( \beta_0 \) term in the +definition of the mean squared error (MSE). The design matrix \( X \) +does in this case not contain any intercept column. When we take the +derivative with respect to \( \beta_0 \), we want the derivative to obey +

    + +

     
    +$$ +\frac{\partial C}{\partial \beta_j} = 0, +$$ +

     
    + +

    for all \( j \). For \( \beta_0 \) we have

    + +

     
    +$$ +\frac{\partial C}{\partial \beta_0} = -\frac{2}{n}\sum_{i=0}^{n-1} \left(y_i - \beta_0 - \sum_{j=1}^{p-1} X_{ij} \beta_j\right). +$$ +

     
    + +

    Multiplying away the constant \( 2/n \), we obtain

    +

     
    +$$ +\sum_{i=0}^{n-1} \beta_0 = \sum_{i=0}^{n-1}y_i - \sum_{i=0}^{n-1} \sum_{j=1}^{p-1} X_{ij} \beta_j. +$$ +

     
    + +

    Let us specialize first to the case where we have only two parameters \( \beta_0 \) and \( \beta_1 \). +Our result for \( \beta_0 \) simplifies then to +

    +

     
    +$$ +n\beta_0 = \sum_{i=0}^{n-1}y_i - \sum_{i=0}^{n-1} X_{i1} \beta_1. +$$ +

     
    + +

    We obtain then

    +

     
    +$$ +\beta_0 = \frac{1}{n}\sum_{i=0}^{n-1}y_i - \beta_1\frac{1}{n}\sum_{i=0}^{n-1} X_{i1}. +$$ +

     
    + +

    If we define

    +

     
    +$$ +\mu_{\boldsymbol{x}_1}=\frac{1}{n}\sum_{i=0}^{n-1} X_{i1}, +$$ +

     
    + +

    and the mean value of the outputs as

    +

     
    +$$ +\mu_y=\frac{1}{n}\sum_{i=0}^{n-1}y_i, +$$ +

     
    + +

    we have

    +

     
    +$$ +\beta_0 = \mu_y - \beta_1\mu_{\boldsymbol{x}_1}. +$$ +

     
    + +

    In the general case with more parameters than \( \beta_0 \) and \( \beta_1 \), we have

    +

     
    +$$ +\beta_0 = \frac{1}{n}\sum_{i=0}^{n-1}y_i - \frac{1}{n}\sum_{i=0}^{n-1}\sum_{j=1}^{p-1} X_{ij}\beta_j. +$$ +

     
    + +

    We can rewrite the latter equation as

    +

     
    +$$ +\beta_0 = \frac{1}{n}\sum_{i=0}^{n-1}y_i - \sum_{j=1}^{p-1} \mu_{\boldsymbol{x}_j}\beta_j, +$$ +

     
    + +

    where we have defined

    +

     
    +$$ +\mu_{\boldsymbol{x}_j}=\frac{1}{n}\sum_{i=0}^{n-1} X_{ij}, +$$ +

     
    + +

    the mean value for all elements of the column vector \( \boldsymbol{x}_j \).

    + +

    Replacing \( y_i \) with \( y_i - y_i - \overline{\boldsymbol{y}} \) and centering also our design matrix results in a cost function (in vector-matrix disguise)

    +

     
    +$$ +C(\boldsymbol{\beta}) = (\boldsymbol{\tilde{y}} - \tilde{X}\boldsymbol{\beta})^T(\boldsymbol{\tilde{y}} - \tilde{X}\boldsymbol{\beta}). +$$ +

     
    + +

    If we minimize with respect to \( \boldsymbol{\beta} \) we have then

    + +

     
    +$$ +\hat{\boldsymbol{\beta}} = (\tilde{X}^T\tilde{X})^{-1}\tilde{X}^T\boldsymbol{\tilde{y}}, +$$ +

     
    + +

    where \( \boldsymbol{\tilde{y}} = \boldsymbol{y} - \overline{\boldsymbol{y}} \) +and \( \tilde{X}_{ij} = X_{ij} - \frac{1}{n}\sum_{k=0}^{n-1}X_{kj} \). +

    + +

    For Ridge regression we need to add \( \lambda \boldsymbol{\beta}^T\boldsymbol{\beta} \) to the cost function and get then

    +

     
    +$$ +\hat{\boldsymbol{\beta}} = (\tilde{X}^T\tilde{X} + \lambda I)^{-1}\tilde{X}^T\boldsymbol{\tilde{y}}. +$$ +

     
    + +

    Now we try to implement this.

    + + + +
    +
    +
    +
    +
    +
    np.random.seed(2018)
    +n = 100
    +# we do not include the intercept
    +d = 2
    +Lambda = 0.01
    +
    +# Make data set.
    +x = np.linspace(-3, 3, n)
    +y = 2.0 + 0.5*x + 5.0*(x**2)+ np.random.randn(n)
    +
    +#Design matrix X does not include the intercept. 
    +X = np.zeros((len(x), d))
    +for p in range(d):     
    +    X[:, p] = x ** (p+1)
    +
    +
    +#Split data in train and test
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +
    +# Scale data by subtracting mean value,own implementation
    +#For our own implementation, we will need to deal with the intercept by centering the design matrix and the target variable
    +X_train_mean = np.mean(X_train,axis=0)
    +#Center by removing mean from each feature
    +X_train_scaled = X_train - X_train_mean
    +X_test_scaled = X_test - X_train_mean
    +#The model intercept (called y_scaler) is given by the mean of the target variable (IF X is centered, note)
    +y_scaler = np.mean(y_train)
    +y_train_scaled = y_train - y_scaler
    +
    +
    +#Calculate beta
    +beta_OLS = OLS_fit_beta(X_train_scaled, y_train_scaled)
    +beta_Ridge = Ridge_fit_beta(X_train_scaled, y_train_scaled,Lambda,d)
    +print(beta_OLS)
    +print(beta_Ridge)
    +# calculate intercepts and print them
    +interceptOLS = y_scaler - X_train_mean @ beta_OLS
    +interceptRidge = y_scaler - X_train_mean @ beta_Ridge
    +print(interceptOLS)
    +print(interceptRidge)
    +
    +#predict value with intercept
    +ytilde_test_OLS = X_test_scaled @ beta_OLS+y_scaler
    +ytilde_test_Ridge = X_test_scaled @ beta_Ridge+y_scaler
    +
    +
    +#Calculate MSE
    +
    +print("  ")
    +print("test MSE of OLS:")
    +print(MSE(y_test,ytilde_test_OLS))
    +print("  ")
    +print("test MSE of Ridge")
    +print(MSE(y_test,ytilde_test_Ridge))
    +
    +plt.scatter(x,y,label='Data')
    +plt.plot(x, X @ beta_OLS+interceptOLS,'*', label="OLS_Fit")
    +plt.plot(x, X @ beta_Ridge+interceptRidge, label="Ridge_Fit")
    +plt.grid()
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    Finally, instead of using our own function we repeat the same example +using the standardscaler functionality of the library +Scikit-Learn. Here we limit ourselves to Ridge regression only. +

    + + + +
    +
    +
    +
    +
    +
    from sklearn import linear_model
    +np.random.seed(2018)
    +n = 10
    +d = 2
    +Lambda = 0.01
    +
    +# Make data set.
    +x = np.linspace(-3, 3, n)
    +y = 2.0 + 0.5*x + 5.0*(x**2)+ np.random.randn(n)
    +
    +# Design matrix X does not include the intercept. 
    +X = np.zeros((n, d))
    +for p in range(d):     
    +    X[:, p] = x ** (p+1)
    +
    +#Split data in train and test
    +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    +# Scale data by subtracting mean value of the input using scikit-learn
    +scaler = StandardScaler(with_std=False)
    +scaler.fit(X_train)
    +X_train_mean = np.mean(X_train,axis=0)
    +X_train_scaled = scaler.transform(X_train)
    +X_test_scaled = scaler.transform(X_test)
    +# We scale also the output, here by our own code
    +y_scaler = np.mean(y_train)
    +y_train_scaled = y_train - y_scaler
    +y_test_scaled = y_test- y_scaler
    +
    +#Calculate beta
    +OLS = LinearRegression()
    +betaOLS=OLS.fit(X_train_scaled,y_train_scaled)
    +ypredictOLS = OLS.predict(X_test_scaled)
    +linear_model.Ridge(Lambda)
    +RegRidge.fit(X_train_scaled,y_train_scaled)
    +ypredictRidge = RegRidge.predict(X_test_scaled)
    +betaOLS = OLS.coef_
    +betaRidge = RegRidge.coef_
    +print(betaOLS)
    +print(betaRidge)
    +interceptOLS = np.mean(y_train) - X_train_mean @ betaOLS
    +interceptRidge = y_scaler - X_train_mean @ betaRidge
    +print(interceptOLS)
    +print(interceptRidge)
    +#predict value 
    +ytilde_test_Ridge = X_test_scaled @ betaRidge+y_scaler
    +ytilde_test_OLS = X_test_scaled @ betaOLS+y_scaler
    +
    +#Calculate MSE
    +print("  ")
    +print("test MSE of OLS")
    +print(MSE(y_test,ytilde_test_OLS))
    +print("  ")
    +print("test MSE of Ridge")
    +print(MSE(y_test,ytilde_test_Ridge))
    +plt.scatter(x,y,label='Data')
    +plt.plot(x, X @ RegRidge.coef_ + RegRidge.intercept_ , label="Ridge_Fit")
    +plt.grid()
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    diff --git a/doc/pub/week37/html/week37-solarized.html b/doc/pub/week37/html/week37-solarized.html index 8b6cc566f..4ee9ecde5 100644 --- a/doc/pub/week37/html/week37-solarized.html +++ b/doc/pub/week37/html/week37-solarized.html @@ -212,7 +212,11 @@ div.toc p,a { ('The same example but now with cross-validation', 2, None, - 'the-same-example-but-now-with-cross-validation')]} + 'the-same-example-but-now-with-cross-validation'), + ('Notes on scaling with examples', + 2, + None, + 'notes-on-scaling-with-examples')]} end of tocinfo --> @@ -266,7 +270,7 @@ MathJax.Hub.Config({
  • Lecture from last week on calculations of expectation values
  • Exercise for week 37
  • Work on project 1
  • -
  • See also additional note on scaling (jupyter-notebook) sent separately. This will be discussed during the first hour of each session.
  • +
  • See also additional note on scaling (jupyter-notebook) sent separately. This will be discussed during the first hour of each session. This note is added at the end of these slides.
  • For more discussions of Ridge regression and calculation of averages, Wessel van Wieringen's article is highly recommended.
  • @@ -275,9 +279,9 @@ MathJax.Hub.Config({ Material for the lecture on Thursday September 7