update week 35

This commit is contained in:
Morten Hjorth-Jensen
2021-09-03 08:01:53 +02:00
parent a0c33afd42
commit ae5eef060d
7 changed files with 167 additions and 585 deletions
+1 -1
View File
@@ -374,7 +374,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Sep 2, 2021</h4></center> <!-- date -->
<center><h4>Sep 3, 2021</h4></center> <!-- date -->
<br>
<p>
+4 -4
View File
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>&nbsp;<br>
<center><h4>Sep 2, 2021</h4></center> <!-- date -->
<center><h4>Sep 3, 2021</h4></center> <!-- date -->
<br>
<p>
@@ -162,9 +162,9 @@ MathJax.Hub.Config({
<h2 id="plans-for-week-35-august-30-september-3">Plans for week 35, August 30 -September 3 </h2>
<ul>
<p><li> Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression</li>
<p><li> Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression and Singular Value Decomposition</li>
<p><li> <a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember2.mp4?vrtx=view-as-webpage" target="_blank">Video of lecture Thursday</a>.</li>
<p><li> Friday: Analysis of Ridge and Lasso Regression</li>
<p><li> Friday: Analysis of Ridge and Lasso Regression and links with Singular Value Decomposition</li>
</ul>
</section>
@@ -1972,7 +1972,7 @@ If you wish to include the zero singular values, you will need to resize the mat
<a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember11.mp4?vrtx=view-as-webpage" target="_blank">Video of Lecture from 2020</a> and <a href="https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember11.pdf" target="_blank">handwritten notes</a>
<p>
More material will be added here, see handwritten notes also.
More material will be added here, see handwritten notes also. Note that this material will be cleaned up after the lecture of Friday September 3. See the handwritten notes from Friday's lecture at <a href="https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021" target="_blank"><tt>https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021</tt></a>.
</section>
+4 -4
View File
@@ -300,7 +300,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Sep 2, 2021</h4></center> <!-- date -->
<center><h4>Sep 3, 2021</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -308,9 +308,9 @@ MathJax.Hub.Config({
<h2 id="plans-for-week-35-august-30-september-3">Plans for week 35, August 30 -September 3 </h2>
<ul>
<li> Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression</li>
<li> Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression and Singular Value Decomposition</li>
<li> <a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember2.mp4?vrtx=view-as-webpage" target="_blank">Video of lecture Thursday</a>.</li>
<li> Friday: Analysis of Ridge and Lasso Regression</li>
<li> Friday: Analysis of Ridge and Lasso Regression and links with Singular Value Decomposition</li>
</ul>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -2032,7 +2032,7 @@ If you wish to include the zero singular values, you will need to resize the mat
<a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember11.mp4?vrtx=view-as-webpage" target="_blank">Video of Lecture from 2020</a> and <a href="https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember11.pdf" target="_blank">handwritten notes</a>
<p>
More material will be added here, see handwritten notes also.
More material will be added here, see handwritten notes also. Note that this material will be cleaned up after the lecture of Friday September 3. See the handwritten notes from Friday's lecture at <a href="https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021" target="_blank"><tt>https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021</tt></a>.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
+4 -4
View File
@@ -305,7 +305,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>Sep 2, 2021</h4></center> <!-- date -->
<center><h4>Sep 3, 2021</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -313,9 +313,9 @@ MathJax.Hub.Config({
<h2 id="plans-for-week-35-august-30-september-3">Plans for week 35, August 30 -September 3 </h2>
<ul>
<li> Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression</li>
<li> Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression and Singular Value Decomposition</li>
<li> <a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember2.mp4?vrtx=view-as-webpage" target="_blank">Video of lecture Thursday</a>.</li>
<li> Friday: Analysis of Ridge and Lasso Regression</li>
<li> Friday: Analysis of Ridge and Lasso Regression and links with Singular Value Decomposition</li>
</ul>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -2037,7 +2037,7 @@ If you wish to include the zero singular values, you will need to resize the mat
<a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember11.mp4?vrtx=view-as-webpage" target="_blank">Video of Lecture from 2020</a> and <a href="https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember11.pdf" target="_blank">handwritten notes</a>
<p>
More material will be added here, see handwritten notes also.
More material will be added here, see handwritten notes also. Note that this material will be cleaned up after the lecture of Friday September 3. See the handwritten notes from Friday's lecture at <a href="https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021" target="_blank"><tt>https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021</tt></a>.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
Binary file not shown.
+151 -569
View File
@@ -10,7 +10,7 @@
"<!-- Author: --> \n",
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
"\n",
"Date: **Sep 2, 2021**\n",
"Date: **Sep 3, 2021**\n",
"\n",
"Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -19,11 +19,11 @@
"\n",
"## Plans for week 35, August 30 -September 3\n",
"\n",
"* Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression\n",
"* Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression and Singular Value Decomposition\n",
"\n",
"* [Video of lecture Thursday](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember2.mp4?vrtx=view-as-webpage).\n",
"\n",
"* Friday: Analysis of Ridge and Lasso Regression\n",
"* Friday: Analysis of Ridge and Lasso Regression and links with Singular Value Decomposition\n",
"\n",
"## Thursday September 2\n",
"\n",
@@ -400,7 +400,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
@@ -943,7 +946,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# matrix inversion to find beta\n",
@@ -962,7 +968,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"fit = np.linalg.lstsq(X, Energies, rcond =None)[0]\n",
@@ -979,7 +988,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"Masses['Eapprox'] = ytilde\n",
@@ -1009,7 +1021,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"def R2(y_data, y_model):\n",
@@ -1026,7 +1041,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"print(R2(Energies,ytilde))"
@@ -1042,7 +1060,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"def MSE(y_data,y_model):\n",
@@ -1062,7 +1083,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"def RelativeError(y_data,y_model):\n",
@@ -1097,7 +1121,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import os\n",
@@ -1150,7 +1177,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# equivalently in numpy\n",
@@ -1222,7 +1252,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import numpy as np\n",
@@ -1242,7 +1275,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"from sklearn.datasets import load_boston\n",
@@ -1264,7 +1300,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"boston = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)\n",
@@ -1282,7 +1321,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# check for missing values in all the columns\n",
@@ -1299,7 +1341,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# set the size of the figure\n",
@@ -1320,7 +1365,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# compute the pair wise correlation for all columns \n",
@@ -1340,7 +1388,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"plt.figure(figsize=(20, 5))\n",
@@ -1368,7 +1419,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"X = pd.DataFrame(np.c_[boston['LSTAT'], boston['RM']], columns = ['LSTAT','RM'])\n",
@@ -1385,7 +1439,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
@@ -1409,7 +1466,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"from sklearn.linear_model import LinearRegression\n",
@@ -1448,7 +1508,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# plotting the y_test vs y_pred\n",
@@ -1575,418 +1638,12 @@
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-1.749765</td>\n",
" <td>0.342680</td>\n",
" <td>1.153036</td>\n",
" <td>-0.252436</td>\n",
" <td>0.981321</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.514219</td>\n",
" <td>0.221180</td>\n",
" <td>-1.070043</td>\n",
" <td>-0.189496</td>\n",
" <td>0.255001</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>-0.458027</td>\n",
" <td>0.435163</td>\n",
" <td>-0.583595</td>\n",
" <td>0.816847</td>\n",
" <td>0.672721</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>-0.104411</td>\n",
" <td>-0.531280</td>\n",
" <td>1.029733</td>\n",
" <td>-0.438136</td>\n",
" <td>-1.118318</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.618982</td>\n",
" <td>1.541605</td>\n",
" <td>-0.251879</td>\n",
" <td>-0.842436</td>\n",
" <td>0.184519</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0.937082</td>\n",
" <td>0.731000</td>\n",
" <td>1.361556</td>\n",
" <td>-0.326238</td>\n",
" <td>0.055676</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0.222400</td>\n",
" <td>-1.443217</td>\n",
" <td>-0.756352</td>\n",
" <td>0.816454</td>\n",
" <td>0.750445</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>-0.455947</td>\n",
" <td>1.189622</td>\n",
" <td>-1.690617</td>\n",
" <td>-1.356399</td>\n",
" <td>-1.232435</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>-0.544439</td>\n",
" <td>-0.668172</td>\n",
" <td>0.007315</td>\n",
" <td>-0.612939</td>\n",
" <td>1.299748</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>-1.733096</td>\n",
" <td>-0.983310</td>\n",
" <td>0.357508</td>\n",
" <td>-1.613579</td>\n",
" <td>1.470714</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3 4\n",
"0 -1.749765 0.342680 1.153036 -0.252436 0.981321\n",
"1 0.514219 0.221180 -1.070043 -0.189496 0.255001\n",
"2 -0.458027 0.435163 -0.583595 0.816847 0.672721\n",
"3 -0.104411 -0.531280 1.029733 -0.438136 -1.118318\n",
"4 1.618982 1.541605 -0.251879 -0.842436 0.184519\n",
"5 0.937082 0.731000 1.361556 -0.326238 0.055676\n",
"6 0.222400 -1.443217 -0.756352 0.816454 0.750445\n",
"7 -0.455947 1.189622 -1.690617 -1.356399 -1.232435\n",
"8 -0.544439 -0.668172 0.007315 -0.612939 1.299748\n",
"9 -1.733096 -0.983310 0.357508 -1.613579 1.470714"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 -0.175300\n",
"1 0.083527\n",
"2 -0.044334\n",
"3 -0.399836\n",
"4 0.331939\n",
"dtype: float64\n",
"0 1.069584\n",
"1 0.965548\n",
"2 1.018232\n",
"3 0.793167\n",
"4 0.918992\n",
"dtype: float64\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>-1.574465</td>\n",
" <td>0.259153</td>\n",
" <td>1.197370</td>\n",
" <td>0.147400</td>\n",
" <td>0.649382</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.689519</td>\n",
" <td>0.137652</td>\n",
" <td>-1.025709</td>\n",
" <td>0.210340</td>\n",
" <td>-0.076938</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>-0.282727</td>\n",
" <td>0.351636</td>\n",
" <td>-0.539261</td>\n",
" <td>1.216683</td>\n",
" <td>0.340782</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.070889</td>\n",
" <td>-0.614808</td>\n",
" <td>1.074067</td>\n",
" <td>-0.038300</td>\n",
" <td>-1.450257</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.794282</td>\n",
" <td>1.458078</td>\n",
" <td>-0.207545</td>\n",
" <td>-0.442600</td>\n",
" <td>-0.147420</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>1.112383</td>\n",
" <td>0.647473</td>\n",
" <td>1.405890</td>\n",
" <td>0.073598</td>\n",
" <td>-0.276263</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0.397700</td>\n",
" <td>-1.526744</td>\n",
" <td>-0.712018</td>\n",
" <td>1.216290</td>\n",
" <td>0.418506</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>-0.280647</td>\n",
" <td>1.106095</td>\n",
" <td>-1.646283</td>\n",
" <td>-0.956563</td>\n",
" <td>-1.564374</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>-0.369139</td>\n",
" <td>-0.751699</td>\n",
" <td>0.051649</td>\n",
" <td>-0.213103</td>\n",
" <td>0.967809</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>-1.557795</td>\n",
" <td>-1.066837</td>\n",
" <td>0.401842</td>\n",
" <td>-1.213743</td>\n",
" <td>1.138775</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3 4\n",
"0 -1.574465 0.259153 1.197370 0.147400 0.649382\n",
"1 0.689519 0.137652 -1.025709 0.210340 -0.076938\n",
"2 -0.282727 0.351636 -0.539261 1.216683 0.340782\n",
"3 0.070889 -0.614808 1.074067 -0.038300 -1.450257\n",
"4 1.794282 1.458078 -0.207545 -0.442600 -0.147420\n",
"5 1.112383 0.647473 1.405890 0.073598 -0.276263\n",
"6 0.397700 -1.526744 -0.712018 1.216290 0.418506\n",
"7 -0.280647 1.106095 -1.646283 -0.956563 -1.564374\n",
"8 -0.369139 -0.751699 0.051649 -0.213103 0.967809\n",
"9 -1.557795 -1.066837 0.401842 -1.213743 1.138775"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3 4\n",
"0 0.0 0.0 0.0 0.0 0.0\n",
"1 0.0 0.0 0.0 0.0 0.0\n",
"2 0.0 0.0 0.0 0.0 0.0\n",
"3 0.0 0.0 0.0 0.0 0.0\n",
"4 0.0 0.0 0.0 0.0 0.0\n",
"5 0.0 0.0 0.0 0.0 0.0\n",
"6 0.0 0.0 0.0 0.0 0.0\n",
"7 0.0 0.0 0.0 0.0 0.0\n",
"8 0.0 0.0 0.0 0.0 0.0\n",
"9 0.0 0.0 0.0 0.0 0.0"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import sklearn.linear_model as skl\n",
"from sklearn.metrics import mean_squared_error\n",
@@ -2055,7 +1712,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"np.random.seed()\n",
@@ -2078,7 +1738,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
@@ -2129,7 +1792,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# Common imports\n",
@@ -2692,7 +2358,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import numpy as np\n",
@@ -2762,7 +2431,7 @@
"\n",
"[Video of Lecture from 2020](https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember11.mp4?vrtx=view-as-webpage) and [handwritten notes](https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember11.pdf)\n",
"\n",
"More material will be added here, see handwritten notes also.\n",
"More material will be added here, see handwritten notes also. Note that this material will be cleaned up after the lecture of Friday September 3. See the handwritten notes from Friday's lecture at <https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021>.\n",
"\n",
"\n",
"## Ridge and LASSO Regression\n",
@@ -3393,20 +3062,12 @@
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.22501987939529708\n",
"3.4265364730355325\n",
"[[1.06251574 3.06513214]\n",
" [3.06513214 9.90295583]]\n"
]
}
],
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# Importing various packages\n",
"import numpy as np\n",
@@ -3435,20 +3096,12 @@
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.080263294546264\n",
"2.011002230765845\n",
"[[1. 0.7136592]\n",
" [0.7136592 1. ]]\n"
]
}
],
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"n = 100\n",
@@ -3490,40 +3143,12 @@
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[-0.31787985 -1.14338084]\n",
" [ 0.04529807 -0.18207237]\n",
" [ 1.11176315 3.45031813]\n",
" [-1.91097714 -5.2907413 ]\n",
" [-0.19918861 1.18654759]\n",
" [ 0.84454053 2.34712647]\n",
" [ 0.82299467 1.93582947]\n",
" [-1.64434822 -5.13289015]\n",
" [ 1.10923753 3.75337971]\n",
" [ 0.13855987 -0.92411672]]\n",
" 0 1\n",
"0 -0.317880 -1.143381\n",
"1 0.045298 -0.182072\n",
"2 1.111763 3.450318\n",
"3 -1.910977 -5.290741\n",
"4 -0.199189 1.186548\n",
"5 0.844541 2.347126\n",
"6 0.822995 1.935829\n",
"7 -1.644348 -5.132890\n",
"8 1.109238 3.753380\n",
"9 0.138560 -0.924117\n",
" 0 1\n",
"0 1.000000 0.968568\n",
"1 0.968568 1.000000\n"
]
}
],
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
@@ -3551,49 +3176,12 @@
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"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.063613 0.068251 0.071169 0.070546 0.069425 0.067581 0.065899 \n",
"2 0.0 0.068251 0.073991 0.077286 0.077098 0.076290 0.073977 0.072493 \n",
"3 0.0 0.071169 0.077286 0.083456 0.083469 0.082851 0.081789 0.080312 \n",
"4 0.0 0.070546 0.077098 0.083469 0.083869 0.083597 0.082364 0.081188 \n",
"5 0.0 0.069425 0.076290 0.082851 0.083597 0.083643 0.082304 0.081413 \n",
"6 0.0 0.067581 0.073977 0.081789 0.082364 0.082304 0.082005 0.080988 \n",
"7 0.0 0.065899 0.072493 0.080312 0.081188 0.081413 0.080988 0.080245 \n",
"8 0.0 0.064203 0.070945 0.078766 0.079908 0.080389 0.079865 0.079371 \n",
"9 0.0 0.062545 0.069397 0.077214 0.078591 0.079301 0.078699 0.078431 \n",
"10 0.0 0.061809 0.068087 0.076517 0.077496 0.077870 0.078063 0.077474 \n",
"11 0.0 0.060077 0.066459 0.074794 0.076005 0.076605 0.076675 0.076314 \n",
"12 0.0 0.058442 0.064904 0.073149 0.074564 0.075366 0.075332 0.075177 \n",
"13 0.0 0.056909 0.063432 0.071590 0.073188 0.074169 0.074047 0.074077 \n",
"14 0.0 0.055478 0.062046 0.070123 0.071881 0.073022 0.072826 0.073022 \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.064203 0.062545 0.061809 0.060077 0.058442 0.056909 0.055478 \n",
"2 0.070945 0.069397 0.068087 0.066459 0.064904 0.063432 0.062046 \n",
"3 0.078766 0.077214 0.076517 0.074794 0.073149 0.071590 0.070123 \n",
"4 0.079908 0.078591 0.077496 0.076005 0.074564 0.073188 0.071881 \n",
"5 0.080389 0.079301 0.077870 0.076605 0.075366 0.074169 0.073022 \n",
"6 0.079865 0.078699 0.078063 0.076675 0.075332 0.074047 0.072826 \n",
"7 0.079371 0.078431 0.077474 0.076314 0.075177 0.074077 0.073022 \n",
"8 0.078726 0.077994 0.076758 0.075809 0.074861 0.073933 0.073033 \n",
"9 0.077994 0.077452 0.075974 0.075216 0.074443 0.073672 0.072915 \n",
"10 0.076758 0.075974 0.075342 0.074315 0.073305 0.072325 0.071384 \n",
"11 0.075809 0.075216 0.074315 0.073486 0.072655 0.071838 0.071044 \n",
"12 0.074861 0.074443 0.073305 0.072655 0.071987 0.071318 0.070658 \n",
"13 0.073933 0.073672 0.072325 0.071838 0.071318 0.070783 0.070245 \n",
"14 0.073033 0.072915 0.071384 0.071044 0.070658 0.070245 0.069818 \n"
]
}
],
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# Common imports\n",
"import numpy as np\n",
@@ -3883,7 +3471,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"x = np.random.rand(100)\n",
@@ -3905,7 +3496,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import os\n",
@@ -4100,7 +3694,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"from mpl_toolkits.mplot3d import Axes3D\n",
@@ -4218,7 +3815,10 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"def FrankeFunction(x,y):\n",
@@ -4276,25 +3876,7 @@
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
+3 -3
View File
@@ -6,10 +6,10 @@ DATE: today
!split
===== Plans for week 35, August 30 -September 3 =====
* Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression
* Thursday: Review of ordinary Least Squares with applications and discussion of Ridge Regression and Singular Value Decomposition
* "Video of lecture Thursday":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember2.mp4?vrtx=view-as-webpage".
* Friday: Analysis of Ridge and Lasso Regression
* Friday: Analysis of Ridge and Lasso Regression and links with Singular Value Decomposition
@@ -1544,7 +1544,7 @@ If you wish to include the zero singular values, you will need to resize the mat
"Video of Lecture from 2020":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember11.mp4?vrtx=view-as-webpage" and "handwritten notes":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember11.pdf"
More material will be added here, see handwritten notes also.
More material will be added here, see handwritten notes also. Note that this material will be cleaned up after the lecture of Friday September 3. See the handwritten notes from Friday's lecture at URL:"https://github.com/CompPhysics/MachineLearning/tree/master/doc/HandWrittenNotes/2021".
!split