This commit is contained in:
Morten Hjorth-Jensen
2024-09-22 21:21:59 +02:00
parent 0a6ba7c08d
commit 80f0f2ffab
102 changed files with 18315 additions and 2027 deletions
+8 -8
View File
@@ -10,13 +10,13 @@ edge [fontname="helvetica"] ;
2 -> 3 ;
4 [label="gini = 0.0\nsamples = 239\nvalue = [[239, 0]\n[0, 239]]", fillcolor="#e58139"] ;
3 -> 4 ;
5 [label="area error <= 51.38\ngini = 0.444\nsamples = 3\nvalue = [[2, 1]\n[1, 2]]", fillcolor="#fdf6f0"] ;
5 [label="mean perimeter <= 78.51\ngini = 0.444\nsamples = 3\nvalue = [[2, 1]\n[1, 2]]", fillcolor="#fdf6f0"] ;
3 -> 5 ;
6 [label="gini = 0.0\nsamples = 1\nvalue = [[0, 1]\n[1, 0]]", fillcolor="#e58139"] ;
5 -> 6 ;
7 [label="gini = 0.0\nsamples = 2\nvalue = [[2, 0]\n[0, 2]]", fillcolor="#e58139"] ;
5 -> 7 ;
8 [label="worst texture <= 29.455\ngini = 0.397\nsamples = 11\nvalue = [[8, 3]\n[3, 8]]", fillcolor="#fae9dd"] ;
8 [label="mean texture <= 20.84\ngini = 0.397\nsamples = 11\nvalue = [[8, 3]\n[3, 8]]", fillcolor="#fae9dd"] ;
2 -> 8 ;
9 [label="gini = 0.0\nsamples = 8\nvalue = [[8, 0]\n[0, 8]]", fillcolor="#e58139"] ;
8 -> 9 ;
@@ -30,11 +30,11 @@ edge [fontname="helvetica"] ;
11 -> 13 ;
14 [label="worst texture <= 20.645\ngini = 0.202\nsamples = 167\nvalue = [[19, 148]\n[148, 19]]", fillcolor="#f0b68c"] ;
0 -> 14 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
15 [label="worst area <= 964.4\ngini = 0.375\nsamples = 16\nvalue = [[12, 4]\n[4, 12]]", fillcolor="#f9e3d4"] ;
15 [label="worst radius <= 17.74\ngini = 0.375\nsamples = 16\nvalue = [[12, 4]\n[4, 12]]", fillcolor="#f9e3d4"] ;
14 -> 15 ;
16 [label="gini = 0.0\nsamples = 11\nvalue = [[11, 0]\n[0, 11]]", fillcolor="#e58139"] ;
15 -> 16 ;
17 [label="symmetry error <= 0.014\ngini = 0.32\nsamples = 5\nvalue = [[1, 4]\n[4, 1]]", fillcolor="#f6d5bd"] ;
17 [label="worst concavity <= 0.212\ngini = 0.32\nsamples = 5\nvalue = [[1, 4]\n[4, 1]]", fillcolor="#f6d5bd"] ;
15 -> 17 ;
18 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139"] ;
17 -> 18 ;
@@ -42,16 +42,16 @@ edge [fontname="helvetica"] ;
17 -> 19 ;
20 [label="mean concave points <= 0.049\ngini = 0.088\nsamples = 151\nvalue = [[7, 144]\n[144, 7]]", fillcolor="#ea985d"] ;
14 -> 20 ;
21 [label="compactness error <= 0.016\ngini = 0.48\nsamples = 15\nvalue = [[6, 9]\n[9, 6]]", fillcolor="#ffffff"] ;
21 [label="concave points error <= 0.01\ngini = 0.48\nsamples = 15\nvalue = [[6, 9]\n[9, 6]]", fillcolor="#ffffff"] ;
20 -> 21 ;
22 [label="gini = 0.0\nsamples = 9\nvalue = [[0, 9]\n[9, 0]]", fillcolor="#e58139"] ;
21 -> 22 ;
23 [label="gini = 0.0\nsamples = 6\nvalue = [[6, 0]\n[0, 6]]", fillcolor="#e58139"] ;
21 -> 23 ;
24 [label="fractal dimension error <= 0.013\ngini = 0.015\nsamples = 136\nvalue = [[1, 135]\n[135, 1]]", fillcolor="#e6853f"] ;
24 [label="mean smoothness <= 0.079\ngini = 0.015\nsamples = 136\nvalue = [[1, 135]\n[135, 1]]", fillcolor="#e6853f"] ;
20 -> 24 ;
25 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139"] ;
25 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139"] ;
24 -> 25 ;
26 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139"] ;
26 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139"] ;
24 -> 26 ;
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 KiB

After

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "12bcd5bb",
"metadata": {
"editable": true
},
"source": [
"<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)\n",
"doconce format html exercisesweek39.do.txt -->\n",
"<!-- dom:TITLE: Exercises week 39 -->"
]
},
{
"cell_type": "markdown",
"id": "cd59f741",
"metadata": {
"editable": true
},
"source": [
"# Exercises week 39\n",
"**September 23-27, 2024**\n",
"\n",
"Date: **Deadline is Friday September 27 at midnight**"
]
},
{
"cell_type": "markdown",
"id": "bdf13ce1",
"metadata": {
"editable": true
},
"source": [
"## Overarching aims of the exercises this week\n",
"\n",
"The aim of the exercises this week is to aid you in getting started\n",
"with writing the report. This will be discussed during the lab\n",
"sessions as well. \n",
"\n",
"A general guideline can be found at <https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/EvaluationGrading/EvaluationForm.md>.\n",
"\n",
"Similarly, an example of an earlier project can be found at <https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/ReportExample/ReportSample.pdf>\n",
"\n",
"Your task this week is to\n",
"1. Write an abstract for your project\n",
"\n",
"2. Write an introduction\n",
"\n",
"3. Include references\n",
"\n",
"A short feedback to the this exercise will be available before the project deadline. And you can reuse these elements in your final report."
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
File diff suppressed because it is too large Load Diff
+15 -5
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1026,13 +1036,13 @@ 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:
[1.95647867]
[1.92622842]
Coefficient beta :
[[5.05401912]]
Mean squared error: 0.25
[[5.21332621]]
Mean squared error: 0.22
Variance score: 0.90
Mean squared log error: 0.01
Mean absolute error: 0.43
Mean absolute error: 0.38
</pre></div>
</div>
<img alt="_images/chapter1_19_1.png" src="_images/chapter1_19_1.png" />
@@ -1132,7 +1142,7 @@ a linear <span class="math notranslate nohighlight">\(x\)</span>-dependence we s
</div>
<div class="cell_output docutils container">
<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.004999999999999991
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.005
</pre></div>
</div>
</div>
+66 -449
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1343,7 +1353,7 @@ the <em>Hadamard product</em>, meaning element-wise multiplication.</p>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Old accuracy on training data: 0.1440501043841336
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1677,7 +1687,7 @@ Lambda = 10.0
Accuracy score on test set: 0.19166666666666668
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1686,7 +1696,7 @@ Lambda = 1e-05
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1695,7 +1705,7 @@ Lambda = 0.0001
Accuracy score on test set: 0.08611111111111111
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1704,7 +1714,7 @@ Lambda = 0.001
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1713,7 +1723,7 @@ Lambda = 0.01
Accuracy score on test set: 0.08888888888888889
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1722,7 +1732,7 @@ Lambda = 0.1
Accuracy score on test set: 0.08611111111111111
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1731,7 +1741,7 @@ Lambda = 1.0
Accuracy score on test set: 0.08888888888888889
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1740,11 +1750,11 @@ Lambda = 10.0
Accuracy score on test set: 0.09166666666666666
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1753,11 +1763,11 @@ Lambda = 1e-05
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1766,11 +1776,11 @@ Lambda = 0.0001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1779,11 +1789,11 @@ Lambda = 0.001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1792,11 +1802,11 @@ Lambda = 0.01
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1805,7 +1815,7 @@ Lambda = 0.1
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
@@ -1814,11 +1824,11 @@ Lambda = 1.0
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1827,11 +1837,11 @@ Lambda = 10.0
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
@@ -1840,82 +1850,37 @@ Lambda = 1e-05
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95354/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.0001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.001
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.01
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.1
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 1.0
Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:43: RuntimeWarning: overflow encountered in exp
exp_term = np.exp(self.z_o)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 10.0
Accuracy score on test set: 0.07777777777777778
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
<span class="ne">KeyboardInterrupt</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
<span class="n">Cell</span> <span class="n">In</span><span class="p">[</span><span class="mi">8</span><span class="p">],</span> <span class="n">line</span> <span class="mi">11</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">for</span> <span class="n">j</span><span class="p">,</span> <span class="n">lmbd</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">lmbd_vals</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">dnn</span> <span class="o">=</span> <span class="n">NeuralNetwork</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">Y_train_onehot</span><span class="p">,</span> <span class="n">eta</span><span class="o">=</span><span class="n">eta</span><span class="p">,</span> <span class="n">lmbd</span><span class="o">=</span><span class="n">lmbd</span><span class="p">,</span> <span class="n">epochs</span><span class="o">=</span><span class="n">epochs</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span>
<span class="g g-Whitespace"> </span><span class="mi">10</span> <span class="n">n_hidden_neurons</span><span class="o">=</span><span class="n">n_hidden_neurons</span><span class="p">,</span> <span class="n">n_categories</span><span class="o">=</span><span class="n">n_categories</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">11</span> <span class="n">dnn</span><span class="o">.</span><span class="n">train</span><span class="p">()</span>
<span class="g g-Whitespace"> </span><span class="mi">13</span> <span class="n">DNN_numpy</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">dnn</span>
<span class="g g-Whitespace"> </span><span class="mi">15</span> <span class="n">test_predict</span> <span class="o">=</span> <span class="n">dnn</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X_test</span><span class="p">)</span>
<span class="nn">Cell In[6], line 99,</span> in <span class="ni">NeuralNetwork.train</span><span class="nt">(self)</span>
<span class="g g-Whitespace"> </span><span class="mi">96</span> <span class="bp">self</span><span class="o">.</span><span class="n">Y_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Y_data_full</span><span class="p">[</span><span class="n">chosen_datapoints</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">98</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed_forward</span><span class="p">()</span>
<span class="ne">---&gt; </span><span class="mi">99</span> <span class="bp">self</span><span class="o">.</span><span class="n">backpropagation</span><span class="p">()</span>
<span class="nn">Cell In[6], line 64,</span> in <span class="ni">NeuralNetwork.backpropagation</span><span class="nt">(self)</span>
<span class="g g-Whitespace"> </span><span class="mi">61</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_weights_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">a_h</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">error_output</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">62</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_bias_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">error_output</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">64</span> <span class="bp">self</span><span class="o">.</span><span class="n">hidden_weights_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">X_data</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">error_hidden</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">65</span> <span class="bp">self</span><span class="o">.</span><span class="n">hidden_bias_gradient</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">error_hidden</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">67</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">lmbd</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
<span class="ne">KeyboardInterrupt</span>:
</pre></div>
</div>
</div>
@@ -1961,22 +1926,6 @@ Accuracy score on test set: 0.07777777777777778
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58656/953065564.py:4: RuntimeWarning: overflow encountered in exp
return 1/(1 + np.exp(-x))
</pre></div>
</div>
<img alt="_images/chapter10_59_1.png" src="_images/chapter10_59_1.png" />
<img alt="_images/chapter10_59_2.png" src="_images/chapter10_59_2.png" />
</div>
</div>
</div>
<div class="section" id="scikit-learn-implementation">
@@ -2012,326 +1961,6 @@ performance overall.</p>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 1e-05
Accuracy score on test set: 0.18333333333333332
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.0001
Accuracy score on test set: 0.18611111111111112
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.001
Accuracy score on test set: 0.13055555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.01
Accuracy score on test set: 0.24444444444444444
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 0.1
Accuracy score on test set: 0.23333333333333334
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 1.0
Accuracy score on test set: 0.12777777777777777
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1e-05
Lambda = 10.0
Accuracy score on test set: 0.1527777777777778
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 1e-05
Accuracy score on test set: 0.9111111111111111
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.0001
Accuracy score on test set: 0.8888888888888888
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.001
Accuracy score on test set: 0.8722222222222222
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.01
Accuracy score on test set: 0.8305555555555556
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 0.1
Accuracy score on test set: 0.8888888888888888
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 1.0
Accuracy score on test set: 0.8805555555555555
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.0001
Lambda = 10.0
Accuracy score on test set: 0.8944444444444445
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 1e-05
Accuracy score on test set: 0.975
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.0001
Accuracy score on test set: 0.9777777777777777
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.001
Accuracy score on test set: 0.9805555555555555
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.01
Accuracy score on test set: 0.9861111111111112
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 0.1
Accuracy score on test set: 0.9805555555555555
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 1.0
Accuracy score on test set: 0.9777777777777777
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.001
Lambda = 10.0
Accuracy score on test set: 0.9444444444444444
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (100) reached and the optimization hasn&#39;t converged yet.
warnings.warn(
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 1e-05
Accuracy score on test set: 0.9861111111111112
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.0001
Accuracy score on test set: 0.9888888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.001
Accuracy score on test set: 0.9888888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.01
Accuracy score on test set: 0.9861111111111112
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 0.1
Accuracy score on test set: 0.9888888888888889
Learning rate = 0.01
Lambda = 1.0
Accuracy score on test set: 0.9722222222222222
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.01
Lambda = 10.0
Accuracy score on test set: 0.9527777777777777
Learning rate = 0.1
Lambda = 1e-05
Accuracy score on test set: 0.9027777777777778
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 0.0001
Accuracy score on test set: 0.8583333333333333
Learning rate = 0.1
Lambda = 0.001
Accuracy score on test set: 0.8722222222222222
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 0.01
Accuracy score on test set: 0.9055555555555556
Learning rate = 0.1
Lambda = 0.1
Accuracy score on test set: 0.8805555555555555
Learning rate = 0.1
Lambda = 1.0
Accuracy score on test set: 0.8722222222222222
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 10.0
Accuracy score on test set: 0.8666666666666667
Learning rate = 1.0
Lambda = 1e-05
Accuracy score on test set: 0.08611111111111111
Learning rate = 1.0
Lambda = 0.0001
Accuracy score on test set: 0.10555555555555556
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 0.001
Accuracy score on test set: 0.10555555555555556
Learning rate = 1.0
Lambda = 0.01
Accuracy score on test set: 0.17777777777777778
Learning rate = 1.0
Lambda = 0.1
Accuracy score on test set: 0.08333333333333333
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 1.0
Accuracy score on test set: 0.08888888888888889
Learning rate = 1.0
Lambda = 10.0
Accuracy score on test set: 0.09444444444444444
Learning rate = 10.0
Lambda = 1e-05
Accuracy score on test set: 0.17222222222222222
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.0001
Accuracy score on test set: 0.11666666666666667
Learning rate = 10.0
Lambda = 0.001
Accuracy score on test set: 0.10555555555555556
Learning rate = 10.0
Lambda = 0.01
Accuracy score on test set: 0.1388888888888889
Learning rate = 10.0
Lambda = 0.1
Accuracy score on test set: 0.11388888888888889
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 1.0
Accuracy score on test set: 0.10555555555555556
Learning rate = 10.0
Lambda = 10.0
Accuracy score on test set: 0.09444444444444444
</pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="id1">
@@ -2375,10 +2004,6 @@ Accuracy score on test set: 0.09444444444444444
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<img alt="_images/chapter10_63_0.png" src="_images/chapter10_63_0.png" />
<img alt="_images/chapter10_63_1.png" src="_images/chapter10_63_1.png" />
</div>
</div>
</div>
<div class="section" id="building-neural-networks-in-tensorflow-and-keras">
@@ -2417,14 +2042,6 @@ and/or if you use <strong>anaconda</strong>, just write (or install from the gra
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span> <span class="n">Cell</span> <span class="n">In</span><span class="p">[</span><span class="mi">12</span><span class="p">],</span> <span class="n">line</span> <span class="mi">1</span>
<span class="n">conda</span> <span class="n">create</span> <span class="o">-</span><span class="n">n</span> <span class="n">tf</span> <span class="n">tensorflow</span>
<span class="o">^</span>
<span class="ne">SyntaxError</span>: invalid syntax
</pre></div>
</div>
</div>
</div>
<p>To install the current release of GPU TensorFlow</p>
<div class="cell docutils container">
+38 -82
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -2577,83 +2587,11 @@ Using TensorFlow results in a much better execution time. Try it!</p>
<span class="g g-Whitespace"> </span><span class="mi">19</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">argnum</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">20</span> <span class="k">return</span> <span class="n">unary_operator</span><span class="p">(</span><span class="n">unary_f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="o">*</span><span class="n">nary_op_args</span><span class="p">,</span> <span class="o">**</span><span class="n">nary_op_kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:28,</span> in <span class="ni">grad</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">21</span> <span class="nd">@unary_to_nary</span>
<span class="g g-Whitespace"> </span><span class="mi">22</span> <span class="k">def</span> <span class="nf">grad</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">23</span><span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="g g-Whitespace"> </span><span class="mi">24</span><span class="sd"> Returns a function which computes the gradient of `fun` with respect to</span>
<span class="g g-Whitespace"> </span><span class="mi">25</span><span class="sd"> positional argument number `argnum`. The returned function takes the same</span>
<span class="g g-Whitespace"> </span><span class="mi">26</span><span class="sd"> arguments as `fun`, but returns the gradient instead. The function `fun`</span>
<span class="g g-Whitespace"> </span><span class="mi">27</span><span class="sd"> should be scalar-valued. The gradient has the same type as the argument.&quot;&quot;&quot;</span>
<span class="ne">---&gt; </span><span class="mi">28</span> <span class="n">vjp</span><span class="p">,</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">_make_vjp</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">29</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">vspace</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span><span class="o">.</span><span class="n">size</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">30</span> <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Grad only applies to real scalar-output functions. &quot;</span>
<span class="g g-Whitespace"> </span><span class="mi">31</span> <span class="s2">&quot;Try jacobian, elementwise_grad or holomorphic_grad.&quot;</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:10,</span> in <span class="ni">make_vjp</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">def</span> <span class="nf">make_vjp</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">start_node</span> <span class="o">=</span> <span class="n">VJPNode</span><span class="o">.</span><span class="n">new_root</span><span class="p">()</span>
<span class="ne">---&gt; </span><span class="mi">10</span> <span class="n">end_value</span><span class="p">,</span> <span class="n">end_node</span> <span class="o">=</span> <span class="n">trace</span><span class="p">(</span><span class="n">start_node</span><span class="p">,</span> <span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">11</span> <span class="k">if</span> <span class="n">end_node</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">12</span> <span class="k">def</span> <span class="nf">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">):</span> <span class="k">return</span> <span class="n">vspace</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">zeros</span><span class="p">()</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py:10,</span> in <span class="ni">trace</span><span class="nt">(start_node, fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="k">with</span> <span class="n">trace_stack</span><span class="o">.</span><span class="n">new_trace</span><span class="p">()</span> <span class="k">as</span> <span class="n">t</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">9</span> <span class="n">start_box</span> <span class="o">=</span> <span class="n">new_box</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">start_node</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">10</span> <span class="n">end_box</span> <span class="o">=</span> <span class="n">fun</span><span class="p">(</span><span class="n">start_box</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">11</span> <span class="k">if</span> <span class="n">isbox</span><span class="p">(</span><span class="n">end_box</span><span class="p">)</span> <span class="ow">and</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_trace</span> <span class="o">==</span> <span class="n">start_box</span><span class="o">.</span><span class="n">_trace</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">12</span> <span class="k">return</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_value</span><span class="p">,</span> <span class="n">end_box</span><span class="o">.</span><span class="n">_node</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:15,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f.&lt;locals&gt;.unary_f</span><span class="nt">(x)</span>
<span class="g g-Whitespace"> </span><span class="mi">13</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">14</span> <span class="n">subargs</span> <span class="o">=</span> <span class="n">subvals</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="nb">zip</span><span class="p">(</span><span class="n">argnum</span><span class="p">,</span> <span class="n">x</span><span class="p">))</span>
<span class="ne">---&gt; </span><span class="mi">15</span> <span class="k">return</span> <span class="n">fun</span><span class="p">(</span><span class="o">*</span><span class="n">subargs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="nn">Cell In[9], line 80,</span> in <span class="ni">cost_function</span><span class="nt">(P, x, t)</span>
<span class="g g-Whitespace"> </span><span class="mi">78</span> <span class="n">g_t</span> <span class="o">=</span> <span class="n">g_trial</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">79</span> <span class="n">g_t_jacobian</span> <span class="o">=</span> <span class="n">g_t_jacobian_func</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">80</span> <span class="n">g_t_hessian</span> <span class="o">=</span> <span class="n">g_t_hessian_func</span><span class="p">(</span><span class="n">point</span><span class="p">,</span><span class="n">P</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">82</span> <span class="n">g_t_dt</span> <span class="o">=</span> <span class="n">g_t_jacobian</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">83</span> <span class="n">g_t_d2x</span> <span class="o">=</span> <span class="n">g_t_hessian</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f</span><span class="nt">(*args, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">18</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">19</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">argnum</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">20</span> <span class="k">return</span> <span class="n">unary_operator</span><span class="p">(</span><span class="n">unary_f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="o">*</span><span class="n">nary_op_args</span><span class="p">,</span> <span class="o">**</span><span class="n">nary_op_kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:81,</span> in <span class="ni">hessian</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">78</span> <span class="nd">@unary_to_nary</span>
<span class="g g-Whitespace"> </span><span class="mi">79</span> <span class="k">def</span> <span class="nf">hessian</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">80</span> <span class="s2">&quot;Returns a function that computes the exact Hessian.&quot;</span>
<span class="ne">---&gt; </span><span class="mi">81</span> <span class="k">return</span> <span class="n">jacobian</span><span class="p">(</span><span class="n">jacobian</span><span class="p">(</span><span class="n">fun</span><span class="p">))(</span><span class="n">x</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20,</span> in <span class="ni">unary_to_nary.&lt;locals&gt;.nary_operator.&lt;locals&gt;.nary_f</span><span class="nt">(*args, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">18</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">19</span> <span class="n">x</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">argnum</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">20</span> <span class="k">return</span> <span class="n">unary_operator</span><span class="p">(</span><span class="n">unary_f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="o">*</span><span class="n">nary_op_args</span><span class="p">,</span> <span class="o">**</span><span class="n">nary_op_kwargs</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:64,</span> in <span class="ni">jacobian</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">62</span> <span class="n">jacobian_shape</span> <span class="o">=</span> <span class="n">ans_vspace</span><span class="o">.</span><span class="n">shape</span> <span class="o">+</span> <span class="n">vspace</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">shape</span>
<span class="g g-Whitespace"> </span><span class="mi">63</span> <span class="n">grads</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="n">vjp</span><span class="p">,</span> <span class="n">ans_vspace</span><span class="o">.</span><span class="n">standard_basis</span><span class="p">())</span>
<span class="ne">---&gt; </span><span class="mi">64</span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">stack</span><span class="p">(</span><span class="n">grads</span><span class="p">),</span> <span class="n">jacobian_shape</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py:88,</span> in <span class="ni">stack</span><span class="nt">(arrays, axis)</span>
<span class="g g-Whitespace"> </span><span class="mi">83</span> <span class="k">def</span> <span class="nf">stack</span><span class="p">(</span><span class="n">arrays</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">84</span> <span class="c1"># this code is basically copied from numpy/core/shape_base.py&#39;s stack</span>
<span class="g g-Whitespace"> </span><span class="mi">85</span> <span class="c1"># we need it here because we want to re-implement stack in terms of the</span>
<span class="g g-Whitespace"> </span><span class="mi">86</span> <span class="c1"># primitives defined in this file</span>
<span class="ne">---&gt; </span><span class="mi">88</span> <span class="n">arrays</span> <span class="o">=</span> <span class="p">[</span><span class="n">array</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span> <span class="k">for</span> <span class="n">arr</span> <span class="ow">in</span> <span class="n">arrays</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">89</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">arrays</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">90</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;need at least one array to stack&#39;</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py:88,</span> in <span class="ni">&lt;listcomp&gt;</span><span class="nt">(.0)</span>
<span class="g g-Whitespace"> </span><span class="mi">83</span> <span class="k">def</span> <span class="nf">stack</span><span class="p">(</span><span class="n">arrays</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">84</span> <span class="c1"># this code is basically copied from numpy/core/shape_base.py&#39;s stack</span>
<span class="g g-Whitespace"> </span><span class="mi">85</span> <span class="c1"># we need it here because we want to re-implement stack in terms of the</span>
<span class="g g-Whitespace"> </span><span class="mi">86</span> <span class="c1"># primitives defined in this file</span>
<span class="ne">---&gt; </span><span class="mi">88</span> <span class="n">arrays</span> <span class="o">=</span> <span class="p">[</span><span class="n">array</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span> <span class="k">for</span> <span class="n">arr</span> <span class="ow">in</span> <span class="n">arrays</span><span class="p">]</span>
<span class="g g-Whitespace"> </span><span class="mi">89</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">arrays</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">90</span> <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;need at least one array to stack&#39;</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:32,</span> in <span class="ni">grad</span><span class="nt">(fun, x)</span>
<span class="g g-Whitespace"> </span><span class="mi">29</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">vspace</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span><span class="o">.</span><span class="n">size</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">30</span> <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Grad only applies to real scalar-output functions. &quot;</span>
<span class="g g-Whitespace"> </span><span class="mi">31</span> <span class="s2">&quot;Try jacobian, elementwise_grad or holomorphic_grad.&quot;</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">32</span> <span class="k">return</span> <span class="n">vjp</span><span class="p">(</span><span class="n">vspace</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span><span class="o">.</span><span class="n">ones</span><span class="p">())</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:14,</span> in <span class="ni">make_vjp.&lt;locals&gt;.vjp</span><span class="nt">(g)</span>
<span class="ne">---&gt; </span><span class="mi">14</span> <span class="k">def</span> <span class="nf">vjp</span><span class="p">(</span><span class="n">g</span><span class="p">):</span> <span class="k">return</span> <span class="n">backward_pass</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="n">end_node</span><span class="p">)</span>
@@ -2678,12 +2616,30 @@ Using TensorFlow results in a much better execution time. Try it!</p>
<span class="g g-Whitespace"> </span><span class="mi">659</span> <span class="n">target_meta</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">metadata</span><span class="p">(</span><span class="n">target</span><span class="p">)</span>
<span class="ne">--&gt; </span><span class="mi">660</span> <span class="k">return</span> <span class="k">lambda</span> <span class="n">g</span><span class="p">:</span> <span class="n">unbroadcast</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">g</span><span class="p">),</span> <span class="n">target_meta</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:651,</span> in <span class="ni">unbroadcast</span><span class="nt">(x, target_meta, broadcast_idx)</span>
<span class="g g-Whitespace"> </span><span class="mi">649</span> <span class="k">while</span> <span class="n">anp</span><span class="o">.</span><span class="n">ndim</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">target_ndim</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">650</span> <span class="n">x</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="n">broadcast_idx</span><span class="p">)</span>
<span class="ne">--&gt; </span><span class="mi">651</span> <span class="k">for</span> <span class="n">axis</span><span class="p">,</span> <span class="n">size</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">target_shape</span><span class="p">):</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:653,</span> in <span class="ni">unbroadcast</span><span class="nt">(x, target_meta, broadcast_idx)</span>
<span class="g g-Whitespace"> </span><span class="mi">651</span> <span class="k">for</span> <span class="n">axis</span><span class="p">,</span> <span class="n">size</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">target_shape</span><span class="p">):</span>
<span class="g g-Whitespace"> </span><span class="mi">652</span> <span class="k">if</span> <span class="n">size</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">653</span> <span class="n">x</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="n">axis</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="ne">--&gt; </span><span class="mi">653</span> <span class="n">x</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="n">axis</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">654</span> <span class="k">if</span> <span class="n">anp</span><span class="o">.</span><span class="n">iscomplexobj</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">target_iscomplex</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">655</span> <span class="n">x</span> <span class="o">=</span> <span class="n">anp</span><span class="o">.</span><span class="n">real</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py:48,</span> in <span class="ni">primitive.&lt;locals&gt;.f_wrapped</span><span class="nt">(*args, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">46</span> <span class="k">return</span> <span class="n">new_box</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">trace</span><span class="p">,</span> <span class="n">node</span><span class="p">)</span>
<span class="g g-Whitespace"> </span><span class="mi">47</span> <span class="k">else</span><span class="p">:</span>
<span class="ne">---&gt; </span><span class="mi">48</span> <span class="k">return</span> <span class="n">f_raw</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="nn">File &lt;__array_function__ internals&gt;:180,</span> in <span class="ni">sum</span><span class="nt">(*args, **kwargs)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:2296,</span> in <span class="ni">sum</span><span class="nt">(a, axis, dtype, out, keepdims, initial, where)</span>
<span class="g g-Whitespace"> </span><span class="mi">2293</span> <span class="k">return</span> <span class="n">out</span>
<span class="g g-Whitespace"> </span><span class="mi">2294</span> <span class="k">return</span> <span class="n">res</span>
<span class="ne">-&gt; </span><span class="mi">2296</span> <span class="k">return</span> <span class="n">_wrapreduction</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">add</span><span class="p">,</span> <span class="s1">&#39;sum&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">out</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="n">keepdims</span><span class="p">,</span>
<span class="g g-Whitespace"> </span><span class="mi">2297</span> <span class="n">initial</span><span class="o">=</span><span class="n">initial</span><span class="p">,</span> <span class="n">where</span><span class="o">=</span><span class="n">where</span><span class="p">)</span>
<span class="nn">File ~/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:86,</span> in <span class="ni">_wrapreduction</span><span class="nt">(obj, ufunc, method, axis, dtype, out, **kwargs)</span>
<span class="g g-Whitespace"> </span><span class="mi">83</span> <span class="k">else</span><span class="p">:</span>
<span class="g g-Whitespace"> </span><span class="mi">84</span> <span class="k">return</span> <span class="n">reduction</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="n">axis</span><span class="p">,</span> <span class="n">out</span><span class="o">=</span><span class="n">out</span><span class="p">,</span> <span class="o">**</span><span class="n">passkwargs</span><span class="p">)</span>
<span class="ne">---&gt; </span><span class="mi">86</span> <span class="k">return</span> <span class="n">ufunc</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">axis</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">out</span><span class="p">,</span> <span class="o">**</span><span class="n">passkwargs</span><span class="p">)</span>
<span class="ne">KeyboardInterrupt</span>:
</pre></div>
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+72 -60
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1275,10 +1285,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.07978850553011713
3.8232102961414203
[[ 1.25705685 3.70704566]
[ 3.70704566 12.1664372 ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.024792624800382218
3.9225384545636204
[[0.94623184 2.84401886]
[2.84401886 9.4477214 ]]
</pre></div>
</div>
</div>
@@ -1315,10 +1325,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.08931169286872433
2.047447724189861
[[1. 0.66729685]
[0.66729685 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.08536248571780691
1.8207274870895702
[[1. 0.74900488]
[0.74900488 1. ]]
</pre></div>
</div>
</div>
@@ -1348,30 +1358,32 @@ 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>[[ 2.37582891 5.4242743 ]
[-0.81925302 -3.60052901]
[ 0.37467515 3.16158074]
[-0.40478305 -2.22601408]
[-0.0776532 -1.70594608]
[-0.99434472 -2.2026985 ]
[ 0.71376303 2.77725472]
[ 0.94637206 2.69303453]
[-0.19791352 0.93366198]
[-1.91669165 -5.2546186 ]]
0 1
0 2.375829 5.424274
1 -0.819253 -3.600529
2 0.374675 3.161581
3 -0.404783 -2.226014
4 -0.077653 -1.705946
5 -0.994345 -2.202698
6 0.713763 2.777255
7 0.946372 2.693035
8 -0.197914 0.933662
9 -1.916692 -5.254619
0 1
0 1.000000 0.932382
1 0.932382 1.000000
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 1.10115017 1.66431407]
[ 0.12043521 1.32305911]
[-1.30023144 -3.36154104]
[-0.25200841 -1.11277166]
[-1.55102329 -4.20158083]
[ 0.72770687 0.97206657]
[ 0.76533281 2.10747579]
[-0.20666447 0.79623487]
[-0.63919355 -2.48490503]
[ 1.23449607 4.29764815]]
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1
0 1.101150 1.664314
1 0.120435 1.323059
2 -1.300231 -3.361541
3 -0.252008 -1.112772
4 -1.551023 -4.201581
5 0.727707 0.972067
6 0.765333 2.107476
7 -0.206664 0.796235
8 -0.639194 -2.484905
9 1.234496 4.297648
0 1
0 1.0000 0.9434
1 0.9434 1.0000
</pre></div>
</div>
</div>
@@ -1428,37 +1440,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.080947 0.086913 0.082764 0.085436 0.088029 0.075956 0.077683
2 0.0 0.086913 0.094044 0.088199 0.091365 0.094439 0.080171 0.082174
3 0.0 0.082764 0.088199 0.090624 0.093094 0.095465 0.086730 0.088375
4 0.0 0.085436 0.091365 0.093094 0.095805 0.098414 0.088651 0.090440
5 0.0 0.088029 0.094439 0.095465 0.098414 0.101263 0.090468 0.092401
6 0.0 0.075956 0.080171 0.086730 0.088651 0.090468 0.085390 0.086712
7 0.0 0.077683 0.082174 0.088375 0.090440 0.092401 0.086712 0.088127
8 0.0 0.079444 0.084218 0.090038 0.092252 0.094362 0.088038 0.089548
9 0.0 0.081252 0.086318 0.091731 0.094099 0.096365 0.089376 0.090985
10 0.0 0.068684 0.071868 0.080702 0.082126 0.083446 0.081103 0.082115
11 0.0 0.069978 0.073339 0.081978 0.083499 0.084915 0.082170 0.083248
12 0.0 0.071314 0.074859 0.083288 0.084910 0.086428 0.083260 0.084406
13 0.0 0.072697 0.076435 0.084637 0.086364 0.087988 0.084376 0.085592
14 0.0 0.074130 0.078071 0.086026 0.087864 0.089600 0.085518 0.086809
1 0.0 0.083179 0.086483 0.081217 0.083548 0.086239 0.072037 0.073514
2 0.0 0.086483 0.091362 0.082533 0.085853 0.089626 0.071638 0.073800
3 0.0 0.081217 0.082533 0.084963 0.086068 0.087429 0.079030 0.079670
4 0.0 0.083548 0.085853 0.086068 0.087871 0.089996 0.078945 0.080094
5 0.0 0.086239 0.089626 0.087429 0.089996 0.092956 0.079002 0.080706
6 0.0 0.072037 0.071638 0.079030 0.078945 0.079002 0.076071 0.075876
7 0.0 0.073514 0.073800 0.079670 0.080094 0.080706 0.075876 0.076066
8 0.0 0.075289 0.076321 0.080549 0.081527 0.082742 0.075842 0.076448
9 0.0 0.077391 0.079240 0.081686 0.083268 0.085145 0.075978 0.077035
10 0.0 0.063786 0.062216 0.072380 0.071437 0.070552 0.071436 0.070622
11 0.0 0.064606 0.063536 0.072591 0.072031 0.071560 0.071049 0.070531
12 0.0 0.065654 0.065121 0.072997 0.072849 0.072826 0.070805 0.070605
13 0.0 0.066948 0.067000 0.073612 0.073911 0.074374 0.070712 0.070855
14 0.0 0.068512 0.069203 0.074454 0.075239 0.076232 0.070780 0.071294
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.079444 0.081252 0.068684 0.069978 0.071314 0.072697 0.074130
2 0.084218 0.086318 0.071868 0.073339 0.074859 0.076435 0.078071
3 0.090038 0.091731 0.080702 0.081978 0.083288 0.084637 0.086026
4 0.092252 0.094099 0.082126 0.083499 0.084910 0.086364 0.087864
5 0.094362 0.096365 0.083446 0.084915 0.086428 0.087988 0.089600
6 0.088038 0.089376 0.081103 0.082170 0.083260 0.084376 0.085518
7 0.089548 0.090985 0.082115 0.083248 0.084406 0.085592 0.086809
8 0.091068 0.092607 0.083119 0.084319 0.085548 0.086808 0.088102
9 0.092607 0.094254 0.084122 0.085392 0.086694 0.088030 0.089404
10 0.083119 0.084122 0.078238 0.079089 0.079953 0.080832 0.081728
11 0.084319 0.085392 0.079089 0.079989 0.080903 0.081835 0.082785
12 0.085548 0.086694 0.079953 0.080903 0.081871 0.082857 0.083864
13 0.086808 0.088030 0.080832 0.081835 0.082857 0.083900 0.084967
14 0.088102 0.089404 0.081728 0.082785 0.083864 0.084967 0.086096
1 0.075289 0.077391 0.063786 0.064606 0.065654 0.066948 0.068512
2 0.076321 0.079240 0.062216 0.063536 0.065121 0.067000 0.069203
3 0.080549 0.081686 0.072380 0.072591 0.072997 0.073612 0.074454
4 0.081527 0.083268 0.071437 0.072031 0.072849 0.073911 0.075239
5 0.082742 0.085145 0.070552 0.071560 0.072826 0.074374 0.076232
6 0.075842 0.075978 0.071436 0.071049 0.070805 0.070712 0.070780
7 0.076448 0.077035 0.070622 0.070531 0.070605 0.070855 0.071294
8 0.077280 0.078359 0.069907 0.070135 0.070552 0.071173 0.072015
9 0.078359 0.079976 0.069293 0.069866 0.070655 0.071680 0.072961
10 0.069907 0.069293 0.068353 0.067515 0.066778 0.066145 0.065619
11 0.070135 0.069866 0.067515 0.066912 0.066425 0.066059 0.065821
12 0.070552 0.070655 0.066778 0.066425 0.066205 0.066127 0.066199
13 0.071173 0.071680 0.066145 0.066059 0.066127 0.066358 0.066766
14 0.072015 0.072961 0.065619 0.065821 0.066199 0.066766 0.067539
</pre></div>
</div>
</div>
+48 -36
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -829,10 +839,10 @@ number <span class="math notranslate nohighlight">\(i\)</span> is left out. Usin
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 0.139224 sec
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 0.147545 sec
Jackknife Statistics :
original bias std. error
99.9792 99.9692 0.149921
99.977 99.967 0.152494
</pre></div>
</div>
</div>
@@ -1051,7 +1061,7 @@ theorem.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Bootstrap Statistics :
original bias std. error
99.8978 15.0232 99.8962 0.149063
100.041 14.8133 100.041 0.149266
</pre></div>
</div>
</div>
@@ -1263,26 +1273,26 @@ Error: 0.10398646080125035
Bias^2: 0.1007711427354898
Var: 0.0032153180657605116
0.10398646080125035 &gt;= 0.1007711427354898 + 0.0032153180657605116 = 0.10398646080125032
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 3
Polynomial degree: 3
Error: 0.06547790180152355
Bias^2: 0.06208238634231949
Var: 0.0033955154592040936
0.06547790180152355 &gt;= 0.06208238634231949 + 0.0033955154592040936 = 0.06547790180152359
Polynomial degree: 4
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 4
Error: 0.06844519414009445
Bias^2: 0.06453579006728324
Var: 0.003909404072811226
0.06844519414009445 &gt;= 0.06453579006728324 + 0.003909404072811226 = 0.06844519414009446
Polynomial degree: 5
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 5
Error: 0.05227921801205686
Bias^2: 0.0481872773043029
Var: 0.004091940707753939
0.05227921801205686 &gt;= 0.0481872773043029 + 0.004091940707753939 = 0.052279218012056844
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 6
Polynomial degree: 6
Error: 0.037813671417389005
Bias^2: 0.033657685071527665
Var: 0.00415598634586135
@@ -1297,19 +1307,21 @@ Error: 0.017355848195593347
Bias^2: 0.010331721306655127
Var: 0.007024126888938232
0.017355848195593347 &gt;= 0.010331721306655127 + 0.007024126888938232 = 0.01735584819559336
Polynomial degree: 9
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 9
Error: 0.02660572763718093
Bias^2: 0.010018312644137363
Var: 0.016587414993043573
0.02660572763718093 &gt;= 0.010018312644137363 + 0.016587414993043573 = 0.026605727637180936
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 10
Polynomial degree: 10
Error: 0.021592704588025025
Bias^2: 0.010516485576645508
Var: 0.011076219011379514
0.021592704588025025 &gt;= 0.010516485576645508 + 0.011076219011379514 = 0.021592704588025022
Polynomial degree: 11
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 11
Error: 0.07160048164233104
Bias^2: 0.014436800088904942
Var: 0.05716368155342608
@@ -1326,7 +1338,7 @@ Var: 0.20867052175034223
0.22842468702219465 &gt;= 0.01975416527185249 + 0.20867052175034223 = 0.2284246870221947
</pre></div>
</div>
<img alt="_images/chapter3_66_4.png" src="_images/chapter3_66_4.png" />
<img alt="_images/chapter3_66_5.png" src="_images/chapter3_66_5.png" />
</div>
</div>
<p>The bias-variance tradeoff summarizes the fundamental tension in
@@ -1641,9 +1653,9 @@ Mean squared error on training data: 0.00060704
Mean squared error on test data: 3262.26814548
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58739/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95419/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(trainingerror), label=&#39;Training Error&#39;)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58739/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95419/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(testerror), label=&#39;Test Error&#39;)
</pre></div>
</div>
@@ -1877,7 +1889,7 @@ cross-validation (LOOCV).</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58739/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95419/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(estimated_mse_sklearn), label=&#39;Test Error&#39;)
</pre></div>
</div>
@@ -2766,7 +2778,7 @@ linear system as an equation would reduce this down to
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58739/4162706317.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95419/4162706317.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -2910,7 +2922,7 @@ with the form utilized in linear regression, viz.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58739/3777801602.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95419/3777801602.py:7: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -2950,7 +2962,7 @@ cost function is given by</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58739/438060758.py:10: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95419/438060758.py:10: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -2985,7 +2997,7 @@ cost function is given by</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58739/3544313922.py:9: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95419/3544313922.py:9: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
cb.ax.set_yticklabels(cb.ax.get_yticklabels(), fontsize=18)
</pre></div>
</div>
@@ -3038,43 +3050,43 @@ constant as opposed to ridge and OLS. We get a sparse solution with
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0%| | 0/10 [00:00&lt;?, ?it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0%| | 0/10 [00:00&lt;?, ?it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/sklearn/linear_model/_coordinate_descent.py:628: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 3.924e+00, tolerance: 1.797e+00
model = cd_fast.enet_coordinate_descent(
10%|█████████████████▏ | 1/10 [00:00&lt;00:07, 1.27it/s]
10%|███████████ | 1/10 [00:00&lt;00:06, 1.35it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 20%|██████████████████████████████████▍ | 2/10 [00:01&lt;00:06, 1.22it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 20%|██████████████████████ | 2/10 [00:01&lt;00:06, 1.22it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 30%|███████████████████████████████████████████████████▌ | 3/10 [00:02&lt;00:05, 1.32it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 30%|█████████████████████████████████ | 3/10 [00:02&lt;00:05, 1.32it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 40%|████████████████████████████████████████████████████████████████████▊ | 4/10 [00:02&lt;00:04, 1.43it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 40%|████████████████████████████████████████████ | 4/10 [00:03&lt;00:04, 1.36it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 50%|██████████████████████████████████████████████████████████████████████████████████████ | 5/10 [00:03&lt;00:03, 1.48it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 50%|████████████████████████████████████████████████████████ | 5/10 [00:03&lt;00:03, 1.40it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 60%|███████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 6/10 [00:04&lt;00:02, 1.55it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 60%|███████████████████████████████████████████████████████████████████ | 6/10 [00:04&lt;00:02, 1.47it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 70%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 7/10 [00:04&lt;00:01, 1.50it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 70%|██████████████████████████████████████████████████████████████████████████████ | 7/10 [00:04&lt;00:01, 1.53it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 80%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌ | 8/10 [00:05&lt;00:01, 1.52it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 80%|█████████████████████████████████████████████████████████████████████████████████████████ | 8/10 [00:05&lt;00:01, 1.54it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 90%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊ | 9/10 [00:06&lt;00:00, 1.50it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 90%|████████████████████████████████████████████████████████████████████████████████████████████████████ | 9/10 [00:06&lt;00:00, 1.49it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:06&lt;00:00, 1.52it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:06&lt;00:00, 1.45it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:06&lt;00:00, 1.47it/s]
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:06&lt;00:00, 1.43it/s]
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+14 -6
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -757,9 +767,9 @@ predicting the target features of query instances is as follows:</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>2nd degree coefficients:
zero power: -1.4725246793626128
first power: -0.08935132374099551
second power: 0.00034688149480437765
zero power: -1.5105332296929628
first power: 0.08398399377155011
second power: -0.0003701342170783489
</pre></div>
</div>
<img alt="_images/chapter6_1_1.png" src="_images/chapter6_1_1.png" />
@@ -1626,9 +1636,7 @@ Test set accuracy with Logistic Regression: 0.94
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Test set accuracy with SVM: 0.63
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Test set accuracy with Decision Trees: 0.90
Test set accuracy with Decision Trees: 0.90
Test set accuracy Logistic Regression with scaled data: 0.96
Test set accuracy SVM with scaled data: 0.96
Test set accuracy with Decision Trees and scaled data: 0.89
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+79 -69
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -711,10 +721,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.14934258650797513
4.548263635652985
[[ 1.0875061 3.3260513 ]
[ 3.3260513 11.10994958]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.13035147135400782
4.25879315330607
[[0.86867512 2.59009792]
[2.59009792 8.82533209]]
</pre></div>
</div>
</div>
@@ -754,10 +764,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.09291556244521161
2.096511363983559
[[1. 0.7198234]
[0.7198234 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.08690184845323
1.521422502348998
[[1. 0.69768266]
[0.69768266 1. ]]
</pre></div>
</div>
</div>
@@ -786,30 +796,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.20480187 0.26586817]
[ 0.72601722 1.13675593]
[ 0.02649469 -0.9834505 ]
[ 0.97548406 1.6266783 ]
[-1.59078383 -4.25673276]
[-0.40596423 -0.31486917]
[-0.34654596 -1.94627617]
[-1.33062878 -3.73785069]
[ 2.22810365 9.25389111]
[-0.48697869 -1.04401421]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 1.14550854 1.96870431]
[ 0.79787194 3.11438414]
[-0.18497496 -1.31315504]
[-1.52706754 -4.97482498]
[-1.30190897 -3.11113486]
[-0.08421808 -1.70928399]
[ 0.11992194 -0.07776381]
[-0.90717653 -2.20404927]
[ 1.05201041 5.38762019]
[ 0.89003324 2.9195033 ]]
0 1
0 0.204802 0.265868
1 0.726017 1.136756
2 0.026495 -0.983450
3 0.975484 1.626678
4 -1.590784 -4.256733
5 -0.405964 -0.314869
6 -0.346546 -1.946276
7 -1.330629 -3.737851
8 2.228104 9.253891
9 -0.486979 -1.044014
0 1.145509 1.968704
1 0.797872 3.114384
2 -0.184975 -1.313155
3 -1.527068 -4.974825
4 -1.301909 -3.111135
5 -0.084218 -1.709284
6 0.119922 -0.077764
7 -0.907177 -2.204049
8 1.052010 5.387620
9 0.890033 2.919503
0 1
0 1.000000 0.950423
1 0.950423 1.000000
0 1.000000 0.937057
1 0.937057 1.000000
</pre></div>
</div>
</div>
@@ -866,37 +876,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.072147 0.072728 0.071758 0.072209 0.072843 0.064428 0.064668
2 0.0 0.072728 0.075385 0.069979 0.071530 0.073408 0.061386 0.062260
3 0.0 0.071758 0.069979 0.076968 0.076244 0.075522 0.072286 0.071935
4 0.0 0.072209 0.071530 0.076244 0.076161 0.076150 0.070898 0.070950
5 0.0 0.072843 0.073408 0.075522 0.076150 0.076934 0.069399 0.069885
6 0.0 0.064428 0.061386 0.072286 0.070898 0.069399 0.069873 0.069179
7 0.0 0.064668 0.062260 0.071935 0.070950 0.069885 0.069179 0.068758
8 0.0 0.065062 0.063354 0.071655 0.071103 0.070514 0.068494 0.068360
9 0.0 0.065616 0.064690 0.071433 0.071356 0.071291 0.067793 0.067967
10 0.0 0.057287 0.053787 0.066153 0.064505 0.062691 0.065212 0.064382
11 0.0 0.057387 0.054286 0.065949 0.064573 0.063048 0.064834 0.064202
12 0.0 0.057607 0.054932 0.065830 0.064739 0.063518 0.064507 0.064077
13 0.0 0.057951 0.055737 0.065788 0.065001 0.064107 0.064218 0.064000
14 0.0 0.058422 0.056717 0.065818 0.065358 0.064820 0.063954 0.063959
1 0.0 0.080345 0.078573 0.079174 0.077839 0.076679 0.070275 0.069320
2 0.0 0.078573 0.078146 0.079202 0.078688 0.078268 0.071580 0.071186
3 0.0 0.079174 0.079202 0.083342 0.083016 0.082784 0.076947 0.076648
4 0.0 0.077839 0.078688 0.083016 0.083260 0.083547 0.077485 0.077601
5 0.0 0.076679 0.078268 0.082784 0.083547 0.084312 0.078044 0.078541
6 0.0 0.070275 0.071580 0.076947 0.077485 0.078044 0.072947 0.073258
7 0.0 0.069320 0.071186 0.076648 0.077601 0.078541 0.073258 0.073882
8 0.0 0.068539 0.070918 0.076479 0.077813 0.079107 0.073647 0.074561
9 0.0 0.067922 0.070772 0.076434 0.078123 0.079747 0.074115 0.075302
10 0.0 0.061319 0.063395 0.068977 0.070098 0.071191 0.066686 0.067431
11 0.0 0.060726 0.063206 0.068843 0.070274 0.071656 0.066988 0.067974
12 0.0 0.060275 0.063130 0.068827 0.070547 0.072200 0.067374 0.068587
13 0.0 0.059956 0.063161 0.068924 0.070916 0.072824 0.067843 0.069270
14 0.0 0.059761 0.063294 0.069129 0.071379 0.073528 0.068394 0.070024
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.065062 0.065616 0.057287 0.057387 0.057607 0.057951 0.058422
2 0.063354 0.064690 0.053787 0.054286 0.054932 0.055737 0.056717
3 0.071655 0.071433 0.066153 0.065949 0.065830 0.065788 0.065818
4 0.071103 0.071356 0.064505 0.064573 0.064739 0.065001 0.065358
5 0.070514 0.071291 0.062691 0.063048 0.063518 0.064107 0.064820
6 0.068494 0.067793 0.065212 0.064834 0.064507 0.064218 0.063954
7 0.068360 0.067967 0.064382 0.064202 0.064077 0.064000 0.063959
8 0.068268 0.068206 0.063526 0.063549 0.063637 0.063781 0.063977
9 0.068206 0.068504 0.062616 0.062853 0.063163 0.063545 0.063995
10 0.063526 0.062616 0.061724 0.061284 0.060870 0.060471 0.060071
11 0.063549 0.062853 0.061284 0.060994 0.060734 0.060490 0.060251
12 0.063637 0.063163 0.060870 0.060734 0.060629 0.060547 0.060475
13 0.063781 0.063545 0.060471 0.060490 0.060547 0.060631 0.060735
14 0.063977 0.063995 0.060071 0.060251 0.060475 0.060735 0.061025
1 0.068539 0.067922 0.061319 0.060726 0.060275 0.059956 0.059761
2 0.070918 0.070772 0.063395 0.063206 0.063130 0.063161 0.063294
3 0.076479 0.076434 0.068977 0.068843 0.068827 0.068924 0.069129
4 0.077813 0.078123 0.070098 0.070274 0.070547 0.070916 0.071379
5 0.079107 0.079747 0.071191 0.071656 0.072200 0.072824 0.073528
6 0.073647 0.074115 0.066686 0.066988 0.067374 0.067843 0.068394
7 0.074561 0.075302 0.067431 0.067974 0.068587 0.069270 0.070024
8 0.075513 0.076508 0.068215 0.068985 0.069811 0.070696 0.071643
9 0.076508 0.077745 0.069045 0.070027 0.071055 0.072132 0.073262
10 0.068215 0.069045 0.061898 0.062520 0.063197 0.063933 0.064728
11 0.068985 0.070027 0.062520 0.063332 0.064189 0.065096 0.066054
12 0.069811 0.071055 0.063197 0.064189 0.065217 0.066286 0.067400
13 0.070696 0.072132 0.063933 0.065096 0.066286 0.067511 0.068775
14 0.071643 0.073262 0.064728 0.066054 0.067400 0.068775 0.070183
</pre></div>
</div>
</div>
@@ -1085,10 +1095,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.935972 1.991047
1 1.991047 2.000783
[[3.93597168 1.99104747]
[1.99104747 2.00078324]]
0 4.032196 2.034476
1 2.034476 1.997746
[[4.0321956 2.03447649]
[2.03447649 1.99774602]]
</pre></div>
</div>
</div>
@@ -1115,8 +1125,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.93597168 1.99104747]
[1.99104747 2.00078324]]
[[4.0321956 2.03447649]
[2.03447649 1.99774602]]
</pre></div>
</div>
<img alt="_images/chapter8_65_1.png" src="_images/chapter8_65_1.png" />
@@ -1176,16 +1186,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.182086698929565
0.7546682196464342
5.2895786617507
0.7403629637766833
First eigenvector
[0.84767088 0.53052247]
[0.85064942 0.52573336]
Second eigenvector
[-0.53052247 0.84767088]
[-0.52573336 0.85064942]
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvector of largest eigenvalue
[0.84767088 0.53052247]
[-0.85064942 -0.52573336]
</pre></div>
</div>
</div>
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -0,0 +1,514 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Exercises week 39 &#8212; Applied Data Analysis and Machine Learning</title>
<link href="_static/css/theme.css" rel="stylesheet">
<link href="_static/css/index.ff1ffe594081f20da1ef19478df9384b.css" rel="stylesheet">
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-book-theme.css?digest=c3fdc42140077d1ad13ad2f1588a4309" />
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/mystnb.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
<link rel="preload" as="script" href="_static/js/index.be7d3bbb2ef33a8344ce.js">
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/clipboard.min.js"></script>
<script src="_static/copybutton.js"></script>
<script>let toggleHintShow = 'Click to show';</script>
<script>let toggleHintHide = 'Click to hide';</script>
<script>let toggleOpenOnPrint = 'true';</script>
<script src="_static/togglebutton.js"></script>
<script>var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
<script src="_static/sphinx-book-theme.d59cb220de22ca1c485ebbdc042f0030.js"></script>
<script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
const thebe_selector = ".thebe,.cell"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output, .cell_output"
</script>
<script async="async" src="_static/sphinx-thebe.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Week 39: Optimization and Gradient Methods" href="week39.html" />
<link rel="prev" title="Week 38: Logistic Regression and Optimization" href="week38.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
<!-- Google Analytics -->
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-fluid" id="banner"></div>
<div class="container-xl">
<div class="row">
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
<div class="navbar-brand-box">
<a class="navbar-brand text-wrap" href="index.html">
<!-- `logo` is deprecated in Sphinx 4.0, so remove this when we stop supporting 3 -->
<img src="_static/logo.png" class="logo" alt="logo">
<h1 class="site-logo" id="site-title">Applied Data Analysis and Machine Learning</h1>
</a>
</div><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
<div class="bd-toc-item active">
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="intro.html">
Applied Data Analysis and Machine Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
About the course
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="schedule.html">
Teaching schedule with links to material
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="teachers.html">
Teachers and Grading
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="textbooks.html">
Textbooks
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Review of Statistics with Resampling Techniques and Linear Algebra
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="statistics.html">
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
From Regression to Support Vector Machines
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter1.html">
3. Linear Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter2.html">
4. Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter3.html">
5. Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter4.html">
6. Logistic Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapteroptimization.html">
7. Optimization, the central part of any Machine Learning algortithm
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter5.html">
8. Support Vector Machines, overarching aims
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Decision Trees, Ensemble Methods and Boosting
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter6.html">
9. Decision trees, overarching aims
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter7.html">
10. Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Dimensionality Reduction
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter8.html">
11. Basic ideas of the Principal Component Analysis (PCA)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="clustering.html">
12. Clustering and Unsupervised Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Deep Learning Methods
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter9.html">
13. Neural networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter10.html">
14. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
15. Solving Differential Equations with Deep Learning
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter12.html">
16. Convolutional Neural Networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter13.html">
17. Recurrent neural networks: Overarching view
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Weekly material, notes and exercises
</span>
</p>
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek34.html">
Exercises week 34
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week34.html">
Week 34: Introduction to the course, Logistics and Practicalities
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek35.html">
Exercises week 35
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week35.html">
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: 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>
<li class="toctree-l1">
<a class="reference internal" href="week38.html">
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</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>
</div>
</nav> <!-- To handle the deprecated key -->
<div class="navbar_extra_footer">
Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
</div>
</div>
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
<div class="topbar container-xl fixed-top">
<div class="topbar-contents row">
<div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
<div class="col pl-md-4 topbar-main">
<button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
title="Toggle navigation" data-toggle="tooltip" data-placement="left">
<i class="fas fa-bars"></i>
<i class="fas fa-arrow-left"></i>
<i class="fas fa-arrow-up"></i>
</button>
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
class="fas fa-download"></i></button>
<div class="dropdown-buttons">
<!-- ipynb file if we had a myst markdown file -->
<!-- Download raw file -->
<a class="dropdown-buttons" href="_sources/exercisesweek39.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
data-placement="left">.ipynb</button></a>
<!-- Download PDF via print -->
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
onclick="printPdf(this)" data-toggle="tooltip" data-placement="left">.pdf</button>
</div>
</div>
<!-- Source interaction buttons -->
<!-- Full screen (wrap in <a> to have style consistency -->
<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
title="Fullscreen mode"><i
class="fas fa-expand"></i></button></a>
<!-- Launch buttons -->
</div>
<!-- Table of contents -->
<div class="d-none d-md-block col-md-2 bd-toc show noprint">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i> Contents
</div>
<nav id="bd-toc-nav" aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#overarching-aims-of-the-exercises-this-week">
Overarching aims of the exercises this week
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div id="main-content" class="row">
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
<!-- Table of contents that is only displayed when printing the page -->
<div id="jb-print-docs-body" class="onlyprint">
<h1>Exercises week 39</h1>
<!-- Table of contents -->
<div id="print-main-content">
<div id="jb-print-toc">
<div>
<h2> Contents </h2>
</div>
<nav aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#overarching-aims-of-the-exercises-this-week">
Overarching aims of the exercises this week
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div>
<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
doconce format html exercisesweek39.do.txt -->
<!-- dom:TITLE: Exercises week 39 --><div class="tex2jax_ignore mathjax_ignore section" id="exercises-week-39">
<h1>Exercises week 39<a class="headerlink" href="#exercises-week-39" title="Permalink to this headline"></a></h1>
<p><strong>September 23-27, 2024</strong></p>
<p>Date: <strong>Deadline is Friday September 27 at midnight</strong></p>
<div class="section" id="overarching-aims-of-the-exercises-this-week">
<h2>Overarching aims of the exercises this week<a class="headerlink" href="#overarching-aims-of-the-exercises-this-week" title="Permalink to this headline"></a></h2>
<p>The aim of the exercises this week is to aid you in getting started
with writing the report. This will be discussed during the lab
sessions as well.</p>
<p>A general guideline can be found at <a class="reference external" href="https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/EvaluationGrading/EvaluationForm.md">https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/EvaluationGrading/EvaluationForm.md</a>.</p>
<p>Similarly, an example of an earlier project can be found at <a class="reference external" href="https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/ReportExample/ReportSample.pdf">https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/ReportExample/ReportSample.pdf</a></p>
<p>Your task this week is to</p>
<ol class="simple">
<li><p>Write an abstract for your project</p></li>
<li><p>Write an introduction</p></li>
<li><p>Include references</p></li>
</ol>
<p>A short feedback to the this exercise will be available before the project deadline. And you can reuse these elements in your final report.</p>
</div>
</div>
<script type="text/x-thebe-config">
{
requestKernel: true,
binderOptions: {
repo: "binder-examples/jupyter-stacks-datascience",
ref: "master",
},
codeMirrorConfig: {
theme: "abcdef",
mode: "python"
},
kernelOptions: {
kernelName: "python3",
path: "./."
},
predefinedOutput: true
}
</script>
<script>kernelName = 'python3'</script>
</div>
<!-- Previous / next buttons -->
<div class='prev-next-area'>
<a class='left-prev' id="prev-link" href="week38.html" title="previous page">
<i class="fas fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Week 38: Logistic Regression and Optimization</p>
</div>
</a>
<a class='right-next' id="next-link" href="week39.html" title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Week 39: Optimization and Gradient Methods</p>
</div>
<i class="fas fa-angle-right"></i>
</a>
</div>
</div>
</div>
<footer class="footer">
<p>
By Morten Hjorth-Jensen<br/>
&copy; Copyright 2021.<br/>
</p>
</footer>
</main>
</div>
</div>
<script src="_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
</body>
</html>
@@ -294,6 +294,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+10
View File
@@ -295,6 +295,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+39 -29
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -613,8 +623,8 @@ matrices and vectors.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[-0.29015871 0.69417174 -1.07998756 0.34332677 0.19547923 -1.09755017
0.86197958 -0.15546887 0.14369927 1.96251859]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 0.69465386 1.75956617 -0.23303727 -0.53125507 1.34598722 -1.09928714
1.37013105 0.79898903 -0.23663482 0.99427512]
</pre></div>
</div>
</div>
@@ -835,26 +845,26 @@ as (recall that we user lowercase letters for vectors and uppercase letters for
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.08233627 0.43727575 0.01759442 0.01179415 0.34483937 0.32733949
0.71332117 0.20347912 0.57521514 0.56042437]
[0.64909048 0.55179339 0.13847167 0.04224929 0.89540936 0.5142856
0.85871255 0.75080943 0.34026086 0.50850373]
[0.03239393 0.87884833 0.41310208 0.82418008 0.01014331 0.24284399
0.93668828 0.79247398 0.48062913 0.77803692]
[0.73068535 0.47910545 0.95715036 0.11844773 0.76686148 0.31453949
0.6029291 0.5443909 0.29398019 0.96585824]
[0.0179826 0.51643579 0.53723188 0.03844073 0.25989189 0.20834188
0.98619989 0.40833375 0.52876551 0.76612827]
[0.44830934 0.94099173 0.07123177 0.96305058 0.11596834 0.69756791
0.60664448 0.89457785 0.86016288 0.33615742]
[0.35243372 0.77465911 0.37532078 0.38399622 0.20728198 0.1108407
0.83020679 0.48170743 0.99003341 0.99956033]
[0.82832579 0.42553096 0.02355756 0.28542801 0.96894842 0.70711022
0.8825782 0.04072235 0.24369936 0.79622905]
[0.60762863 0.21699817 0.20218457 0.63071772 0.02358547 0.62886648
0.44286735 0.78745927 0.30982436 0.76277254]
[0.52173381 0.9495484 0.47433659 0.73203674 0.95226607 0.40072098
0.35098705 0.46544987 0.66456459 0.25512598]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.81947005 0.93619369 0.37449168 0.91933003 0.76855921 0.41820116
0.96853248 0.60375434 0.96015381 0.30269539]
[0.46086448 0.16777789 0.9930742 0.10837392 0.69089532 0.94221383
0.53629564 0.50327198 0.33734605 0.04757138]
[0.51069279 0.12363332 0.79171202 0.16791183 0.62617788 0.9288904
0.85112594 0.86519139 0.61192712 0.90842732]
[0.82551764 0.67524588 0.02175561 0.1118933 0.42575338 0.45731379
0.61069681 0.40184681 0.18702469 0.71838601]
[0.68655456 0.11747908 0.28253033 0.4591127 0.68072161 0.59372982
0.95343966 0.24780663 0.98740373 0.06808421]
[0.99512017 0.14828178 0.02354386 0.90860768 0.891715 0.39039235
0.48151166 0.43563433 0.52657934 0.73176319]
[0.77030637 0.00676256 0.37454707 0.5076963 0.51937727 0.46065811
0.65917558 0.72962885 0.99370678 0.92341148]
[0.16292908 0.17214545 0.44995924 0.20367355 0.64885265 0.34225662
0.4215795 0.27933134 0.02552966 0.62908496]
[0.8084934 0.51364117 0.4937346 0.05296475 0.69247718 0.56783103
0.85276538 0.52635761 0.96461948 0.67374815]
[0.02137508 0.03177331 0.78186404 0.33096549 0.8423144 0.07745579
0.4619526 0.61414743 0.38460453 0.51928402]]
</pre></div>
</div>
</div>
@@ -914,13 +924,13 @@ 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.0018310257999764163
4.092608577084595
0.31555734196707536
[[ 0.78671736 2.38337498 2.04657426]
[ 2.38337498 8.33235647 6.05002471]
[ 2.04657426 6.05002471 10.13152828]]
[15.98413606 0.08227668 3.18418938]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.07218473624441492
4.346000154268618
0.09048717285916912
[[ 1.0974119 3.2131067 3.36880327]
[ 3.2131067 10.51564682 9.75138064]
[ 3.36880327 9.75138064 17.26527089]]
[25.09487358 0.09070064 3.6927554 ]
</pre></div>
</div>
</div>
Binary file not shown.
+13 -3
View File
@@ -55,7 +55,7 @@ const thebe_selector_output = ".output, .cell_output"
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Week 38: Logistic Regression and Optimization" href="week38.html" />
<link rel="prev" title="Week 39: Optimization and Gradient Methods" href="week39.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
@@ -297,6 +297,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1038,11 +1048,11 @@ of code developers and contributors keeps increasing.</p>
<!-- Previous / next buttons -->
<div class='prev-next-area'>
<a class='left-prev' id="prev-link" href="week38.html" title="previous page">
<a class='left-prev' id="prev-link" href="week39.html" title="previous page">
<i class="fas fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Week 38: Logistic Regression and Optimization</p>
<p class="prev-next-title">Week 39: Optimization and Gradient Methods</p>
</div>
</a>
</div>
@@ -296,6 +296,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+10
View File
@@ -300,6 +300,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
File diff suppressed because one or more lines are too long
+41 -31
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -985,27 +995,27 @@ uncorrelated.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.9841870203276504
[[ 3.57492326 2.52888979 5.61382924 2.32419549 4.2986082 3.83718206
4.7658599 4.76527062 8.55196383 8.05747369]
[ 2.52888979 1.78892891 3.97120565 1.64412879 3.0408223 2.71441086
3.37135473 3.37093787 6.04963309 5.69983227]
[ 5.61382924 3.97120565 8.81559586 3.64976691 6.75025744 6.02566356
7.48399942 7.48307405 13.42945319 12.65293772]
[ 2.32419549 1.64412879 3.64976691 1.51104913 2.79469098 2.49470005
3.09846933 3.09808622 5.55996153 5.23847441]
[ 4.2986082 3.0408223 6.75025744 2.79469098 5.16879134 4.61395701
5.73063053 5.72992196 10.28316949 9.68857788]
[ 3.83718206 2.71441086 6.02566356 2.49470005 4.61395701 4.11868033
5.11548661 5.1148541 9.1793417 8.64857542]
[ 4.7658599 3.37135473 7.48399942 3.09846933 5.73063053 5.11548661
6.35354073 6.35275513 11.40093324 10.74171049]
[ 4.76527062 3.37093787 7.48307405 3.09808622 5.72992196 5.1148541
6.35275513 6.35196964 11.39952356 10.74038232]
[ 8.55196383 6.04963309 13.42945319 5.55996153 10.28316949 9.1793417
11.40093324 11.39952356 20.4580854 19.2751616 ]
[ 8.05747369 5.69983227 12.65293772 5.23847441 9.68857788 8.64857542
10.74171049 10.74038232 19.2751616 18.16063661]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>3.613893902124586
[[18.33217312 13.09829902 1.98271562 18.53534008 -0.88860399 18.12957454
7.18043393 1.59698459 17.87186187 10.81979166]
[13.09829902 9.35870701 1.41664613 13.24346138 -0.63490568 12.95354276
5.13040489 1.14104212 12.76940759 7.73071831]
[ 1.98271562 1.41664613 0.21444055 2.00468914 -0.09610694 1.96080358
0.77659961 0.17272182 1.93293067 1.17021424]
[18.53534008 13.24346138 2.00468914 18.74075864 -0.89845198 18.33049619
7.26001134 1.61468323 18.0699274 10.93970238]
[-0.88860399 -0.63490568 -0.09610694 -0.89845198 0.04307275 -0.87878356
-0.3480527 -0.07740964 -0.86629161 -0.52446101]
[18.12957454 12.95354276 1.96080358 18.33049619 -0.87878356 17.92921498
7.10107914 1.57933547 17.67435043 10.7002164 ]
[ 7.18043393 5.13040489 0.77659961 7.26001134 -0.3480527 7.10107914
2.81246697 0.62551462 7.000137 4.23794815]
[ 1.59698459 1.14104212 0.17272182 1.61468323 -0.07740964 1.57933547
0.62551462 0.13911934 1.55688514 0.94255277]
[17.87186187 12.76940759 1.93293067 18.0699274 -0.86629161 17.67435043
7.000137 1.55688514 17.42310878 10.54811237]
[10.81979166 7.73071831 1.17021424 10.93970238 -0.52446101 10.7002164
4.23794815 0.94255277 10.54811237 6.38592549]]
</pre></div>
</div>
</div>
@@ -1273,15 +1283,15 @@ more practically oriented methods like the blocking technique.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.07950356694388497
4.124228866018077
0.3908470004999506
1.2475908482537097 11.548432150659993 27.870704644539707
3.6568686180915178 4.6156409232714415 13.395980256477532
[[ 1.24759085 3.65686862 4.61564092]
[ 3.65686862 11.54843215 13.39598026]
[ 4.61564092 13.39598026 27.87070464]]
[36.35957915 0.07241855 4.23472994]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.0973900819831327
4.559791959661649
0.6333349473431832
1.1064601390492845 11.271260217275557 17.072290639572326
3.390334838933238 3.4951301940723654 11.033233504714921
[[ 1.10646014 3.39033484 3.49513019]
[ 3.39033484 11.27126022 11.0332335 ]
[ 3.49513019 11.0332335 17.07229064]]
[26.5020612 0.075885 2.8720648]
</pre></div>
</div>
</div>
@@ -1611,7 +1621,7 @@ assumption for approximating <span class="math notranslate nohighlight">\(\sigma
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.05577845931438246 1.0303586629618948
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.02214409916811925 1.073576975500551
</pre></div>
</div>
<img alt="_images/statistics_188_1.png" src="_images/statistics_188_1.png" />
@@ -296,6 +296,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -296,6 +296,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+40 -30
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1673,8 +1683,8 @@ developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly he
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[-1.24454968 1.12382443 0.67088558 1.12498355 1.0342028 -0.44563226
0.14599499 0.07378525 0.03479236 -1.2976637 ]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[-0.60588173 1.59884169 -1.56922102 -1.32068736 -0.21631786 0.37600869
-0.14841322 -0.83655756 0.88809826 -0.85625134]
</pre></div>
</div>
</div>
@@ -1899,26 +1909,26 @@ lowercase letters for vectors and uppercase letters for matrices)</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.50306335 0.66487438 0.75677341 0.01349244 0.2813829 0.80056922
0.07974741 0.63046054 0.05098714 0.26479234]
[0.17861414 0.3388112 0.30005983 0.35520169 0.5399913 0.51709529
0.36339156 0.71582784 0.34568909 0.23164401]
[0.11922031 0.771128 0.20051449 0.07890044 0.96866031 0.34346829
0.5116375 0.52732966 0.80637385 0.69435454]
[0.94291287 0.29238145 0.84711297 0.22849742 0.56967917 0.1636508
0.15833751 0.84254917 0.05068486 0.54057582]
[0.17856374 0.71524686 0.66498292 0.00256622 0.72427854 0.50667812
0.0894015 0.22688898 0.54873252 0.31727523]
[0.73578772 0.81479491 0.45620975 0.2662452 0.47757553 0.64322974
0.54921401 0.70630967 0.51136852 0.59683811]
[0.37837864 0.71860732 0.35320952 0.67495943 0.16188604 0.41925189
0.28956161 0.06685171 0.75654448 0.28923 ]
[0.91099021 0.8387133 0.18277213 0.40418675 0.7249499 0.46415522
0.35018806 0.87148597 0.94141801 0.50911289]
[0.86066395 0.12235593 0.82418352 0.57881465 0.82559478 0.96826039
0.291056 0.41675053 0.06430789 0.96432396]
[0.91270333 0.64362404 0.18816387 0.81318307 0.47989224 0.20375464
0.33145794 0.92192012 0.33596404 0.18085537]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[0.32641434 0.35731585 0.64796751 0.41146753 0.67561021 0.53312817
0.3910042 0.88157423 0.4576811 0.48004784]
[0.70469324 0.28496213 0.84862355 0.6988905 0.95890587 0.19849513
0.89058005 0.51546825 0.88289263 0.06926192]
[0.38198866 0.33000573 0.80740939 0.54935794 0.38934047 0.87740526
0.45053025 0.27231287 0.7070883 0.7989356 ]
[0.4198932 0.3727791 0.95400323 0.86459987 0.2666905 0.13564988
0.97498674 0.9450635 0.6383903 0.57803254]
[0.13896095 0.13663125 0.68826552 0.13729154 0.91672129 0.08266769
0.88639567 0.16407038 0.36353321 0.81007381]
[0.31849289 0.68735473 0.1767857 0.42873361 0.44454123 0.21333766
0.94285762 0.72710494 0.37153115 0.21070843]
[0.11930916 0.28021598 0.69566966 0.98770503 0.88653291 0.82161167
0.90114639 0.7127128 0.97486336 0.26152075]
[0.55386681 0.37919989 0.57468142 0.35980374 0.7150195 0.70499955
0.9647801 0.63142399 0.97512176 0.97570392]
[0.24613581 0.62573269 0.41487642 0.42095725 0.51447004 0.41869784
0.34483955 0.55582742 0.85711016 0.17739525]
[0.89533642 0.03382942 0.918785 0.79718864 0.64361375 0.4843772
0.33532886 0.13164176 0.63209435 0.39279291]]
</pre></div>
</div>
</div>
@@ -1973,13 +1983,13 @@ 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.1385510301651882
4.344176915013831
0.13134148011170077
[[ 0.87981676 2.52698542 2.65591748]
[ 2.52698542 8.29861395 7.76790092]
[ 2.65591748 7.76790092 13.4831139 ]]
[19.77845284 0.09028702 2.79280475]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.050315327923114654
3.7539148284817965
-0.09246293455466892
[[ 0.90894281 2.8691787 2.58589719]
[ 2.8691787 10.23481471 8.16535252]
[ 2.58589719 8.16535252 12.44536331]]
[20.33742926 0.08458591 3.16710567]
</pre></div>
</div>
</div>
@@ -2204,7 +2214,7 @@ Name: Aragorn, dtype: object
<div class="cell_output docutils container">
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
<span class="ne">AttributeError</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
<span class="nn">/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58840/1326197715.py</span> in <span class="ni">?</span><span class="nt">()</span>
<span class="nn">/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95519/1326197715.py</span> in <span class="ni">?</span><span class="nt">()</span>
<span class="ne">----&gt; </span><span class="mi">6</span> <span class="n">new_hobbit</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;First Name&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Peregrin&quot;</span><span class="p">],</span>
<span class="g g-Whitespace"> </span><span class="mi">7</span> <span class="s1">&#39;Last Name&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Took&quot;</span><span class="p">],</span>
<span class="g g-Whitespace"> </span><span class="mi">8</span> <span class="s1">&#39;Place of birth&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Shire&quot;</span><span class="p">],</span>
+45 -25
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1641,7 +1651,7 @@ Since we are not using <strong>Scikit-Learn</strong> here we can define our own
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.9969513794144311
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.9952505213910134
</pre></div>
</div>
</div>
@@ -1658,7 +1668,7 @@ Since we are not using <strong>Scikit-Learn</strong> here we can define our own
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.007658477904313023
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.008753288788081405
</pre></div>
</div>
</div>
@@ -1673,23 +1683,31 @@ Since we are not using <strong>Scikit-Learn</strong> here we can define our own
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[0.00053122 0.03115122 0.00789262 0.02218076 0.00573727 0.00557893
0.00099778 0.01234 0.03960002 0.03596557 0.0134113 0.00556946
0.00136125 0.10719554 0.02754248 0.01409478 0.01760144 0.01032533
0.01241284 0.01039879 0.00100913 0.02944152 0.00512599 0.00747773
0.06260611 0.0231353 0.01624447 0.02923006 0.0046544 0.07332248
0.02338085 0.02920675 0.02286267 0.04353549 0.00569512 0.02664408
0.01098247 0.02156565 0.03529801 0.00507531 0.00554202 0.05141614
0.02031987 0.01244297 0.01551724 0.00174738 0.01044475 0.01161645
0.02622039 0.03285784 0.00522055 0.00687309 0.0195302 0.04101344
0.00816675 0.0206033 0.04046513 0.02189863 0.06777772 0.04832356
0.00114855 0.08660891 0.00586355 0.00625051 0.00939407 0.00108471
0.03948301 0.02527621 0.03205795 0.11042239 0.02594314 0.05176711
0.03396658 0.00889475 0.02632742 0.02502325 0.01266999 0.00455966
0.03853313 0.01543076 0.00617221 0.00552462 0.01573062 0.01035006
0.00162921 0.00974758 0.00812487 0.01881237 0.06690071 0.01499192
0.04652794 0.04061345 0.04495752 0.00566707 0.01006984 0.00519717
0.00151416 0.03214829 0.00891702 0.01844822]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[8.90304177e-02 3.21655059e-02 1.15924557e-02 1.83823317e-02
8.19559737e-03 1.66018725e-02 1.79135536e-03 1.03313259e-01
7.69182892e-04 1.29306584e-02 1.21565007e-02 2.83463634e-03
3.03538673e-02 2.37415625e-02 1.56790195e-02 9.03400724e-03
1.35613536e-02 5.35506347e-02 1.01123792e-02 4.10604579e-02
2.63898112e-02 1.94766419e-02 3.81425129e-02 3.27482829e-02
5.12829994e-03 6.02901273e-03 8.26321660e-02 4.04504728e-02
2.20601797e-02 4.62113349e-03 9.03476611e-04 4.87494456e-02
3.82060913e-03 2.53729411e-02 2.38612299e-02 1.59355752e-02
3.60160003e-03 1.65738717e-02 2.98947674e-02 5.18501900e-03
9.36303682e-03 4.81218742e-02 1.49392067e-02 4.88551766e-03
2.17643975e-02 2.20608548e-04 1.90135464e-02 2.74291603e-02
1.23344210e-02 6.03309191e-03 1.57252451e-02 9.02612988e-03
3.32084559e-02 3.76692036e-03 2.87169607e-02 4.85551266e-02
1.48826894e-02 6.41842093e-04 1.89017198e-02 3.49584063e-02
1.77652198e-02 6.38298234e-03 1.05034088e-03 1.99753321e-02
5.52031552e-03 8.22217237e-03 6.86192682e-02 8.40354798e-03
1.29491144e-02 7.44658658e-03 1.00731392e-02 9.52284329e-02
1.51437058e-02 2.00002585e-05 2.37700967e-02 1.95166920e-02
4.82376174e-02 3.73986200e-02 4.84707251e-02 8.76887316e-02
2.74724414e-02 5.14825560e-03 1.26254957e-02 2.81042619e-02
2.11265643e-02 2.52301447e-03 3.13819592e-02 2.93900569e-02
3.65720152e-02 1.02850506e-02 4.85945208e-02 2.79870689e-02
3.12846660e-02 6.17869861e-02 9.09590269e-03 1.11715109e-02
3.62863106e-02 1.21277816e-02 9.05665429e-03 4.85293303e-02]
</pre></div>
</div>
</div>
@@ -1758,15 +1776,15 @@ but now splitting the data into a training set and a test set.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 1.97243946 0.15593478 4.54011398 0.56342158 -0.19299283]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 2.05054319 -0.48521055 6.95338273 -2.63619709 1.0524497 ]
Training R2
0.9948998579029953
0.9959308805732706
Training MSE
0.009396472959497925
0.009211602191395454
Test R2
0.9951059931014423
0.9955318336036834
Test MSE
0.010612904886352397
0.011818646101922625
</pre></div>
</div>
</div>
@@ -2430,7 +2448,9 @@ the aims is to reproduce Figure 2.11 of <a class="reference external" href="http
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>MSE before scaling: 0.00
R2 score before scaling 1.00
Feature min values before scaling:
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Feature min values before scaling:
[1.00000000e+00 6.97906022e-03 2.43639284e-03 4.87072815e-05
1.70037324e-05 5.93601008e-06 3.39931051e-07 1.18670072e-07
4.14277718e-08 1.44624525e-08 2.37239927e-09 8.28205578e-10
+10
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
+29 -18
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -1629,7 +1639,7 @@ theorem.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Bootstrap Statistics :
original bias std. error
99.8244 15.0449 99.8227 0.150527
99.8485 15.0562 99.8488 0.149353
</pre></div>
</div>
</div>
@@ -1849,7 +1859,9 @@ Error: 0.08426840630693411
Bias^2: 0.0796891867672603
Var: 0.004579219539673834
0.08426840630693411 &gt;= 0.0796891867672603 + 0.004579219539673834 = 0.08426840630693413
Polynomial degree: 2
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 2
Error: 0.10398646080125035
Bias^2: 0.1007711427354898
Var: 0.0032153180657605116
@@ -1864,14 +1876,14 @@ Error: 0.06844519414009445
Bias^2: 0.06453579006728324
Var: 0.003909404072811226
0.06844519414009445 &gt;= 0.06453579006728324 + 0.003909404072811226 = 0.06844519414009446
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 5
Polynomial degree: 5
Error: 0.05227921801205686
Bias^2: 0.0481872773043029
Var: 0.004091940707753939
0.05227921801205686 &gt;= 0.0481872773043029 + 0.004091940707753939 = 0.052279218012056844
Polynomial degree: 6
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 6
Error: 0.037813671417389005
Bias^2: 0.033657685071527665
Var: 0.00415598634586135
@@ -1881,7 +1893,9 @@ Error: 0.02760977349102253
Bias^2: 0.022999498260366312
Var: 0.004610275230656212
0.02760977349102253 &gt;= 0.022999498260366312 + 0.004610275230656212 = 0.027609773491022525
Polynomial degree: 8
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 8
Error: 0.017355848195593347
Bias^2: 0.010331721306655127
Var: 0.007024126888938232
@@ -1896,17 +1910,14 @@ Error: 0.021592704588025025
Bias^2: 0.010516485576645508
Var: 0.011076219011379514
0.021592704588025025 &gt;= 0.010516485576645508 + 0.011076219011379514 = 0.021592704588025022
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree:
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 11
Polynomial degree: 11
Error: 0.07160048164233104
Bias^2: 0.014436800088904942
Var: 0.05716368155342608
0.07160048164233104 &gt;= 0.014436800088904942 + 0.05716368155342608 = 0.07160048164233102
Polynomial degree: 12
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Polynomial degree: 12
Error: 0.11547777218872497
Bias^2: 0.01628578269596628
Var: 0.09919198949275869
@@ -1918,7 +1929,7 @@ Var: 0.20867052175034223
0.22842468702219465 &gt;= 0.01975416527185249 + 0.20867052175034223 = 0.2284246870221947
</pre></div>
</div>
<img alt="_images/week37_139_4.png" src="_images/week37_139_4.png" />
<img alt="_images/week37_139_5.png" src="_images/week37_139_5.png" />
</div>
</div>
</div>
@@ -2349,9 +2360,9 @@ Mean squared error on training data: 0.00063866
Mean squared error on test data: 3099.60342978
</pre></div>
</div>
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58862/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95542/626635268.py:73: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(trainingerror), label=&#39;Training Error&#39;)
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58862/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95542/626635268.py:74: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(testerror), label=&#39;Test Error&#39;)
</pre></div>
</div>
@@ -2436,7 +2447,7 @@ Mean squared error on test data: 3099.60342978
</div>
</div>
<div class="cell_output docutils container">
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58862/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95542/3817475779.py:63: RuntimeWarning: divide by zero encountered in log10
plt.plot(polynomial, np.log10(estimated_mse_sklearn), label=&#39;Test Error&#39;)
</pre></div>
</div>
+13 -3
View File
@@ -55,7 +55,7 @@ const thebe_selector_output = ".output, .cell_output"
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Project 1 on Machine Learning, deadline October 7 (midnight), 2024" href="project1.html" />
<link rel="next" title="Exercises week 39" href="exercisesweek39.html" />
<link rel="prev" title="Exercises week 38" href="exercisesweek38.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -2691,10 +2701,10 @@ cross-validation (LOOCV).</p>
<p class="prev-next-title">Exercises week 38</p>
</div>
</a>
<a class='right-next' id="next-link" href="project1.html" title="next page">
<a class='right-next' id="next-link" href="exercisesweek39.html" title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Project 1 on Machine Learning, deadline October 7 (midnight), 2024</p>
<p class="prev-next-title">Exercises week 39</p>
</div>
<i class="fas fa-angle-right"></i>
</a>
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2981,22 +2981,16 @@
"Cell \u001b[0;32mIn[9], line 143\u001b[0m\n\u001b[1;32m 140\u001b[0m num_iter \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m250\u001b[39m\n\u001b[1;32m 141\u001b[0m lmb \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0.01\u001b[39m\n\u001b[0;32m--> 143\u001b[0m P \u001b[38;5;241m=\u001b[39m \u001b[43msolve_pde_deep_neural_network\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43mt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum_hidden_neurons\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnum_iter\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlmb\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 145\u001b[0m \u001b[38;5;66;03m## Store the results\u001b[39;00m\n\u001b[1;32m 146\u001b[0m g_dnn_ag \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mzeros((Nx, Nt))\n",
"Cell \u001b[0;32mIn[9], line 120\u001b[0m, in \u001b[0;36msolve_pde_deep_neural_network\u001b[0;34m(x, t, num_neurons, num_iter, lmb)\u001b[0m\n\u001b[1;32m 118\u001b[0m \u001b[38;5;66;03m# Let the update be done num_iter times\u001b[39;00m\n\u001b[1;32m 119\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(num_iter):\n\u001b[0;32m--> 120\u001b[0m cost_grad \u001b[38;5;241m=\u001b[39m \u001b[43mcost_function_grad\u001b[49m\u001b[43m(\u001b[49m\u001b[43mP\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m \u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 122\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m l \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(N_hidden\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m):\n\u001b[1;32m 123\u001b[0m P[l] \u001b[38;5;241m=\u001b[39m P[l] \u001b[38;5;241m-\u001b[39m lmb \u001b[38;5;241m*\u001b[39m cost_grad[l]\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20\u001b[0m, in \u001b[0;36munary_to_nary.<locals>.nary_operator.<locals>.nary_f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 19\u001b[0m x \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(args[i] \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m argnum)\n\u001b[0;32m---> 20\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43munary_operator\u001b[49m\u001b[43m(\u001b[49m\u001b[43munary_f\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mnary_op_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mnary_op_kwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:28\u001b[0m, in \u001b[0;36mgrad\u001b[0;34m(fun, x)\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[38;5;129m@unary_to_nary\u001b[39m\n\u001b[1;32m 22\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgrad\u001b[39m(fun, x):\n\u001b[1;32m 23\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;124;03m Returns a function which computes the gradient of `fun` with respect to\u001b[39;00m\n\u001b[1;32m 25\u001b[0m \u001b[38;5;124;03m positional argument number `argnum`. The returned function takes the same\u001b[39;00m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;124;03m arguments as `fun`, but returns the gradient instead. The function `fun`\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \u001b[38;5;124;03m should be scalar-valued. The gradient has the same type as the argument.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 28\u001b[0m vjp, ans \u001b[38;5;241m=\u001b[39m \u001b[43m_make_vjp\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfun\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 29\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m vspace(ans)\u001b[38;5;241m.\u001b[39msize \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 30\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGrad only applies to real scalar-output functions. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 31\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTry jacobian, elementwise_grad or holomorphic_grad.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:10\u001b[0m, in \u001b[0;36mmake_vjp\u001b[0;34m(fun, x)\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmake_vjp\u001b[39m(fun, x):\n\u001b[1;32m 9\u001b[0m start_node \u001b[38;5;241m=\u001b[39m VJPNode\u001b[38;5;241m.\u001b[39mnew_root()\n\u001b[0;32m---> 10\u001b[0m end_value, end_node \u001b[38;5;241m=\u001b[39m \u001b[43mtrace\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart_node\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfun\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m end_node \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mvjp\u001b[39m(g): \u001b[38;5;28;01mreturn\u001b[39;00m vspace(x)\u001b[38;5;241m.\u001b[39mzeros()\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py:10\u001b[0m, in \u001b[0;36mtrace\u001b[0;34m(start_node, fun, x)\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m trace_stack\u001b[38;5;241m.\u001b[39mnew_trace() \u001b[38;5;28;01mas\u001b[39;00m t:\n\u001b[1;32m 9\u001b[0m start_box \u001b[38;5;241m=\u001b[39m new_box(x, t, start_node)\n\u001b[0;32m---> 10\u001b[0m end_box \u001b[38;5;241m=\u001b[39m \u001b[43mfun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart_box\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m isbox(end_box) \u001b[38;5;129;01mand\u001b[39;00m end_box\u001b[38;5;241m.\u001b[39m_trace \u001b[38;5;241m==\u001b[39m start_box\u001b[38;5;241m.\u001b[39m_trace:\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m end_box\u001b[38;5;241m.\u001b[39m_value, end_box\u001b[38;5;241m.\u001b[39m_node\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:15\u001b[0m, in \u001b[0;36munary_to_nary.<locals>.nary_operator.<locals>.nary_f.<locals>.unary_f\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 14\u001b[0m subargs \u001b[38;5;241m=\u001b[39m subvals(args, \u001b[38;5;28mzip\u001b[39m(argnum, x))\n\u001b[0;32m---> 15\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43msubargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[0;32mIn[9], line 80\u001b[0m, in \u001b[0;36mcost_function\u001b[0;34m(P, x, t)\u001b[0m\n\u001b[1;32m 78\u001b[0m g_t \u001b[38;5;241m=\u001b[39m g_trial(point,P)\n\u001b[1;32m 79\u001b[0m g_t_jacobian \u001b[38;5;241m=\u001b[39m g_t_jacobian_func(point,P)\n\u001b[0;32m---> 80\u001b[0m g_t_hessian \u001b[38;5;241m=\u001b[39m \u001b[43mg_t_hessian_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpoint\u001b[49m\u001b[43m,\u001b[49m\u001b[43mP\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 82\u001b[0m g_t_dt \u001b[38;5;241m=\u001b[39m g_t_jacobian[\u001b[38;5;241m1\u001b[39m]\n\u001b[1;32m 83\u001b[0m g_t_d2x \u001b[38;5;241m=\u001b[39m g_t_hessian[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m]\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20\u001b[0m, in \u001b[0;36munary_to_nary.<locals>.nary_operator.<locals>.nary_f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 19\u001b[0m x \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(args[i] \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m argnum)\n\u001b[0;32m---> 20\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43munary_operator\u001b[49m\u001b[43m(\u001b[49m\u001b[43munary_f\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mnary_op_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mnary_op_kwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:81\u001b[0m, in \u001b[0;36mhessian\u001b[0;34m(fun, x)\u001b[0m\n\u001b[1;32m 78\u001b[0m \u001b[38;5;129m@unary_to_nary\u001b[39m\n\u001b[1;32m 79\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mhessian\u001b[39m(fun, x):\n\u001b[1;32m 80\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mReturns a function that computes the exact Hessian.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m---> 81\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mjacobian\u001b[49m\u001b[43m(\u001b[49m\u001b[43mjacobian\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfun\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py:20\u001b[0m, in \u001b[0;36munary_to_nary.<locals>.nary_operator.<locals>.nary_f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 19\u001b[0m x \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(args[i] \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m argnum)\n\u001b[0;32m---> 20\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43munary_operator\u001b[49m\u001b[43m(\u001b[49m\u001b[43munary_f\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mnary_op_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mnary_op_kwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:64\u001b[0m, in \u001b[0;36mjacobian\u001b[0;34m(fun, x)\u001b[0m\n\u001b[1;32m 62\u001b[0m jacobian_shape \u001b[38;5;241m=\u001b[39m ans_vspace\u001b[38;5;241m.\u001b[39mshape \u001b[38;5;241m+\u001b[39m vspace(x)\u001b[38;5;241m.\u001b[39mshape\n\u001b[1;32m 63\u001b[0m grads \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mmap\u001b[39m(vjp, ans_vspace\u001b[38;5;241m.\u001b[39mstandard_basis())\n\u001b[0;32m---> 64\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m np\u001b[38;5;241m.\u001b[39mreshape(\u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstack\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgrads\u001b[49m\u001b[43m)\u001b[49m, jacobian_shape)\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py:88\u001b[0m, in \u001b[0;36mstack\u001b[0;34m(arrays, axis)\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstack\u001b[39m(arrays, axis\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m):\n\u001b[1;32m 84\u001b[0m \u001b[38;5;66;03m# this code is basically copied from numpy/core/shape_base.py's stack\u001b[39;00m\n\u001b[1;32m 85\u001b[0m \u001b[38;5;66;03m# we need it here because we want to re-implement stack in terms of the\u001b[39;00m\n\u001b[1;32m 86\u001b[0m \u001b[38;5;66;03m# primitives defined in this file\u001b[39;00m\n\u001b[0;32m---> 88\u001b[0m arrays \u001b[38;5;241m=\u001b[39m [array(arr) \u001b[38;5;28;01mfor\u001b[39;00m arr \u001b[38;5;129;01min\u001b[39;00m arrays]\n\u001b[1;32m 89\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m arrays:\n\u001b[1;32m 90\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mneed at least one array to stack\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py:88\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstack\u001b[39m(arrays, axis\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m):\n\u001b[1;32m 84\u001b[0m \u001b[38;5;66;03m# this code is basically copied from numpy/core/shape_base.py's stack\u001b[39;00m\n\u001b[1;32m 85\u001b[0m \u001b[38;5;66;03m# we need it here because we want to re-implement stack in terms of the\u001b[39;00m\n\u001b[1;32m 86\u001b[0m \u001b[38;5;66;03m# primitives defined in this file\u001b[39;00m\n\u001b[0;32m---> 88\u001b[0m arrays \u001b[38;5;241m=\u001b[39m [array(arr) \u001b[38;5;28;01mfor\u001b[39;00m arr \u001b[38;5;129;01min\u001b[39;00m arrays]\n\u001b[1;32m 89\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m arrays:\n\u001b[1;32m 90\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mneed at least one array to stack\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py:32\u001b[0m, in \u001b[0;36mgrad\u001b[0;34m(fun, x)\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m vspace(ans)\u001b[38;5;241m.\u001b[39msize \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 30\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGrad only applies to real scalar-output functions. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 31\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTry jacobian, elementwise_grad or holomorphic_grad.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 32\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mvjp\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvspace\u001b[49m\u001b[43m(\u001b[49m\u001b[43mans\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mones\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:14\u001b[0m, in \u001b[0;36mmake_vjp.<locals>.vjp\u001b[0;34m(g)\u001b[0m\n\u001b[0;32m---> 14\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mvjp\u001b[39m(g): \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mbackward_pass\u001b[49m\u001b[43m(\u001b[49m\u001b[43mg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mend_node\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:21\u001b[0m, in \u001b[0;36mbackward_pass\u001b[0;34m(g, end_node)\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m node \u001b[38;5;129;01min\u001b[39;00m toposort(end_node):\n\u001b[1;32m 20\u001b[0m outgrad \u001b[38;5;241m=\u001b[39m outgrads\u001b[38;5;241m.\u001b[39mpop(node)\n\u001b[0;32m---> 21\u001b[0m ingrads \u001b[38;5;241m=\u001b[39m \u001b[43mnode\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvjp\u001b[49m\u001b[43m(\u001b[49m\u001b[43moutgrad\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 22\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m parent, ingrad \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(node\u001b[38;5;241m.\u001b[39mparents, ingrads):\n\u001b[1;32m 23\u001b[0m outgrads[parent] \u001b[38;5;241m=\u001b[39m add_outgrads(outgrads\u001b[38;5;241m.\u001b[39mget(parent), ingrad)\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py:67\u001b[0m, in \u001b[0;36mdefvjp.<locals>.vjp_argnums.<locals>.<lambda>\u001b[0;34m(g)\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mNotImplementedError\u001b[39;00m(\n\u001b[1;32m 65\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mVJP of \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m wrt argnum 0 not defined\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(fun\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m))\n\u001b[1;32m 66\u001b[0m vjp \u001b[38;5;241m=\u001b[39m vjpfun(ans, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m---> 67\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mlambda\u001b[39;00m g: (\u001b[43mvjp\u001b[49m\u001b[43m(\u001b[49m\u001b[43mg\u001b[49m\u001b[43m)\u001b[49m,)\n\u001b[1;32m 68\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m L \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2\u001b[39m:\n\u001b[1;32m 69\u001b[0m argnum_0, argnum_1 \u001b[38;5;241m=\u001b[39m argnums\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:660\u001b[0m, in \u001b[0;36munbroadcast_f.<locals>.<lambda>\u001b[0;34m(g)\u001b[0m\n\u001b[1;32m 658\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21munbroadcast_f\u001b[39m(target, f):\n\u001b[1;32m 659\u001b[0m target_meta \u001b[38;5;241m=\u001b[39m anp\u001b[38;5;241m.\u001b[39mmetadata(target)\n\u001b[0;32m--> 660\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mlambda\u001b[39;00m g: \u001b[43munbroadcast\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mg\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget_meta\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:651\u001b[0m, in \u001b[0;36munbroadcast\u001b[0;34m(x, target_meta, broadcast_idx)\u001b[0m\n\u001b[1;32m 649\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m anp\u001b[38;5;241m.\u001b[39mndim(x) \u001b[38;5;241m>\u001b[39m target_ndim:\n\u001b[1;32m 650\u001b[0m x \u001b[38;5;241m=\u001b[39m anp\u001b[38;5;241m.\u001b[39msum(x, axis\u001b[38;5;241m=\u001b[39mbroadcast_idx)\n\u001b[0;32m--> 651\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m axis, size \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28;43menumerate\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mtarget_shape\u001b[49m\u001b[43m)\u001b[49m:\n\u001b[1;32m 652\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m size \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 653\u001b[0m x \u001b[38;5;241m=\u001b[39m anp\u001b[38;5;241m.\u001b[39msum(x, axis\u001b[38;5;241m=\u001b[39maxis, keepdims\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py:653\u001b[0m, in \u001b[0;36munbroadcast\u001b[0;34m(x, target_meta, broadcast_idx)\u001b[0m\n\u001b[1;32m 651\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m axis, size \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(target_shape):\n\u001b[1;32m 652\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m size \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m--> 653\u001b[0m x \u001b[38;5;241m=\u001b[39m \u001b[43manp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msum\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43maxis\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkeepdims\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 654\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m anp\u001b[38;5;241m.\u001b[39miscomplexobj(x) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m target_iscomplex:\n\u001b[1;32m 655\u001b[0m x \u001b[38;5;241m=\u001b[39m anp\u001b[38;5;241m.\u001b[39mreal(x)\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py:48\u001b[0m, in \u001b[0;36mprimitive.<locals>.f_wrapped\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m new_box(ans, trace, node)\n\u001b[1;32m 47\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 48\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf_raw\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m<__array_function__ internals>:180\u001b[0m, in \u001b[0;36msum\u001b[0;34m(*args, **kwargs)\u001b[0m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:2296\u001b[0m, in \u001b[0;36msum\u001b[0;34m(a, axis, dtype, out, keepdims, initial, where)\u001b[0m\n\u001b[1;32m 2293\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m out\n\u001b[1;32m 2294\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m res\n\u001b[0;32m-> 2296\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_wrapreduction\u001b[49m\u001b[43m(\u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msum\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkeepdims\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkeepdims\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 2297\u001b[0m \u001b[43m \u001b[49m\u001b[43minitial\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minitial\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mwhere\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mwhere\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:86\u001b[0m, in \u001b[0;36m_wrapreduction\u001b[0;34m(obj, ufunc, method, axis, dtype, out, **kwargs)\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m reduction(axis\u001b[38;5;241m=\u001b[39maxis, out\u001b[38;5;241m=\u001b[39mout, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mpasskwargs)\n\u001b[0;32m---> 86\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mufunc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreduce\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mpasskwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

@@ -1798,10 +1798,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"-0.07978850553011713\n",
"3.8232102961414203\n",
"[[ 1.25705685 3.70704566]\n",
" [ 3.70704566 12.1664372 ]]\n"
"-0.024792624800382218\n",
"3.9225384545636204\n",
"[[0.94623184 2.84401886]\n",
" [2.84401886 9.4477214 ]]\n"
]
}
],
@@ -1845,10 +1845,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.08931169286872433\n",
"2.047447724189861\n",
"[[1. 0.66729685]\n",
" [0.66729685 1. ]]\n"
"0.08536248571780691\n",
"1.8207274870895702\n",
"[[1. 0.74900488]\n",
" [0.74900488 1. ]]\n"
]
}
],
@@ -1905,30 +1905,36 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 2.37582891 5.4242743 ]\n",
" [-0.81925302 -3.60052901]\n",
" [ 0.37467515 3.16158074]\n",
" [-0.40478305 -2.22601408]\n",
" [-0.0776532 -1.70594608]\n",
" [-0.99434472 -2.2026985 ]\n",
" [ 0.71376303 2.77725472]\n",
" [ 0.94637206 2.69303453]\n",
" [-0.19791352 0.93366198]\n",
" [-1.91669165 -5.2546186 ]]\n",
"[[ 1.10115017 1.66431407]\n",
" [ 0.12043521 1.32305911]\n",
" [-1.30023144 -3.36154104]\n",
" [-0.25200841 -1.11277166]\n",
" [-1.55102329 -4.20158083]\n",
" [ 0.72770687 0.97206657]\n",
" [ 0.76533281 2.10747579]\n",
" [-0.20666447 0.79623487]\n",
" [-0.63919355 -2.48490503]\n",
" [ 1.23449607 4.29764815]]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0 1\n",
"0 2.375829 5.424274\n",
"1 -0.819253 -3.600529\n",
"2 0.374675 3.161581\n",
"3 -0.404783 -2.226014\n",
"4 -0.077653 -1.705946\n",
"5 -0.994345 -2.202698\n",
"6 0.713763 2.777255\n",
"7 0.946372 2.693035\n",
"8 -0.197914 0.933662\n",
"9 -1.916692 -5.254619\n",
" 0 1\n",
"0 1.000000 0.932382\n",
"1 0.932382 1.000000\n"
"0 1.101150 1.664314\n",
"1 0.120435 1.323059\n",
"2 -1.300231 -3.361541\n",
"3 -0.252008 -1.112772\n",
"4 -1.551023 -4.201581\n",
"5 0.727707 0.972067\n",
"6 0.765333 2.107476\n",
"7 -0.206664 0.796235\n",
"8 -0.639194 -2.484905\n",
"9 1.234496 4.297648\n",
" 0 1\n",
"0 1.0000 0.9434\n",
"1 0.9434 1.0000\n"
]
}
],
@@ -1974,37 +1980,37 @@
"text": [
" 0 1 2 3 4 5 6 7 \\\n",
"0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"1 0.0 0.080947 0.086913 0.082764 0.085436 0.088029 0.075956 0.077683 \n",
"2 0.0 0.086913 0.094044 0.088199 0.091365 0.094439 0.080171 0.082174 \n",
"3 0.0 0.082764 0.088199 0.090624 0.093094 0.095465 0.086730 0.088375 \n",
"4 0.0 0.085436 0.091365 0.093094 0.095805 0.098414 0.088651 0.090440 \n",
"5 0.0 0.088029 0.094439 0.095465 0.098414 0.101263 0.090468 0.092401 \n",
"6 0.0 0.075956 0.080171 0.086730 0.088651 0.090468 0.085390 0.086712 \n",
"7 0.0 0.077683 0.082174 0.088375 0.090440 0.092401 0.086712 0.088127 \n",
"8 0.0 0.079444 0.084218 0.090038 0.092252 0.094362 0.088038 0.089548 \n",
"9 0.0 0.081252 0.086318 0.091731 0.094099 0.096365 0.089376 0.090985 \n",
"10 0.0 0.068684 0.071868 0.080702 0.082126 0.083446 0.081103 0.082115 \n",
"11 0.0 0.069978 0.073339 0.081978 0.083499 0.084915 0.082170 0.083248 \n",
"12 0.0 0.071314 0.074859 0.083288 0.084910 0.086428 0.083260 0.084406 \n",
"13 0.0 0.072697 0.076435 0.084637 0.086364 0.087988 0.084376 0.085592 \n",
"14 0.0 0.074130 0.078071 0.086026 0.087864 0.089600 0.085518 0.086809 \n",
"1 0.0 0.083179 0.086483 0.081217 0.083548 0.086239 0.072037 0.073514 \n",
"2 0.0 0.086483 0.091362 0.082533 0.085853 0.089626 0.071638 0.073800 \n",
"3 0.0 0.081217 0.082533 0.084963 0.086068 0.087429 0.079030 0.079670 \n",
"4 0.0 0.083548 0.085853 0.086068 0.087871 0.089996 0.078945 0.080094 \n",
"5 0.0 0.086239 0.089626 0.087429 0.089996 0.092956 0.079002 0.080706 \n",
"6 0.0 0.072037 0.071638 0.079030 0.078945 0.079002 0.076071 0.075876 \n",
"7 0.0 0.073514 0.073800 0.079670 0.080094 0.080706 0.075876 0.076066 \n",
"8 0.0 0.075289 0.076321 0.080549 0.081527 0.082742 0.075842 0.076448 \n",
"9 0.0 0.077391 0.079240 0.081686 0.083268 0.085145 0.075978 0.077035 \n",
"10 0.0 0.063786 0.062216 0.072380 0.071437 0.070552 0.071436 0.070622 \n",
"11 0.0 0.064606 0.063536 0.072591 0.072031 0.071560 0.071049 0.070531 \n",
"12 0.0 0.065654 0.065121 0.072997 0.072849 0.072826 0.070805 0.070605 \n",
"13 0.0 0.066948 0.067000 0.073612 0.073911 0.074374 0.070712 0.070855 \n",
"14 0.0 0.068512 0.069203 0.074454 0.075239 0.076232 0.070780 0.071294 \n",
"\n",
" 8 9 10 11 12 13 14 \n",
"0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"1 0.079444 0.081252 0.068684 0.069978 0.071314 0.072697 0.074130 \n",
"2 0.084218 0.086318 0.071868 0.073339 0.074859 0.076435 0.078071 \n",
"3 0.090038 0.091731 0.080702 0.081978 0.083288 0.084637 0.086026 \n",
"4 0.092252 0.094099 0.082126 0.083499 0.084910 0.086364 0.087864 \n",
"5 0.094362 0.096365 0.083446 0.084915 0.086428 0.087988 0.089600 \n",
"6 0.088038 0.089376 0.081103 0.082170 0.083260 0.084376 0.085518 \n",
"7 0.089548 0.090985 0.082115 0.083248 0.084406 0.085592 0.086809 \n",
"8 0.091068 0.092607 0.083119 0.084319 0.085548 0.086808 0.088102 \n",
"9 0.092607 0.094254 0.084122 0.085392 0.086694 0.088030 0.089404 \n",
"10 0.083119 0.084122 0.078238 0.079089 0.079953 0.080832 0.081728 \n",
"11 0.084319 0.085392 0.079089 0.079989 0.080903 0.081835 0.082785 \n",
"12 0.085548 0.086694 0.079953 0.080903 0.081871 0.082857 0.083864 \n",
"13 0.086808 0.088030 0.080832 0.081835 0.082857 0.083900 0.084967 \n",
"14 0.088102 0.089404 0.081728 0.082785 0.083864 0.084967 0.086096 \n"
"1 0.075289 0.077391 0.063786 0.064606 0.065654 0.066948 0.068512 \n",
"2 0.076321 0.079240 0.062216 0.063536 0.065121 0.067000 0.069203 \n",
"3 0.080549 0.081686 0.072380 0.072591 0.072997 0.073612 0.074454 \n",
"4 0.081527 0.083268 0.071437 0.072031 0.072849 0.073911 0.075239 \n",
"5 0.082742 0.085145 0.070552 0.071560 0.072826 0.074374 0.076232 \n",
"6 0.075842 0.075978 0.071436 0.071049 0.070805 0.070712 0.070780 \n",
"7 0.076448 0.077035 0.070622 0.070531 0.070605 0.070855 0.071294 \n",
"8 0.077280 0.078359 0.069907 0.070135 0.070552 0.071173 0.072015 \n",
"9 0.078359 0.079976 0.069293 0.069866 0.070655 0.071680 0.072961 \n",
"10 0.069907 0.069293 0.068353 0.067515 0.066778 0.066145 0.065619 \n",
"11 0.070135 0.069866 0.067515 0.066912 0.066425 0.066059 0.065821 \n",
"12 0.070552 0.070655 0.066778 0.066425 0.066205 0.066127 0.066199 \n",
"13 0.071173 0.071680 0.066145 0.066059 0.066127 0.066358 0.066766 \n",
"14 0.072015 0.072961 0.065619 0.065821 0.066199 0.066766 0.067539 \n"
]
}
],
File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 38 KiB

File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "12bcd5bb",
"metadata": {
"editable": true
},
"source": [
"<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)\n",
"doconce format html exercisesweek39.do.txt -->\n",
"<!-- dom:TITLE: Exercises week 39 -->"
]
},
{
"cell_type": "markdown",
"id": "cd59f741",
"metadata": {
"editable": true
},
"source": [
"# Exercises week 39\n",
"**September 23-27, 2024**\n",
"\n",
"Date: **Deadline is Friday September 27 at midnight**"
]
},
{
"cell_type": "markdown",
"id": "bdf13ce1",
"metadata": {
"editable": true
},
"source": [
"## Overarching aims of the exercises this week\n",
"\n",
"The aim of the exercises this week is to aid you in getting started\n",
"with writing the report. This will be discussed during the lab\n",
"sessions as well. \n",
"\n",
"A general guideline can be found at <https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/EvaluationGrading/EvaluationForm.md>.\n",
"\n",
"Similarly, an example of an earlier project can be found at <https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/ReportExample/ReportSample.pdf>\n",
"\n",
"Your task this week is to\n",
"1. Write an abstract for your project\n",
"\n",
"2. Write an introduction\n",
"\n",
"3. Include references\n",
"\n",
"A short feedback to the this exercise will be available before the project deadline. And you can reuse these elements in your final report."
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
@@ -225,8 +225,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[-0.29015871 0.69417174 -1.07998756 0.34332677 0.19547923 -1.09755017\n",
" 0.86197958 -0.15546887 0.14369927 1.96251859]\n"
"[ 0.69465386 1.75956617 -0.23303727 -0.53125507 1.34598722 -1.09928714\n",
" 1.37013105 0.79898903 -0.23663482 0.99427512]\n"
]
}
],
@@ -662,26 +662,26 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.08233627 0.43727575 0.01759442 0.01179415 0.34483937 0.32733949\n",
" 0.71332117 0.20347912 0.57521514 0.56042437]\n",
" [0.64909048 0.55179339 0.13847167 0.04224929 0.89540936 0.5142856\n",
" 0.85871255 0.75080943 0.34026086 0.50850373]\n",
" [0.03239393 0.87884833 0.41310208 0.82418008 0.01014331 0.24284399\n",
" 0.93668828 0.79247398 0.48062913 0.77803692]\n",
" [0.73068535 0.47910545 0.95715036 0.11844773 0.76686148 0.31453949\n",
" 0.6029291 0.5443909 0.29398019 0.96585824]\n",
" [0.0179826 0.51643579 0.53723188 0.03844073 0.25989189 0.20834188\n",
" 0.98619989 0.40833375 0.52876551 0.76612827]\n",
" [0.44830934 0.94099173 0.07123177 0.96305058 0.11596834 0.69756791\n",
" 0.60664448 0.89457785 0.86016288 0.33615742]\n",
" [0.35243372 0.77465911 0.37532078 0.38399622 0.20728198 0.1108407\n",
" 0.83020679 0.48170743 0.99003341 0.99956033]\n",
" [0.82832579 0.42553096 0.02355756 0.28542801 0.96894842 0.70711022\n",
" 0.8825782 0.04072235 0.24369936 0.79622905]\n",
" [0.60762863 0.21699817 0.20218457 0.63071772 0.02358547 0.62886648\n",
" 0.44286735 0.78745927 0.30982436 0.76277254]\n",
" [0.52173381 0.9495484 0.47433659 0.73203674 0.95226607 0.40072098\n",
" 0.35098705 0.46544987 0.66456459 0.25512598]]\n"
"[[0.81947005 0.93619369 0.37449168 0.91933003 0.76855921 0.41820116\n",
" 0.96853248 0.60375434 0.96015381 0.30269539]\n",
" [0.46086448 0.16777789 0.9930742 0.10837392 0.69089532 0.94221383\n",
" 0.53629564 0.50327198 0.33734605 0.04757138]\n",
" [0.51069279 0.12363332 0.79171202 0.16791183 0.62617788 0.9288904\n",
" 0.85112594 0.86519139 0.61192712 0.90842732]\n",
" [0.82551764 0.67524588 0.02175561 0.1118933 0.42575338 0.45731379\n",
" 0.61069681 0.40184681 0.18702469 0.71838601]\n",
" [0.68655456 0.11747908 0.28253033 0.4591127 0.68072161 0.59372982\n",
" 0.95343966 0.24780663 0.98740373 0.06808421]\n",
" [0.99512017 0.14828178 0.02354386 0.90860768 0.891715 0.39039235\n",
" 0.48151166 0.43563433 0.52657934 0.73176319]\n",
" [0.77030637 0.00676256 0.37454707 0.5076963 0.51937727 0.46065811\n",
" 0.65917558 0.72962885 0.99370678 0.92341148]\n",
" [0.16292908 0.17214545 0.44995924 0.20367355 0.64885265 0.34225662\n",
" 0.4215795 0.27933134 0.02552966 0.62908496]\n",
" [0.8084934 0.51364117 0.4937346 0.05296475 0.69247718 0.56783103\n",
" 0.85276538 0.52635761 0.96461948 0.67374815]\n",
" [0.02137508 0.03177331 0.78186404 0.33096549 0.8423144 0.07745579\n",
" 0.4619526 0.61414743 0.38460453 0.51928402]]\n"
]
}
],
@@ -800,13 +800,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"-0.0018310257999764163\n",
"4.092608577084595\n",
"0.31555734196707536\n",
"[[ 0.78671736 2.38337498 2.04657426]\n",
" [ 2.38337498 8.33235647 6.05002471]\n",
" [ 2.04657426 6.05002471 10.13152828]]\n",
"[15.98413606 0.08227668 3.18418938]\n"
"0.07218473624441492\n",
"4.346000154268618\n",
"0.09048717285916912\n",
"[[ 1.0974119 3.2131067 3.36880327]\n",
" [ 3.2131067 10.51564682 9.75138064]\n",
" [ 3.36880327 9.75138064 17.26527089]]\n",
"[25.09487358 0.09070064 3.6927554 ]\n"
]
}
],
File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 18 KiB

@@ -874,8 +874,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[-1.24454968 1.12382443 0.67088558 1.12498355 1.0342028 -0.44563226\n",
" 0.14599499 0.07378525 0.03479236 -1.2976637 ]\n"
"[-0.60588173 1.59884169 -1.56922102 -1.32068736 -0.21631786 0.37600869\n",
" -0.14841322 -0.83655756 0.88809826 -0.85625134]\n"
]
}
],
@@ -1313,26 +1313,26 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.50306335 0.66487438 0.75677341 0.01349244 0.2813829 0.80056922\n",
" 0.07974741 0.63046054 0.05098714 0.26479234]\n",
" [0.17861414 0.3388112 0.30005983 0.35520169 0.5399913 0.51709529\n",
" 0.36339156 0.71582784 0.34568909 0.23164401]\n",
" [0.11922031 0.771128 0.20051449 0.07890044 0.96866031 0.34346829\n",
" 0.5116375 0.52732966 0.80637385 0.69435454]\n",
" [0.94291287 0.29238145 0.84711297 0.22849742 0.56967917 0.1636508\n",
" 0.15833751 0.84254917 0.05068486 0.54057582]\n",
" [0.17856374 0.71524686 0.66498292 0.00256622 0.72427854 0.50667812\n",
" 0.0894015 0.22688898 0.54873252 0.31727523]\n",
" [0.73578772 0.81479491 0.45620975 0.2662452 0.47757553 0.64322974\n",
" 0.54921401 0.70630967 0.51136852 0.59683811]\n",
" [0.37837864 0.71860732 0.35320952 0.67495943 0.16188604 0.41925189\n",
" 0.28956161 0.06685171 0.75654448 0.28923 ]\n",
" [0.91099021 0.8387133 0.18277213 0.40418675 0.7249499 0.46415522\n",
" 0.35018806 0.87148597 0.94141801 0.50911289]\n",
" [0.86066395 0.12235593 0.82418352 0.57881465 0.82559478 0.96826039\n",
" 0.291056 0.41675053 0.06430789 0.96432396]\n",
" [0.91270333 0.64362404 0.18816387 0.81318307 0.47989224 0.20375464\n",
" 0.33145794 0.92192012 0.33596404 0.18085537]]\n"
"[[0.32641434 0.35731585 0.64796751 0.41146753 0.67561021 0.53312817\n",
" 0.3910042 0.88157423 0.4576811 0.48004784]\n",
" [0.70469324 0.28496213 0.84862355 0.6988905 0.95890587 0.19849513\n",
" 0.89058005 0.51546825 0.88289263 0.06926192]\n",
" [0.38198866 0.33000573 0.80740939 0.54935794 0.38934047 0.87740526\n",
" 0.45053025 0.27231287 0.7070883 0.7989356 ]\n",
" [0.4198932 0.3727791 0.95400323 0.86459987 0.2666905 0.13564988\n",
" 0.97498674 0.9450635 0.6383903 0.57803254]\n",
" [0.13896095 0.13663125 0.68826552 0.13729154 0.91672129 0.08266769\n",
" 0.88639567 0.16407038 0.36353321 0.81007381]\n",
" [0.31849289 0.68735473 0.1767857 0.42873361 0.44454123 0.21333766\n",
" 0.94285762 0.72710494 0.37153115 0.21070843]\n",
" [0.11930916 0.28021598 0.69566966 0.98770503 0.88653291 0.82161167\n",
" 0.90114639 0.7127128 0.97486336 0.26152075]\n",
" [0.55386681 0.37919989 0.57468142 0.35980374 0.7150195 0.70499955\n",
" 0.9647801 0.63142399 0.97512176 0.97570392]\n",
" [0.24613581 0.62573269 0.41487642 0.42095725 0.51447004 0.41869784\n",
" 0.34483955 0.55582742 0.85711016 0.17739525]\n",
" [0.89533642 0.03382942 0.918785 0.79718864 0.64361375 0.4843772\n",
" 0.33532886 0.13164176 0.63209435 0.39279291]]\n"
]
}
],
@@ -1446,13 +1446,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.1385510301651882\n",
"4.344176915013831\n",
"0.13134148011170077\n",
"[[ 0.87981676 2.52698542 2.65591748]\n",
" [ 2.52698542 8.29861395 7.76790092]\n",
" [ 2.65591748 7.76790092 13.4831139 ]]\n",
"[19.77845284 0.09028702 2.79280475]\n"
"-0.050315327923114654\n",
"3.7539148284817965\n",
"-0.09246293455466892\n",
"[[ 0.90894281 2.8691787 2.58589719]\n",
" [ 2.8691787 10.23481471 8.16535252]\n",
" [ 2.58589719 8.16535252 12.44536331]]\n",
"[20.33742926 0.08458591 3.16710567]\n"
]
}
],
@@ -1808,7 +1808,7 @@
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_58840/1326197715.py\u001b[0m in \u001b[0;36m?\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m new_hobbit = {'First Name': [\"Peregrin\"],\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m'Last Name'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\"Took\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m'Place of birth'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\"Shire\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m'Date of Birth T.A.'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m2990\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_95519/1326197715.py\u001b[0m in \u001b[0;36m?\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m new_hobbit = {'First Name': [\"Peregrin\"],\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m'Last Name'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\"Took\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m'Place of birth'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\"Shire\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m'Date of Birth T.A.'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m2990\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/miniforge3/envs/myenv/lib/python3.9/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m?\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 6200\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mname\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_accessors\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6201\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6202\u001b[0m ):\n\u001b[1;32m 6203\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 6204\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'append'"
]
@@ -1533,7 +1533,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.9969513794144311\n"
"0.9952505213910134\n"
]
}
],
@@ -1564,7 +1564,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.007658477904313023\n"
"0.008753288788081405\n"
]
}
],
@@ -1599,23 +1599,31 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[0.00053122 0.03115122 0.00789262 0.02218076 0.00573727 0.00557893\n",
" 0.00099778 0.01234 0.03960002 0.03596557 0.0134113 0.00556946\n",
" 0.00136125 0.10719554 0.02754248 0.01409478 0.01760144 0.01032533\n",
" 0.01241284 0.01039879 0.00100913 0.02944152 0.00512599 0.00747773\n",
" 0.06260611 0.0231353 0.01624447 0.02923006 0.0046544 0.07332248\n",
" 0.02338085 0.02920675 0.02286267 0.04353549 0.00569512 0.02664408\n",
" 0.01098247 0.02156565 0.03529801 0.00507531 0.00554202 0.05141614\n",
" 0.02031987 0.01244297 0.01551724 0.00174738 0.01044475 0.01161645\n",
" 0.02622039 0.03285784 0.00522055 0.00687309 0.0195302 0.04101344\n",
" 0.00816675 0.0206033 0.04046513 0.02189863 0.06777772 0.04832356\n",
" 0.00114855 0.08660891 0.00586355 0.00625051 0.00939407 0.00108471\n",
" 0.03948301 0.02527621 0.03205795 0.11042239 0.02594314 0.05176711\n",
" 0.03396658 0.00889475 0.02632742 0.02502325 0.01266999 0.00455966\n",
" 0.03853313 0.01543076 0.00617221 0.00552462 0.01573062 0.01035006\n",
" 0.00162921 0.00974758 0.00812487 0.01881237 0.06690071 0.01499192\n",
" 0.04652794 0.04061345 0.04495752 0.00566707 0.01006984 0.00519717\n",
" 0.00151416 0.03214829 0.00891702 0.01844822]\n"
"[8.90304177e-02 3.21655059e-02 1.15924557e-02 1.83823317e-02\n",
" 8.19559737e-03 1.66018725e-02 1.79135536e-03 1.03313259e-01\n",
" 7.69182892e-04 1.29306584e-02 1.21565007e-02 2.83463634e-03\n",
" 3.03538673e-02 2.37415625e-02 1.56790195e-02 9.03400724e-03\n",
" 1.35613536e-02 5.35506347e-02 1.01123792e-02 4.10604579e-02\n",
" 2.63898112e-02 1.94766419e-02 3.81425129e-02 3.27482829e-02\n",
" 5.12829994e-03 6.02901273e-03 8.26321660e-02 4.04504728e-02\n",
" 2.20601797e-02 4.62113349e-03 9.03476611e-04 4.87494456e-02\n",
" 3.82060913e-03 2.53729411e-02 2.38612299e-02 1.59355752e-02\n",
" 3.60160003e-03 1.65738717e-02 2.98947674e-02 5.18501900e-03\n",
" 9.36303682e-03 4.81218742e-02 1.49392067e-02 4.88551766e-03\n",
" 2.17643975e-02 2.20608548e-04 1.90135464e-02 2.74291603e-02\n",
" 1.23344210e-02 6.03309191e-03 1.57252451e-02 9.02612988e-03\n",
" 3.32084559e-02 3.76692036e-03 2.87169607e-02 4.85551266e-02\n",
" 1.48826894e-02 6.41842093e-04 1.89017198e-02 3.49584063e-02\n",
" 1.77652198e-02 6.38298234e-03 1.05034088e-03 1.99753321e-02\n",
" 5.52031552e-03 8.22217237e-03 6.86192682e-02 8.40354798e-03\n",
" 1.29491144e-02 7.44658658e-03 1.00731392e-02 9.52284329e-02\n",
" 1.51437058e-02 2.00002585e-05 2.37700967e-02 1.95166920e-02\n",
" 4.82376174e-02 3.73986200e-02 4.84707251e-02 8.76887316e-02\n",
" 2.74724414e-02 5.14825560e-03 1.26254957e-02 2.81042619e-02\n",
" 2.11265643e-02 2.52301447e-03 3.13819592e-02 2.93900569e-02\n",
" 3.65720152e-02 1.02850506e-02 4.85945208e-02 2.79870689e-02\n",
" 3.12846660e-02 6.17869861e-02 9.09590269e-03 1.11715109e-02\n",
" 3.62863106e-02 1.21277816e-02 9.05665429e-03 4.85293303e-02]\n"
]
}
],
@@ -1669,15 +1677,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[ 1.97243946 0.15593478 4.54011398 0.56342158 -0.19299283]\n",
"[ 2.05054319 -0.48521055 6.95338273 -2.63619709 1.0524497 ]\n",
"Training R2\n",
"0.9948998579029953\n",
"0.9959308805732706\n",
"Training MSE\n",
"0.009396472959497925\n",
"0.009211602191395454\n",
"Test R2\n",
"0.9951059931014423\n",
"0.9955318336036834\n",
"Test MSE\n",
"0.010612904886352397\n"
"0.011818646101922625\n"
]
}
],
@@ -2549,7 +2557,13 @@
"output_type": "stream",
"text": [
"MSE before scaling: 0.00\n",
"R2 score before scaling 1.00\n",
"R2 score before scaling 1.00\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Feature min values before scaling:\n",
" [1.00000000e+00 6.97906022e-03 2.43639284e-03 4.87072815e-05\n",
" 1.70037324e-05 5.93601008e-06 3.39931051e-07 1.18670072e-07\n",
File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More