This commit is contained in:
Morten Hjorth-Jensen
2021-09-12 21:35:47 +02:00
2 changed files with 186 additions and 155 deletions
+8 -8
View File
@@ -235,37 +235,37 @@ Recommended prereading: Chapters 1-2 (linear algebra) and chapter 3 (statistics)
- Lab Wednesday: Introduction to software and repetition of Python Programming
- Lecture Thursday: Introduction to the course, what is Machine Learning and introduction to Linear Regression
- Lecture Friday: Basics of Linear Regression
- Reading recommendations: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 35 at https://compphysics.github.io/MachineLearning/doc/web/course.html
- Reading recommendations: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html
### Week 35 August 30-September 3
- Lab Wednesday:
- Lecture Thursday: Linear Regression, from ordinary linear regression to Ridge and Lasso regression, linear algebra analysis, examples and discussions of codes
- Lecture Friday: Linear Regression, Linear algebra and Ridge and Lasso Regression, linear algebra analysis, examples and discussions of codes
- Reading recommendations: See lecture notes for week 36 at https://compphysics.github.io/MachineLearning/doc/web/course.html. HTF chapter 3. GBC chapters 1 and and sections 3.1-3.11 and 5.1 and CMB sections 1.1 and 3.1
- Reading recommendations: See lecture notes for week 35 at https://compphysics.github.io/MachineLearning/doc/web/course.html. HTF chapter 3. GBC chapters 1 and and sections 3.1-3.11 and 5.1 and CMB sections 1.1 and 3.1
### Week 36 September 6-10
- Lab Wednesday:
- Lecture Thursday: Statistical interpretation of Linear Regression
- Lecture Friday: Bias-Variance tradeoff
- Reading recommendations: See lecture notes for week 37 at https://compphysics.github.io/MachineLearning/doc/web/course.html. GBC sections 5.2-5.5, CMB section 3.2
- Lecture Thursday: Ridge and Lasso regression and the SVD. Statistical interpretation of Linear Regression
- Lecture Friday: Further interpretations of Linear regression.
- Reading recommendations: See lecture notes for week 36 at https://compphysics.github.io/MachineLearning/doc/web/course.html. GBC sections 5.2-5.5, CMB section 3.2
- Chapter
### Week 37 September 13-17
- Lab Wednesday:
- Lecture Thursday: Resampling methods, cross-validation and Bootstrap
- Lecture Friday: More on Resampling methods and summary of linear regression
- Reading recommendations: See lecture notes for week 38 at https://compphysics.github.io/MachineLearning/doc/web/course.html.
- Reading recommendations: See lecture notes for week 37 at https://compphysics.github.io/MachineLearning/doc/web/course.html.
- Chapter
### Week 38 September 20-24
- Lab Wednesday:
- Lecture Thursday: Classification problems and Logistic Regression, from binary cases to several categories
- Lecture Friday: Logistic Regression and gradient optimization
- Reading recommendations: See lecture notes for week 39 at https://compphysics.github.io/MachineLearning/doc/web/course.html.
- Reading recommendations: See lecture notes for week 38 at https://compphysics.github.io/MachineLearning/doc/web/course.html.
- Chapter
### Week 39 September 27- October 1
- Lab Wednesday:
- Lecture Thursday: Gradient Optimization methods
- Lecture Friday: Deep Learning and Neural Networks
- Reading recommendations: See lecture notes for week 40 at https://compphysics.github.io/MachineLearning/doc/web/course.html.
- Reading recommendations: See lecture notes for week 39 at https://compphysics.github.io/MachineLearning/doc/web/course.html.
- Chapter
### Week 40 October 4-8
- Lab Wednesday:
+178 -147
View File
@@ -402,10 +402,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
@@ -956,10 +953,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"# matrix inversion to find beta\n",
@@ -978,10 +972,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"fit = np.linalg.lstsq(X, Energies, rcond =None)[0]\n",
@@ -998,10 +989,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"Masses['Eapprox'] = ytilde\n",
@@ -1031,10 +1019,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"def R2(y_data, y_model):\n",
@@ -1051,10 +1036,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"print(R2(Energies,ytilde))"
@@ -1070,10 +1052,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"def MSE(y_data,y_model):\n",
@@ -1093,10 +1072,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"def RelativeError(y_data,y_model):\n",
@@ -1131,10 +1107,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"import os\n",
@@ -1187,10 +1160,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"# equivalently in numpy\n",
@@ -1262,10 +1232,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
@@ -1285,10 +1252,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from sklearn.datasets import load_boston\n",
@@ -1310,10 +1274,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"boston = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)\n",
@@ -1331,10 +1292,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"# check for missing values in all the columns\n",
@@ -1351,10 +1309,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"# set the size of the figure\n",
@@ -1375,10 +1330,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"# compute the pair wise correlation for all columns \n",
@@ -1398,10 +1350,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(20, 5))\n",
@@ -1429,10 +1378,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"X = pd.DataFrame(np.c_[boston['LSTAT'], boston['RM']], columns = ['LSTAT','RM'])\n",
@@ -1449,10 +1395,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
@@ -1476,10 +1419,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from sklearn.linear_model import LinearRegression\n",
@@ -1518,10 +1458,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"# plotting the y_test vs y_pred\n",
@@ -1649,10 +1586,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"import sklearn.linear_model as skl\n",
@@ -1722,10 +1656,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"np.random.seed()\n",
@@ -1748,10 +1679,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
@@ -1802,10 +1730,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"# Common imports\n",
@@ -2379,12 +2304,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1. -1.]\n",
" [ 1. -1.]]\n",
"test U\n",
"[[0. 0.]\n",
" [0. 0.]]\n",
"test VT\n",
"[[0. 0.]\n",
" [0. 0.]]\n",
"[[-0.70710678 -0.70710678]\n",
" [-0.70710678 0.70710678]]\n",
"[2.00000000e+00 3.35470445e-17]\n",
"[[-0.70710678 0.70710678]\n",
" [ 0.70710678 0.70710678]]\n",
"[[-3.33066907e-16 4.44089210e-16]\n",
" [ 0.00000000e+00 2.22044605e-16]]\n"
]
}
],
"source": [
"import numpy as np\n",
"# SVD inversion\n",
@@ -3182,12 +3126,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.08839767027751376\n",
"3.8294285924714866\n",
"[[0.92932998 2.63805954]\n",
" [2.63805954 8.61477117]]\n"
]
}
],
"source": [
"# Importing various packages\n",
"import numpy as np\n",
@@ -3216,12 +3168,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0850713352585812\n",
"1.5846946541436007\n",
"[[1. 0.63837291]\n",
" [0.63837291 1. ]]\n"
]
}
],
"source": [
"import numpy as np\n",
"n = 100\n",
@@ -3263,12 +3223,40 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1.09669785 3.23795259]\n",
" [-0.22166894 -1.30593687]\n",
" [ 0.10192631 0.04245426]\n",
" [ 0.82011099 2.55486566]\n",
" [ 0.32105408 0.96706068]\n",
" [ 0.60361795 1.47703672]\n",
" [-1.87875598 -5.24764141]\n",
" [ 0.03658513 0.37688017]\n",
" [-0.57033315 -1.70980756]\n",
" [-0.30923424 -0.39286425]]\n",
" 0 1\n",
"0 1.096698 3.237953\n",
"1 -0.221669 -1.305937\n",
"2 0.101926 0.042454\n",
"3 0.820111 2.554866\n",
"4 0.321054 0.967061\n",
"5 0.603618 1.477037\n",
"6 -1.878756 -5.247641\n",
"7 0.036585 0.376880\n",
"8 -0.570333 -1.709808\n",
"9 -0.309234 -0.392864\n",
" 0 1\n",
"0 1.000000 0.990742\n",
"1 0.990742 1.000000\n"
]
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
@@ -3297,12 +3285,49 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"execution_count": 5,
"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.079955 0.083252 0.080480 0.081776 0.083055 0.071202 0.072287 \n",
"2 0.0 0.083252 0.087624 0.083966 0.085810 0.087616 0.074576 0.076060 \n",
"3 0.0 0.080480 0.083966 0.085125 0.086868 0.088629 0.077734 0.079241 \n",
"4 0.0 0.081776 0.085810 0.086868 0.089002 0.091153 0.079679 0.081504 \n",
"5 0.0 0.083055 0.087616 0.088629 0.091153 0.093695 0.081663 0.083808 \n",
"6 0.0 0.071202 0.074576 0.077734 0.079679 0.081663 0.072591 0.074289 \n",
"7 0.0 0.072287 0.076060 0.079241 0.081504 0.083808 0.074289 0.076255 \n",
"8 0.0 0.073485 0.077660 0.080883 0.083467 0.086097 0.076120 0.078358 \n",
"9 0.0 0.074811 0.079394 0.082672 0.085583 0.088544 0.078096 0.080610 \n",
"10 0.0 0.061639 0.064871 0.068789 0.070813 0.072887 0.065314 0.067084 \n",
"11 0.0 0.062699 0.066259 0.070225 0.072518 0.074865 0.066904 0.068904 \n",
"12 0.0 0.063878 0.067775 0.071800 0.074368 0.076991 0.068629 0.070864 \n",
"13 0.0 0.065183 0.069422 0.073519 0.076366 0.079274 0.070494 0.072970 \n",
"14 0.0 0.066615 0.071207 0.075386 0.078520 0.081718 0.072505 0.075226 \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.073485 0.074811 0.061639 0.062699 0.063878 0.065183 0.066615 \n",
"2 0.077660 0.079394 0.064871 0.066259 0.067775 0.069422 0.071207 \n",
"3 0.080883 0.082672 0.068789 0.070225 0.071800 0.073519 0.075386 \n",
"4 0.083467 0.085583 0.070813 0.072518 0.074368 0.076366 0.078520 \n",
"5 0.086097 0.088544 0.072887 0.074865 0.076991 0.079274 0.081718 \n",
"6 0.076120 0.078096 0.065314 0.066904 0.068629 0.070494 0.072505 \n",
"7 0.078358 0.080610 0.067084 0.068904 0.070864 0.072970 0.075226 \n",
"8 0.080737 0.083272 0.068979 0.071034 0.073233 0.075583 0.078091 \n",
"9 0.083272 0.086096 0.071010 0.073303 0.075747 0.078348 0.081114 \n",
"10 0.068979 0.071010 0.059527 0.061166 0.062930 0.064825 0.066855 \n",
"11 0.071034 0.073303 0.061166 0.063004 0.064972 0.067075 0.069319 \n",
"12 0.073233 0.075747 0.062930 0.064972 0.067148 0.069465 0.071929 \n",
"13 0.075583 0.078348 0.064825 0.067075 0.069465 0.072001 0.074691 \n",
"14 0.078091 0.081114 0.066855 0.069319 0.071929 0.074691 0.077614 \n"
]
}
],
"source": [
"# Common imports\n",
"import numpy as np\n",
@@ -4086,10 +4111,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"x = np.random.rand(100)\n",
@@ -4111,10 +4133,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"import os\n",
@@ -4309,10 +4328,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from mpl_toolkits.mplot3d import Axes3D\n",
@@ -4430,10 +4446,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"def FrankeFunction(x,y):\n",
@@ -4491,7 +4504,25 @@
]
}
],
"metadata": {},
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}