This commit is contained in:
Morten Hjorth-Jensen
2024-09-10 12:06:15 +02:00
parent 4a3985783f
commit 4e5c11dfa3
143 changed files with 2073 additions and 6207 deletions
+99 -74
View File
@@ -275,7 +275,34 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -679,10 +706,10 @@ covariance matrix through the <strong>np.linalg.eig()</strong> function.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.046842629321028326
3.909446359461397
[[0.76681867 2.32238906]
[2.32238906 8.10983159]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.1477190177681485
3.5426270409877345
[[1.01393496 3.02432309]
[3.02432309 9.86643649]]
</pre></div>
</div>
</div>
@@ -722,10 +749,10 @@ a more brute force way. Here we scale the mean values for each column of the des
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.0798590438380667
1.270350130579073
[[1. 0.58734026]
[0.58734026 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.08793554992813543
1.9271707090281667
[[1. 0.6690108]
[0.6690108 1. ]]
</pre></div>
</div>
</div>
@@ -754,30 +781,30 @@ this matrix we easily see that it is a positive definite matrix.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[-0.34565973 -1.4704785 ]
[-0.29669702 -0.75437273]
[ 1.05100602 2.13022421]
[ 0.40103689 3.11022072]
[ 0.01591047 -0.05087888]
[-0.89261577 -1.74947597]
[-0.21796226 -0.62901905]
[-0.5961905 -2.9242511 ]
[ 0.39428522 1.65208925]
[ 0.48688666 0.68594205]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[-0.95395895 -3.11535632]
[ 1.05641352 3.6533977 ]
[ 0.801356 4.56475921]
[-0.69136414 -1.7642448 ]
[ 0.68822559 0.63896182]
[ 0.30916988 1.25233253]
[ 0.10008326 0.10539984]
[-0.52155823 -1.85777073]
[ 0.24377554 0.94616709]
[-1.03214247 -4.42364634]]
0 1
0 -0.345660 -1.470478
1 -0.296697 -0.754373
2 1.051006 2.130224
3 0.401037 3.110221
4 0.015910 -0.050879
5 -0.892616 -1.749476
6 -0.217962 -0.629019
7 -0.596190 -2.924251
8 0.394285 1.652089
9 0.486887 0.685942
0 1
0 1.00000 0.87078
1 0.87078 1.00000
0 -0.953959 -3.115356
1 1.056414 3.653398
2 0.801356 4.564759
3 -0.691364 -1.764245
4 0.688226 0.638962
5 0.309170 1.252333
6 0.100083 0.105400
7 -0.521558 -1.857771
8 0.243776 0.946167
9 -1.032142 -4.423646
0 1
0 1.000000 0.947607
1 0.947607 1.000000
</pre></div>
</div>
</div>
@@ -834,37 +861,37 @@ this matrix we easily see that it is a positive definite matrix.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1 2 3 4 5 6 7 \
0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.0 0.078785 0.081798 0.081422 0.083540 0.085693 0.075398 0.077082
2 0.0 0.081798 0.085346 0.084157 0.086550 0.088986 0.077522 0.079381
3 0.0 0.081422 0.084157 0.090290 0.092347 0.094426 0.087176 0.088908
4 0.0 0.083540 0.086550 0.092347 0.094577 0.096837 0.088893 0.090751
5 0.0 0.085693 0.088986 0.094426 0.096837 0.099287 0.090623 0.092613
6 0.0 0.075398 0.077522 0.087176 0.088893 0.090623 0.086538 0.088061
7 0.0 0.077082 0.079381 0.088908 0.090751 0.092613 0.088061 0.089682
8 0.0 0.078824 0.081308 0.090696 0.092672 0.094671 0.089629 0.091353
9 0.0 0.080630 0.083309 0.092544 0.094659 0.096803 0.091246 0.093078
10 0.0 0.068605 0.070202 0.081597 0.082978 0.084362 0.082661 0.083943
11 0.0 0.070006 0.071729 0.083096 0.084574 0.086059 0.084022 0.085383
12 0.0 0.071462 0.073318 0.084650 0.086230 0.087822 0.085431 0.086875
13 0.0 0.072976 0.074973 0.086263 0.087951 0.089654 0.086890 0.088422
14 0.0 0.074552 0.076697 0.087938 0.089739 0.091561 0.088402 0.090025
1 0.0 0.079977 0.079947 0.079510 0.081431 0.083259 0.070891 0.072689
2 0.0 0.079947 0.081195 0.081235 0.083734 0.086125 0.073415 0.075557
3 0.0 0.079510 0.081235 0.084255 0.086970 0.089578 0.078324 0.080630
4 0.0 0.081431 0.083734 0.086970 0.090033 0.092982 0.081221 0.083765
5 0.0 0.083259 0.086125 0.089578 0.092982 0.096270 0.084018 0.086799
6 0.0 0.070891 0.073415 0.078324 0.081221 0.084018 0.074971 0.077341
7 0.0 0.072689 0.075557 0.080630 0.083765 0.086799 0.077341 0.079887
8 0.0 0.074531 0.077736 0.082971 0.086346 0.089619 0.079739 0.082464
9 0.0 0.076418 0.079959 0.085353 0.088970 0.092486 0.082173 0.085079
10 0.0 0.062300 0.065028 0.070886 0.073685 0.076396 0.069322 0.071578
11 0.0 0.063862 0.066824 0.072817 0.075794 0.078684 0.071279 0.073672
12 0.0 0.065482 0.068680 0.074807 0.077965 0.081038 0.073288 0.075822
13 0.0 0.067164 0.070600 0.076859 0.080205 0.083465 0.075356 0.078035
14 0.0 0.068912 0.072590 0.078981 0.082519 0.085973 0.077486 0.080316
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.078824 0.080630 0.068605 0.070006 0.071462 0.072976 0.074552
2 0.081308 0.083309 0.070202 0.071729 0.073318 0.074973 0.076697
3 0.090696 0.092544 0.081597 0.083096 0.084650 0.086263 0.087938
4 0.092672 0.094659 0.082978 0.084574 0.086230 0.087951 0.089739
5 0.094671 0.096803 0.084362 0.086059 0.087822 0.089654 0.091561
6 0.089629 0.091246 0.082661 0.084022 0.085431 0.086890 0.088402
7 0.091353 0.093078 0.083943 0.085383 0.086875 0.088422 0.090025
8 0.093132 0.094970 0.085259 0.086782 0.088361 0.090000 0.091700
9 0.094970 0.096928 0.086611 0.088222 0.089892 0.091627 0.093429
10 0.085259 0.086611 0.080195 0.081374 0.082592 0.083851 0.085152
11 0.086782 0.088222 0.081374 0.082619 0.083906 0.085237 0.086615
12 0.088361 0.089892 0.082592 0.083906 0.085265 0.086673 0.088130
13 0.090000 0.091627 0.083851 0.085237 0.086673 0.088160 0.089702
14 0.091700 0.093429 0.085152 0.086615 0.088130 0.089702 0.091331
1 0.074531 0.076418 0.062300 0.063862 0.065482 0.067164 0.068912
2 0.077736 0.079959 0.065028 0.066824 0.068680 0.070600 0.072590
3 0.082971 0.085353 0.070886 0.072817 0.074807 0.076859 0.078981
4 0.086346 0.088970 0.073685 0.075794 0.077965 0.080205 0.082519
5 0.089619 0.092486 0.076396 0.078684 0.081038 0.083465 0.085973
6 0.079739 0.082173 0.069322 0.071279 0.073288 0.075356 0.077486
7 0.082464 0.085079 0.071578 0.073672 0.075822 0.078035 0.080316
8 0.085222 0.088023 0.073858 0.076091 0.078386 0.080747 0.083182
9 0.088023 0.091015 0.076167 0.078544 0.080987 0.083501 0.086095
10 0.073858 0.076167 0.065149 0.067003 0.068903 0.070855 0.072863
11 0.076091 0.078544 0.067003 0.068967 0.070980 0.073048 0.075177
12 0.078386 0.080987 0.068903 0.070980 0.073109 0.075298 0.077553
13 0.080747 0.083501 0.070855 0.073048 0.075298 0.077613 0.079998
14 0.083182 0.086095 0.072863 0.075177 0.077553 0.079998 0.082518
</pre></div>
</div>
</div>
@@ -1053,10 +1080,10 @@ We can write our own code or simply use either the functionaly of <strong>numpy<
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1
0 4.034057 2.045548
1 2.045548 2.024217
[[4.03405654 2.04554803]
[2.04554803 2.02421742]]
0 3.970827 1.972533
1 1.972533 1.968650
[[3.97082748 1.97253307]
[1.97253307 1.96865004]]
</pre></div>
</div>
</div>
@@ -1083,8 +1110,8 @@ Our own code here is not very elegant and asks for obvious improvements. It is t
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Centered covariance using own code
[[4.03405654 2.04554803]
[2.04554803 2.02421742]]
[[3.97082748 1.97253307]
[1.97253307 1.96865004]]
</pre></div>
</div>
<img alt="_images/chapter8_65_1.png" src="_images/chapter8_65_1.png" />
@@ -1144,16 +1171,16 @@ questions.</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvalues of Covariance matrix
5.30820040103372
0.7500735612987705
5.181766185664273
0.7577113351177733
First eigenvector
[0.84880366 0.52870818]
[0.85222243 0.52317963]
Second eigenvector
[-0.52870818 0.84880366]
[-0.52317963 0.85222243]
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvector of largest eigenvalue
[-0.84880366 -0.52870818]
[0.85222243 0.52317963]
</pre></div>
</div>
</div>
@@ -1494,9 +1521,7 @@ Here we compute performance scores on the training data using logistic regressio
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Train set accuracy from Logistic Regression: 0.95
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Train set accuracy scaled data: 0.99
Train set accuracy scaled data: 0.99
Train set accuracy scaled and PCA data: 0.96
</pre></div>
</div>