small update

This commit is contained in:
Morten Hjorth-Jensen
2023-09-03 14:22:23 +02:00
parent 3cc1f701c0
commit 7f3ecb7bb7
103 changed files with 16669 additions and 1168 deletions
+79 -69
View File
@@ -268,6 +268,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek36.html">
Exercises week 36
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Statistical interpretation of Linear Regression and Resampling techniques
</a>
</li>
</ul>
</div>
@@ -669,10 +679,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.264540221699101
4.673457751724773
[[0.83632853 2.54078623]
[2.54078623 8.44021223]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.26662339374864535
4.736115211426478
[[ 1.20561803 3.63264564]
[ 3.63264564 12.10207647]]
</pre></div>
</div>
</div>
@@ -712,10 +722,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.08374032367704139
1.7696835316227453
[[1. 0.66443521]
[0.66443521 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.09318696260700278
1.9096305360355206
[[1. 0.65907898]
[0.65907898 1. ]]
</pre></div>
</div>
</div>
@@ -744,30 +754,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>[[ 1.20708879 4.33201844]
[-0.3838783 -1.24125217]
[ 0.74722409 1.60194224]
[-0.04086326 0.37419664]
[ 0.62422045 2.05587489]
[ 1.75357263 5.63710438]
[-2.53968309 -7.28219089]
[-1.42054337 -4.90629812]
[-0.13019959 -0.83320794]
[ 0.18306165 0.26181254]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 0.32360769 2.53264317]
[ 0.04531375 -0.70569833]
[ 0.17001895 -0.49570819]
[ 1.60938882 4.69896355]
[ 0.14052537 1.37535105]
[-0.12909917 1.25781559]
[-0.03016916 0.01780471]
[-0.38816656 -0.82894017]
[-0.34591885 -3.1893772 ]
[-1.39550083 -4.66285417]]
0 1
0 1.207089 4.332018
1 -0.383878 -1.241252
2 0.747224 1.601942
3 -0.040863 0.374197
4 0.624220 2.055875
5 1.753573 5.637104
6 -2.539683 -7.282191
7 -1.420543 -4.906298
8 -0.130200 -0.833208
9 0.183062 0.261813
0 0.323608 2.532643
1 0.045314 -0.705698
2 0.170019 -0.495708
3 1.609389 4.698964
4 0.140525 1.375351
5 -0.129099 1.257816
6 -0.030169 0.017805
7 -0.388167 -0.828940
8 -0.345919 -3.189377
9 -1.395501 -4.662854
0 1
0 1.000000 0.992504
1 0.992504 1.000000
0 1.000000 0.899734
1 0.899734 1.000000
</pre></div>
</div>
</div>
@@ -824,37 +834,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.092290 0.091376 0.091772 0.091659 0.091579 0.083691 0.083321
2 0.0 0.091376 0.091209 0.090620 0.090923 0.091266 0.082166 0.082105
3 0.0 0.091772 0.090620 0.098069 0.097435 0.096845 0.093556 0.092724
4 0.0 0.091659 0.090923 0.097435 0.097111 0.096833 0.092478 0.091896
5 0.0 0.091579 0.091266 0.096845 0.096833 0.096872 0.091445 0.091113
6 0.0 0.083691 0.082166 0.093556 0.092478 0.091445 0.092007 0.090828
7 0.0 0.083321 0.082105 0.092724 0.091896 0.091113 0.090828 0.089857
8 0.0 0.083051 0.082145 0.091996 0.091418 0.090888 0.089744 0.088982
9 0.0 0.082877 0.082285 0.091369 0.091044 0.090768 0.088754 0.088201
10 0.0 0.075829 0.073985 0.087419 0.086021 0.084663 0.087860 0.086440
11 0.0 0.075277 0.073684 0.086460 0.085272 0.084124 0.086624 0.085384
12 0.0 0.074819 0.073477 0.085603 0.084624 0.083685 0.085484 0.084422
13 0.0 0.074453 0.073363 0.084846 0.084076 0.083348 0.084438 0.083555
14 0.0 0.074180 0.073344 0.084187 0.083627 0.083111 0.083485 0.082779
1 0.0 0.086358 0.084977 0.084028 0.085456 0.086705 0.073624 0.075225
2 0.0 0.084977 0.085778 0.080455 0.082791 0.085242 0.069320 0.071314
3 0.0 0.084028 0.080455 0.086647 0.086999 0.086904 0.078715 0.079856
4 0.0 0.085456 0.082791 0.086999 0.087848 0.088361 0.078426 0.079839
5 0.0 0.086705 0.085242 0.086904 0.088361 0.089641 0.077606 0.079333
6 0.0 0.073624 0.069320 0.078715 0.078426 0.077606 0.073298 0.074046
7 0.0 0.075225 0.071314 0.079856 0.079839 0.079333 0.074046 0.074971
8 0.0 0.076867 0.073465 0.080914 0.081223 0.081100 0.074653 0.075779
9 0.0 0.078521 0.075782 0.081827 0.082527 0.082877 0.075047 0.076403
10 0.0 0.063766 0.059453 0.069855 0.069291 0.068201 0.066209 0.066728
11 0.0 0.065175 0.061037 0.071105 0.070700 0.069782 0.067233 0.067873
12 0.0 0.066656 0.062742 0.072370 0.072150 0.071437 0.068239 0.069013
13 0.0 0.068206 0.064577 0.073634 0.073630 0.073163 0.069203 0.070127
14 0.0 0.069816 0.066556 0.074868 0.075121 0.074951 0.070092 0.071185
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.083051 0.082877 0.075829 0.075277 0.074819 0.074453 0.074180
2 0.082145 0.082285 0.073985 0.073684 0.073477 0.073363 0.073344
3 0.091996 0.091369 0.087419 0.086460 0.085603 0.084846 0.084187
4 0.091418 0.091044 0.086021 0.085272 0.084624 0.084076 0.083627
5 0.090888 0.090768 0.084663 0.084124 0.083685 0.083348 0.083111
6 0.089744 0.088754 0.087860 0.086624 0.085484 0.084438 0.083485
7 0.088982 0.088201 0.086440 0.085384 0.084422 0.083555 0.082779
8 0.088317 0.087746 0.085108 0.084230 0.083446 0.082756 0.082158
9 0.087746 0.087386 0.083859 0.083159 0.082553 0.082040 0.081620
10 0.085108 0.083859 0.085252 0.083832 0.082501 0.081258 0.080098
11 0.084230 0.083159 0.083832 0.082569 0.081395 0.080305 0.079298
12 0.083446 0.082553 0.082501 0.081395 0.080374 0.079437 0.078582
13 0.082756 0.082040 0.081258 0.080305 0.079437 0.078652 0.077949
14 0.082158 0.081620 0.080098 0.079298 0.078582 0.077949 0.077397
1 0.076867 0.078521 0.063766 0.065175 0.066656 0.068206 0.069816
2 0.073465 0.075782 0.059453 0.061037 0.062742 0.064577 0.066556
3 0.080914 0.081827 0.069855 0.071105 0.072370 0.073634 0.074868
4 0.081223 0.082527 0.069291 0.070700 0.072150 0.073630 0.075121
5 0.081100 0.082877 0.068201 0.069782 0.071437 0.073163 0.074951
6 0.074653 0.075047 0.066209 0.067233 0.068239 0.069203 0.070092
7 0.075779 0.076403 0.066728 0.067873 0.069013 0.070127 0.071185
8 0.076819 0.077713 0.067089 0.068365 0.069654 0.070936 0.072186
9 0.077713 0.078926 0.067224 0.068643 0.070096 0.071567 0.073038
10 0.067089 0.067224 0.060603 0.061468 0.062298 0.063070 0.063750
11 0.068365 0.068643 0.061468 0.062424 0.063353 0.064232 0.065030
12 0.069654 0.070096 0.062298 0.063353 0.064390 0.065389 0.066317
13 0.070936 0.071567 0.063070 0.064232 0.065389 0.066519 0.067593
14 0.072186 0.073038 0.063750 0.065030 0.066317 0.067593 0.068832
</pre></div>
</div>
</div>
@@ -1043,10 +1053,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 3.956454 1.972286
1 1.972286 1.977089
[[3.95645365 1.97228638]
[1.97228638 1.97708897]]
0 4.059118 2.009163
1 2.009163 2.004788
[[4.05911793 2.00916336]
[2.00916336 2.00478786]]
</pre></div>
</div>
</div>
@@ -1073,8 +1083,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
[[3.95645365 1.97228638]
[1.97228638 1.97708897]]
[[4.05911793 2.00916336]
[2.00916336 2.00478786]]
</pre></div>
</div>
<img alt="_images/chapter8_65_1.png" src="_images/chapter8_65_1.png" />
@@ -1134,16 +1144,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.173439546289586
0.7601030735620569
5.288455813429108
0.7754499790100834
First eigenvector
[0.85102768 0.52512084]
[0.85299536 0.52191849]
Second eigenvector
[-0.52512084 0.85102768]
[-0.52191849 0.85299536]
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvector of largest eigenvalue
[-0.85102768 -0.52512084]
[0.85299536 0.52191849]
</pre></div>
</div>
</div>