update lecture notes

This commit is contained in:
Morten Hjorth-Jensen
2022-08-24 22:09:34 +02:00
parent ec32146f14
commit 1d1e5a2475
28 changed files with 3589 additions and 6264 deletions
+27 -65
View File
@@ -548,7 +548,8 @@ const thebe_selector_output = ".output, .cell_output"
<div>
<div class="tex2jax_ignore mathjax_ignore section" id="linear-regression">
<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
doconce format html chapter1.do.txt --><div class="tex2jax_ignore mathjax_ignore section" id="linear-regression">
<h1><span class="section-number">3. </span>Linear Regression<a class="headerlink" href="#linear-regression" title="Permalink to this headline"></a></h1>
<div class="section" id="introduction">
<h2><span class="section-number">3.1. </span>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
@@ -805,7 +806,7 @@ Thereafter we wish to apply it to data which were not included in the training.
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/chapter1_3_0.png" src="_images/chapter1_3_0.png" />
<img alt="_images/chapter1_9_0.png" src="_images/chapter1_9_0.png" />
</div>
</div>
<p>This example serves several aims. It allows us to demonstrate several
@@ -890,7 +891,7 @@ to be dominated by outliers.</p>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/chapter1_11_0.png" src="_images/chapter1_11_0.png" />
<img alt="_images/chapter1_17_0.png" src="_images/chapter1_17_0.png" />
</div>
</div>
<p>Depending on the parameter in front of the normal distribution, we may
@@ -937,16 +938,16 @@ example of the functionality of <strong>Scikit-Learn</strong>.</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>The intercept alpha:
[2.09170751]
[1.92272314]
Coefficient beta :
[[4.91479093]]
[[5.13117061]]
Mean squared error: 0.21
Variance score: 0.90
Variance score: 0.92
Mean squared log error: 0.01
Mean absolute error: 0.35
Mean absolute error: 0.36
</pre></div>
</div>
<img alt="_images/chapter1_13_1.png" src="_images/chapter1_13_1.png" />
<img alt="_images/chapter1_19_1.png" src="_images/chapter1_19_1.png" />
</div>
</div>
<p>The function <strong>coef</strong> gives us the parameter <span class="math notranslate nohighlight">\(\beta\)</span> of our fit while <strong>intercept</strong> yields
@@ -1042,8 +1043,8 @@ a linear <span class="math notranslate nohighlight">\(x\)</span>-dependence we s
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/chapter1_27_0.png" src="_images/chapter1_27_0.png" />
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.004999999999999984
<img alt="_images/chapter1_33_0.png" src="_images/chapter1_33_0.png" />
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.004999999999999996
</pre></div>
</div>
</div>
@@ -1128,7 +1129,7 @@ After having downloaded this file to our own computer, we are now ready to read
<span class="c1"># Where to save the figures and data files</span>
<span class="n">PROJECT_ROOT_DIR</span> <span class="o">=</span> <span class="s2">&quot;Results&quot;</span>
<span class="n">FIGURE_ID</span> <span class="o">=</span> <span class="s2">&quot;Results/FigureFiles&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;DataFiles/&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;datafiles/&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">)</span>
@@ -1585,7 +1586,7 @@ our matrix as <span class="math notranslate nohighlight">\(\boldsymbol{X}\in {\m
<span class="c1"># Where to save the figures and data files</span>
<span class="n">PROJECT_ROOT_DIR</span> <span class="o">=</span> <span class="s2">&quot;Results&quot;</span>
<span class="n">FIGURE_ID</span> <span class="o">=</span> <span class="s2">&quot;Results/FigureFiles&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;DataFiles/&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;datafiles/&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">)</span>
@@ -1745,57 +1746,18 @@ allow for the usage of direct linear algebra methods such as <strong>LU</strong>
<p><strong>Small question</strong>: Do you think the example we have at hand here (the nuclear binding energies) can lead to problems in inverting the matrix <span class="math notranslate nohighlight">\(\boldsymbol{X}^T\boldsymbol{X}\)</span>? What kind of problems can we expect?</p>
<p>The following matrix and vector relation will be useful here and for the rest of the course. Vectors are always written as boldfaced lower case letters and
matrices as upper case boldfaced letters.</p>
<p>4
3</p>
<p>&lt;
&lt;
&lt;
!
!
M
A
T
H
_
B
L
O
C
K</p>
<p>4
4</p>
<p>&lt;
&lt;
&lt;
!
!
M
A
T
H
_
B
L
O
C
K</p>
<p>4
5</p>
<p>&lt;
&lt;
&lt;
!
!
M
A
T
H
_
B
L
O
C
K</p>
<div class="math notranslate nohighlight">
\[
\frac{\partial\boldsymbol{b}^T\boldsymbol{a}}{\partial\boldsymbol{a}}=\boldsymbol{b},
\]</div>
<div class="math notranslate nohighlight">
\[
\frac{\partial\boldsymbol{a}^T\boldsymbol{A}\boldsymbol{a}}{\partial\boldsymbol{a}}=(\boldsymbol{A}+\boldsymbol{A}^T)\boldsymbol{a},
\]</div>
<div class="math notranslate nohighlight">
\[
\frac{\partial tr(\boldsymbol{B}\boldsymbol{A})}{\partial\boldsymbol{A}}=\boldsymbol{B}^T,
\]</div>
<div class="math notranslate nohighlight">
\[
\frac{\partial\log{\vert\boldsymbol{A}\vert}}{\partial \boldsymbol{A}}=(\boldsymbol{A}^{-1})^T.
@@ -2061,7 +2023,7 @@ instead of our own matrix inversion implementation.</p>
<span class="c1"># Where to save the figures and data files</span>
<span class="n">PROJECT_ROOT_DIR</span> <span class="o">=</span> <span class="s2">&quot;Results&quot;</span>
<span class="n">FIGURE_ID</span> <span class="o">=</span> <span class="s2">&quot;Results/FigureFiles&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;DataFiles/&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;datafiles/&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">)</span>
@@ -2226,7 +2188,7 @@ but now splitting the data into a training set and a test set.</p>
<span class="c1"># Where to save the figures and data files</span>
<span class="n">PROJECT_ROOT_DIR</span> <span class="o">=</span> <span class="s2">&quot;Results&quot;</span>
<span class="n">FIGURE_ID</span> <span class="o">=</span> <span class="s2">&quot;Results/FigureFiles&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;DataFiles/&quot;</span>
<span class="n">DATA_ID</span> <span class="o">=</span> <span class="s2">&quot;datafiles/&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">PROJECT_ROOT_DIR</span><span class="p">)</span>