This commit is contained in:
Morten Hjorth-Jensen
2024-10-14 09:13:10 +02:00
parent f1f5b33d5e
commit a7012b5326
140 changed files with 3712 additions and 3488 deletions
+72 -60
View File
@@ -323,6 +323,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 41 Neural networks and constructing a neural network code
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek42.html">
Exercises week 42
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week42.html">
Week 42 Constructing a Neural Network code with examples
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1305,10 +1315,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.009134699065945493
4.0244965108017645
[[0.85613835 2.50655379]
[2.50655379 8.3404509 ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.04718566894028431
4.11080997912276
[[ 1.10517643 3.48455788]
[ 3.48455788 12.00216162]]
</pre></div>
</div>
</div>
@@ -1345,10 +1355,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.07971187802560528
1.800782161095708
[[1. 0.59411814]
[0.59411814 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.07836997022107646
1.1378267322316808
[[1. 0.63980097]
[0.63980097 1. ]]
</pre></div>
</div>
</div>
@@ -1378,30 +1388,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.81395716 1.89155934]
[-1.34726166 -4.13453411]
[-0.46229544 -2.34061974]
[ 0.24429334 1.4051634 ]
[ 0.41971814 1.6405671 ]
[ 2.02456235 5.03973227]
[-1.97311824 -4.72521196]
[ 0.10738656 0.24578123]
[-0.52702419 -2.34023682]
[ 0.69978197 3.31779928]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 1.34931214 3.06139439]
[-0.44476964 -2.60794187]
[ 0.02225493 0.16388664]
[-1.91193672 -3.82324216]
[-0.2044881 -1.56027537]
[-1.15572395 -3.25982474]
[ 0.94217756 1.49888671]
[ 0.28472162 2.92474572]
[ 2.38943 7.14118216]
[-1.27097785 -3.5388115 ]]
0 1
0 0.813957 1.891559
1 -1.347262 -4.134534
2 -0.462295 -2.340620
3 0.244293 1.405163
4 0.419718 1.640567
5 2.024562 5.039732
6 -1.973118 -4.725212
7 0.107387 0.245781
8 -0.527024 -2.340237
9 0.699782 3.317799
0 1.349312 3.061394
1 -0.444770 -2.607942
2 0.022255 0.163887
3 -1.911937 -3.823242
4 -0.204488 -1.560275
5 -1.155724 -3.259825
6 0.942178 1.498887
7 0.284722 2.924746
8 2.389430 7.141182
9 -1.270978 -3.538811
0 1
0 1.000000 0.969413
1 0.969413 1.000000
0 1.000000 0.950873
1 0.950873 1.000000
</pre></div>
</div>
</div>
@@ -1458,37 +1468,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.092746 0.090302 0.090561 0.088058 0.085463 0.081530 0.078898
2 0.0 0.090302 0.088694 0.089052 0.086797 0.084423 0.080286 0.077782
3 0.0 0.090561 0.089052 0.095106 0.092533 0.089858 0.089404 0.086489
4 0.0 0.088058 0.086797 0.092533 0.090114 0.087585 0.086913 0.084127
5 0.0 0.085463 0.084423 0.089858 0.087585 0.085197 0.084340 0.081681
6 0.0 0.081530 0.080286 0.089404 0.086913 0.084340 0.086471 0.083596
7 0.0 0.078898 0.077782 0.086489 0.084127 0.081681 0.083596 0.080849
8 0.0 0.076334 0.075334 0.083645 0.081405 0.079080 0.080793 0.078170
9 0.0 0.073841 0.072946 0.080875 0.078753 0.076543 0.078067 0.075562
10 0.0 0.072973 0.071789 0.082361 0.079982 0.077541 0.081296 0.078544
11 0.0 0.070485 0.069391 0.079518 0.077254 0.074928 0.078454 0.075823
12 0.0 0.068088 0.067077 0.076777 0.074622 0.072404 0.075712 0.073198
13 0.0 0.065778 0.064845 0.074134 0.072083 0.069970 0.073071 0.070667
14 0.0 0.063554 0.062693 0.071588 0.069637 0.067623 0.070527 0.068229
1 0.0 0.074334 0.080585 0.077061 0.078751 0.080220 0.070657 0.071406
2 0.0 0.080585 0.088425 0.082009 0.084289 0.086338 0.074009 0.075052
3 0.0 0.077061 0.082009 0.085147 0.086339 0.087297 0.081324 0.081796
4 0.0 0.078751 0.084289 0.086339 0.087789 0.089007 0.081926 0.082537
5 0.0 0.080220 0.086338 0.087297 0.089007 0.090492 0.082307 0.083061
6 0.0 0.070657 0.074009 0.081324 0.081926 0.082307 0.079874 0.080032
7 0.0 0.071406 0.075052 0.081796 0.082537 0.083061 0.080032 0.080271
8 0.0 0.072148 0.076101 0.082240 0.083128 0.083801 0.080150 0.080474
9 0.0 0.072902 0.077180 0.082670 0.083714 0.084548 0.080237 0.080651
10 0.0 0.063646 0.065859 0.075320 0.075498 0.075472 0.075478 0.075409
11 0.0 0.064071 0.066452 0.075576 0.075838 0.075897 0.075542 0.075525
12 0.0 0.064514 0.067074 0.075838 0.076189 0.076340 0.075602 0.075639
13 0.0 0.064980 0.067731 0.076108 0.076555 0.076803 0.075658 0.075753
14 0.0 0.065472 0.068429 0.076389 0.076938 0.077292 0.075711 0.075868
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.076334 0.073841 0.072973 0.070485 0.068088 0.065778 0.063554
2 0.075334 0.072946 0.071789 0.069391 0.067077 0.064845 0.062693
3 0.083645 0.080875 0.082361 0.079518 0.076777 0.074134 0.071588
4 0.081405 0.078753 0.079982 0.077254 0.074622 0.072083 0.069637
5 0.079080 0.076543 0.077541 0.074928 0.072404 0.069970 0.067623
6 0.080793 0.078067 0.081296 0.078454 0.075712 0.073071 0.070527
7 0.078170 0.075562 0.078544 0.075823 0.073198 0.070667 0.068229
8 0.075609 0.073115 0.075864 0.073260 0.070747 0.068324 0.065989
9 0.073115 0.070730 0.073260 0.070769 0.068364 0.066044 0.063809
10 0.075864 0.073260 0.077608 0.074866 0.072223 0.069676 0.067224
11 0.073260 0.070769 0.074866 0.072241 0.069711 0.067273 0.064924
12 0.070747 0.068364 0.072223 0.069711 0.067288 0.064954 0.062705
13 0.068324 0.066044 0.069676 0.067273 0.064954 0.062719 0.060565
14 0.065989 0.063809 0.067224 0.064924 0.062705 0.060565 0.058503
1 0.072148 0.072902 0.063646 0.064071 0.064514 0.064980 0.065472
2 0.076101 0.077180 0.065859 0.066452 0.067074 0.067731 0.068429
3 0.082240 0.082670 0.075320 0.075576 0.075838 0.076108 0.076389
4 0.083128 0.083714 0.075498 0.075838 0.076189 0.076555 0.076938
5 0.083801 0.084548 0.075472 0.075897 0.076340 0.076803 0.077292
6 0.080150 0.080237 0.075478 0.075542 0.075602 0.075658 0.075711
7 0.080474 0.080651 0.075409 0.075525 0.075639 0.075753 0.075868
8 0.080766 0.081038 0.075293 0.075463 0.075634 0.075809 0.075988
9 0.081038 0.081411 0.075136 0.075363 0.075595 0.075834 0.076082
10 0.075293 0.075136 0.072406 0.072329 0.072240 0.072140 0.072028
11 0.075463 0.075363 0.072329 0.072286 0.072234 0.072173 0.072101
12 0.075634 0.075595 0.072240 0.072234 0.072220 0.072199 0.072171
13 0.075809 0.075834 0.072140 0.072173 0.072199 0.072221 0.072238
14 0.075988 0.076082 0.072028 0.072101 0.072171 0.072238 0.072303
</pre></div>
</div>
</div>
@@ -1969,11 +1979,13 @@ We select values of the hyperparameter <span class="math notranslate nohighlight
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[2. 2.]
Training MSE for OLS
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Training MSE for OLS
3.0
</pre></div>
</div>
<img alt="_images/chapter2_252_1.png" src="_images/chapter2_252_1.png" />
<img alt="_images/chapter2_252_2.png" src="_images/chapter2_252_2.png" />
</div>
</div>
<p>We see here that we reach a plateau for the Ridge results. Writing out the coefficients <span class="math notranslate nohighlight">\(\boldsymbol{\beta}\)</span>, we observe that they are getting smaller and smaller and our error stabilizes since the predicted values of <span class="math notranslate nohighlight">\(\tilde{\boldsymbol{y}}\)</span> approach zero.</p>