From 419f83c93ae1907a8c625a663f83d39d97a6e6ee Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Thu, 9 Sep 2021 15:11:20 +0200 Subject: [PATCH] update week 36 --- doc/pub/week36/html/week36-reveal.html | 17 +- doc/pub/week36/html/week36-solarized.html | 17 +- doc/pub/week36/html/week36.html | 17 +- doc/pub/week36/ipynb/ipynb-week36-src.tar.gz | Bin 192 -> 191 bytes doc/pub/week36/ipynb/week36.ipynb | 379 +-- doc/src/week36/add.do.txt | 2249 ++++++++++++++++++ doc/src/week36/week36.do.txt | 17 +- 7 files changed, 2376 insertions(+), 320 deletions(-) create mode 100644 doc/src/week36/add.do.txt diff --git a/doc/pub/week36/html/week36-reveal.html b/doc/pub/week36/html/week36-reveal.html index f7d65c56d..c330b6cec 100644 --- a/doc/pub/week36/html/week36-reveal.html +++ b/doc/pub/week36/html/week36-reveal.html @@ -162,7 +162,7 @@ MathJax.Hub.Config({

Plans for week 36

@@ -769,11 +769,7 @@ $$

 

-Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of \( \beta_i \) for specific values of \( \lambda \). Ridge regression reduces on the other hand the values of \( \beta_i \) as function of \( \lambda \). - -

-We will now couple the discussions of ordinary least squares, Ridge and Lasso regression with a statistical interpretation, that is we move from a linear algebra analysis to a statistical analysis. In particular, we will focus on what the regularization terms can result in. -We will amongst other things show that the regularization parameter can reduce considerably the variance of the parameters \( \beta \). +Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of \( \beta_i \) for specific values of \( \lambda \). Ridge regression reduces on the other hand the values of \( \beta_i \) as function of \( \lambda \). @@ -1195,6 +1191,15 @@ plt.show()

Linking the regression analysis with a statistical interpretation

+

+We will now couple the discussions of ordinary least squares, Ridge +and Lasso regression with a statistical interpretation, that is we +move from a linear algebra analysis to a statistical analysis. In +particular, we will focus on what the regularization terms can result +in. We will amongst other things show that the regularization +parameter can reduce considerably the variance of the parameters +\( \beta \). +

The advantage of doing linear regression is that we actually end up with diff --git a/doc/pub/week36/html/week36-solarized.html b/doc/pub/week36/html/week36-solarized.html index 2d52143dc..8ea13d897 100644 --- a/doc/pub/week36/html/week36-solarized.html +++ b/doc/pub/week36/html/week36-solarized.html @@ -303,7 +303,7 @@ MathJax.Hub.Config({

Plans for week 36

@@ -827,11 +827,7 @@ $$ $$

-Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of \( \beta_i \) for specific values of \( \lambda \). Ridge regression reduces on the other hand the values of \( \beta_i \) as function of \( \lambda \). - -

-We will now couple the discussions of ordinary least squares, Ridge and Lasso regression with a statistical interpretation, that is we move from a linear algebra analysis to a statistical analysis. In particular, we will focus on what the regularization terms can result in. -We will amongst other things show that the regularization parameter can reduce considerably the variance of the parameters \( \beta \). +Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of \( \beta_i \) for specific values of \( \lambda \). Ridge regression reduces on the other hand the values of \( \beta_i \) as function of \( \lambda \).











@@ -1216,6 +1212,15 @@ plt.show()

Linking the regression analysis with a statistical interpretation

+

+We will now couple the discussions of ordinary least squares, Ridge +and Lasso regression with a statistical interpretation, that is we +move from a linear algebra analysis to a statistical analysis. In +particular, we will focus on what the regularization terms can result +in. We will amongst other things show that the regularization +parameter can reduce considerably the variance of the parameters +\( \beta \). +

The advantage of doing linear regression is that we actually end up with diff --git a/doc/pub/week36/html/week36.html b/doc/pub/week36/html/week36.html index b3cf5190d..4a73d1fc6 100644 --- a/doc/pub/week36/html/week36.html +++ b/doc/pub/week36/html/week36.html @@ -308,7 +308,7 @@ MathJax.Hub.Config({

Plans for week 36

@@ -832,11 +832,7 @@ $$ $$

-Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of \( \beta_i \) for specific values of \( \lambda \). Ridge regression reduces on the other hand the values of \( \beta_i \) as function of \( \lambda \). - -

-We will now couple the discussions of ordinary least squares, Ridge and Lasso regression with a statistical interpretation, that is we move from a linear algebra analysis to a statistical analysis. In particular, we will focus on what the regularization terms can result in. -We will amongst other things show that the regularization parameter can reduce considerably the variance of the parameters \( \beta \). +Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of \( \beta_i \) for specific values of \( \lambda \). Ridge regression reduces on the other hand the values of \( \beta_i \) as function of \( \lambda \).











@@ -1221,6 +1217,15 @@ plt.show()

Linking the regression analysis with a statistical interpretation

+

+We will now couple the discussions of ordinary least squares, Ridge +and Lasso regression with a statistical interpretation, that is we +move from a linear algebra analysis to a statistical analysis. In +particular, we will focus on what the regularization terms can result +in. We will amongst other things show that the regularization +parameter can reduce considerably the variance of the parameters +\( \beta \). +

The advantage of doing linear regression is that we actually end up with diff --git a/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz b/doc/pub/week36/ipynb/ipynb-week36-src.tar.gz index b5f94b110721cb9786744c736276b88aa1b85628..3c840b2d52f09b604ad102048863565b3880e56d 100644 GIT binary patch literal 191 zcmV;w06_mAiwFSh2RdN@1MSaC3c@fD2H>uHia9|^%%f|;E?fvAULd8ZjkQTlQna_X z573q3rihSl^E1pa%p9`yW|t-Y?xV#ZggB)zX3E)=Xf@Xpj2U2xF{g;6i~_=h5flMh z?xdH_d0~fBn(8dIlltAwd?K@bGN*B%8{$$$U|004;SS$Y5f literal 192 zcmV;x06+g9iwFQJ$~j>G1MSbv3c@f92k@Qu6nTQtZtXk^?%+WX@dY}TxjNU*wnO*! z?gR9sco`z}cli?%LUPE~n_U*Uy9*XW2uT@(F;^*{lEia8p_Btl$u|b&^K1?Ntti uMmx5^;I)$mL8u-?QAj7X5|^+w`ea07qwv?yc%J8ZUwZ&XPn_NW2mk;QeOoR7 diff --git a/doc/pub/week36/ipynb/week36.ipynb b/doc/pub/week36/ipynb/week36.ipynb index 727eb88f7..32d4e9909 100644 --- a/doc/pub/week36/ipynb/week36.ipynb +++ b/doc/pub/week36/ipynb/week36.ipynb @@ -19,7 +19,7 @@ "\n", "## Plans for week 36\n", "\n", - "* Thursday: Summary from last week on SVD, Statistics, probability theory and linear regression\n", + "* Thursday: Summary from last week on SVD, Statistics, probability theory and linear regression. [Video of Lecture](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember9.mp4?vrtx=view-as-webpage).\n", "\n", "* Friday: Linear Regression and links with Statistics, Resampling methods and presentation of first project.\n", "\n", @@ -264,7 +264,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "Ainv = np.linlag.pinv(A)" @@ -279,30 +282,12 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1 2 3]\n", - " [2 4 5]\n", - " [3 5 6]]\n", - "test U\n", - "[[ 2.22044605e-16 -7.77156117e-16 -5.55111512e-16]\n", - " [-7.77156117e-16 0.00000000e+00 -1.11022302e-16]\n", - " [-5.55111512e-16 -1.11022302e-16 0.00000000e+00]]\n", - "test VT\n", - "[[ 1.11022302e-16 -2.22044605e-16 1.38777878e-16]\n", - " [-2.22044605e-16 -1.11022302e-16 -1.11022302e-16]\n", - " [ 1.38777878e-16 -1.11022302e-16 0.00000000e+00]]\n", - "[[2.35367281e-12 1.70885528e-12 3.20632410e-13]\n", - " [2.17248441e-12 1.46016532e-12 2.00728323e-13]\n", - " [6.95443703e-13 4.13891144e-13 2.13162821e-14]]\n" - ] - } - ], + "execution_count": null, + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "import numpy as np\n", "# SVD inversion\n", @@ -370,24 +355,12 @@ }, { "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0.3 0.4]\n", - " [0.5 0.6]\n", - " [0.7 0.8]\n", - " [0.9 1. ]]\n", - "[[-13. -6. 1. 8. ]\n", - " [ 11.5 5.5 -0.5 -6.5]]\n", - "[[0. 0. 0. 0.]\n", - " [0. 0. 0. 0.]]\n" - ] - } - ], + "execution_count": null, + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "import numpy as np\n", "# SVD inversion\n", @@ -947,10 +920,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of $\\beta_i$ for specific values of $\\lambda$. Ridge regression reduces on the other hand the values of $\\beta_i$ as function of $\\lambda$.\n", + "Plotting these results ([figure in handwritten notes for week 36](https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/2021/NotesSeptember9.pdf)) shows clearly that Lasso regression suppresses (sets to zero) values of $\\beta_i$ for specific values of $\\lambda$. Ridge regression reduces on the other hand the values of $\\beta_i$ as function of $\\lambda$.\n", "\n", - "We will now couple the discussions of ordinary least squares, Ridge and Lasso regression with a statistical interpretation, that is we move from a linear algebra analysis to a statistical analysis. In particular, we will focus on what the regularization terms can result in.\n", - "We will amongst other things show that the regularization parameter can reduce considerably the variance of the parameters $\\beta$.\n", "\n", "\n", "## Yet another Example\n", @@ -1272,71 +1243,12 @@ }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2. 2.]\n", - "Training MSE for OLS\n", - "3.0\n", - "[1.99995 1.99980002]\n", - "[1.99991982 1.99967931]\n", - "[1.99987141 1.99948575]\n", - "[1.99979379 1.99917541]\n", - "[1.99966932 1.99867793]\n", - "[1.99946973 1.99788061]\n", - "[1.99914973 1.99660327]\n", - "[1.99863676 1.99455818]\n", - "[1.99781465 1.99128716]\n", - "[1.99649762 1.98606371]\n", - "[1.99438911 1.97774375]\n", - "[1.99101692 1.96454542]\n", - "[1.98563263 1.94374291]\n", - "[1.97705827 1.91128596]\n", - "[1.96346096 1.86143821]\n", - "[1.94204092 1.78670708]\n", - "[1.90864819 1.67862942]\n", - "[1.85742884 1.53018786]\n", - "[1.78078998 1.34013383]\n", - "[1.67026738 1.11753552]\n", - "[1.51906998 0.88246448]\n", - "[1.32649797 0.65986617]\n", - "[1.10238077 0.46981214]\n", - "[0.86736427 0.32137058]\n", - "[0.64637186 0.21329292]\n", - "[0.45887364 0.13856179]\n", - "[0.31318084 0.08871404]\n", - "[0.20751692 0.05625709]\n", - "[0.134657 0.03545458]\n", - "[0.08614899 0.02225625]\n", - "[0.05460368 0.01393629]\n", - "[0.03440174 0.00871284]\n", - "[0.02159104 0.00544182]\n", - "[0.01351804 0.00339673]\n", - "[0.00845069 0.00211939]\n", - "[0.00527783 0.00132207]\n", - "[0.00329427 0.00082459]\n", - "[0.00205542 0.00051425]\n", - "[0.00128215 0.00032069]\n", - "[0.00079968 0.00019998]\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEGCAYAAABvtY4XAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAj3klEQVR4nO3deXxV1bn/8c/DPMqMMohQBwQRLQQVcWZQURGVFhDrVbTodUB/Iq3Wex3rrV5671VpK5XiUEW0oMxIoSpqVYQwg6BWRcCCRirIIBiS5/fHOiEBQgIhO/sM3/frtV8556x9zv6G4cnK2muvbe6OiIikn0pxBxARkWiowIuIpCkVeBGRNKUCLyKSplTgRUTSVJW4AxTVuHFjb926ddwxRERSxoIFC75x9ybFtSVVgW/dujXZ2dlxxxARSRlm9sX+2jREIyKSplTgRUTSlAq8iEiaSqox+OLk5uaybt06duzYEXcUOQg1atSgZcuWVK1aNe4oIhkr6Qv8unXrqFu3Lq1bt8bM4o4jB8Dd2bhxI+vWraNNmzZxxxHJWEk/RLNjxw4aNWqk4p5CzIxGjRrpty6RmCV9gQdU3FOQ/s5E4pf0QzQiIrHasQO2bg1fd+4MW34+dOgQ2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ZifJS74WW5mpyTe38jCvQFWmNmfACtyzElmtiDRNqTI50wBBpb1z1Iyjwq8JLvLCet3n0TolY9IFOXLgdaEddp/RrjqtTTFrg5pZm2Ab919ZzHvWQWc6e4/JqwC+l9F2jokcnQBHga2J/Z7H7i6yH61EvcCuAl4OvHafcDf3f0EYCLQqsj+g929M5AFDDWzRgDu/i1QveC5SGlSbrExyThnAOMSKwF+ZWZvEQrqGcB4d88HNiQWjyqrZkDOftrqAc8l1hNywjriBd5MrHm+xcw2A1MTry8DOhbZbxyENdzN7LDEmihnEX444O7TzezbIvsPNbPLEo+PJAwpbUw8/xpoXuS5yH6pBy+ZZH+rQ35PWM2vOA8RCnkH4JK99iva488v8jyfPTtPe68Hst/1QRLLxvYAuibuPrRor2PWSOQVKZUKvCS7d4D+iZs1NCH0fOcRTqRekRiLPxw45wA+awpwdWJc/zRgs7uvJ9yusPV+3lOPwiWCrynj91Bw3uCMxDE3E25HeGXi9QuBgtkx9QjDRdvN7HjCbe9I7GeENfRXlzGHZBgVeEl2E4GlwBLgDeAXiSWgXyGMoX8IvAAsBDYDmNnQxGqULYGliZOYENbh/wz4B2HGzE0A7r4N+NTMjinm+P8N/MbMFlH2Ic0difePAgpWfXwAOMvMVhCGagruITwTqGJmK4FHCLdSLNAZmFvkNosiJdJqkpKyzKyOu29NnHScB3Qr6/r/iTHvzu7+H+UashyZ2ePAFHd/Pe4skhp0klVS2bTECctqwEOHcnMXd5+YArNTlqu4y8FQD15EJE1pDF5EJE2pwIuIpCkVeBGRNKUCLyKSplTgRUTS1P8HjeN/LhUCH4UAAAAASUVORK5CYII=\n", - "text/plain": [ - "

" - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "execution_count": null, + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "%matplotlib inline\n", "\n", @@ -1371,13 +1283,13 @@ "# Repeat now for Ridge regression and various values of the regularization parameter\n", "I = np.eye(2,2)\n", "# Decide which values of lambda to use\n", - "nlambdas = 40\n", + "nlambdas = 100\n", "MSEPredict = np.zeros(nlambdas)\n", "lambdas = np.logspace(-4, 4, nlambdas)\n", "for i in range(nlambdas):\n", " lmb = lambdas[i]\n", " Ridgebeta = np.linalg.inv(X.T @ X+lmb*I) @ X.T @ y\n", - " print(Ridgebeta)\n", + "# print(Ridgebeta)\n", " # and then make the prediction\n", " ypredictRidge = X @ Ridgebeta\n", " MSEPredict[i] = MSE(y,ypredictRidge)\n", @@ -1403,131 +1315,12 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2. 2.]\n", - "Training MSE for OLS\n", - "3.0\n", - "[1.99995 1.99980002]\n", - "[1.99993978 1.99975913]\n", - "[1.99992746 1.99970988]\n", - "[1.99991263 1.99965056]\n", - "[1.99989476 1.99957911]\n", - "[1.99987324 1.99949306]\n", - "[1.99984732 1.99938942]\n", - "[1.9998161 1.99926459]\n", - "[1.99977849 1.99911427]\n", - "[1.9997332 1.99893323]\n", - "[1.99967865 1.99871521]\n", - "[1.99961294 1.99845267]\n", - "[1.99953381 1.99813653]\n", - "[1.9994385 1.99775587]\n", - "[1.9993237 1.99729756]\n", - "[1.99918546 1.9967458 ]\n", - "[1.99901896 1.99608161]\n", - "[1.99881845 1.99528218]\n", - "[1.998577 1.9943201]\n", - "[1.99828624 1.99316252]\n", - "[1.99793613 1.99176998]\n", - "[1.99751458 1.99009525]\n", - "[1.99700706 1.98808176]\n", - "[1.9963961 1.98566191]\n", - "[1.99566069 1.98275501]\n", - "[1.9947756 1.97926491]\n", - "[1.99371056 1.97507735]\n", - "[1.99242921 1.97005689]\n", - "[1.99088801 1.9640435 ]\n", - "[1.9890348 1.95684892]\n", - "[1.98680716 1.9482527 ]\n", - "[1.98413059 1.93799826]\n", - "[1.98091621 1.92578916]\n", - "[1.97705827 1.91128596]\n", - "[1.97243128 1.89410423]\n", - "[1.96688672 1.87381451]\n", - "[1.96024953 1.84994524]\n", - "[1.95231424 1.82198978]\n", - "[1.94284104 1.78941903]\n", - "[1.93155188 1.75170092]\n", - "[1.91812702 1.70832814]\n", - "[1.90220243 1.65885453]\n", - "[1.88336879 1.60293962]\n", - "[1.86117291 1.54039921]\n", - "[1.83512277 1.47125748]\n", - "[1.80469739 1.39579407]\n", - "[1.76936315 1.31457796]\n", - "[1.72859758 1.22847924]\n", - "[1.68192193 1.13865173]\n", - "[1.62894215 1.04648335]\n", - "[1.56939714 0.95351665]\n", - "[1.50321091 0.86134827]\n", - "[1.43054282 0.77152076]\n", - "[1.35182854 0.68542204]\n", - "[1.26780278 0.60420593]\n", - "[1.17949575 0.52874252]\n", - "[1.0881981 0.45960079]\n", - "[0.99539415 0.39706038]\n", - "[0.90266948 0.34114547]\n", - "[0.81160425 0.29167186]\n", - "[0.7236674 0.24829908]\n", - "[0.64012627 0.21058097]\n", - "[0.56198284 0.17801022]\n", - "[0.48994188 0.15005476]\n", - "[0.42441033 0.12618549]\n", - "[0.3655222 0.10589577]\n", - "[0.31318084 0.08871404]\n", - "[0.26710969 0.07421084]\n", - "[0.22690428 0.06200174]\n", - "[0.19207979 0.0517473 ]\n", - "[0.16211139 0.04315108]\n", - "[0.13646574 0.0359565 ]\n", - "[0.11462415 0.02994311]\n", - "[0.09609807 0.02492265]\n", - "[0.08043851 0.02073509]\n", - "[0.06724062 0.01724499]\n", - "[0.05614483 0.01433809]\n", - "[0.04683565 0.01191824]\n", - "[0.039039 0.00990475]\n", - "[0.03251863 0.00823002]\n", - "[0.02707227 0.00683748]\n", - "[0.02252765 0.0056799 ]\n", - "[0.01873869 0.00471782]\n", - "[0.01558197 0.00391839]\n", - "[0.01295356 0.0032542 ]\n", - "[0.01076611 0.00270244]\n", - "[0.00894639 0.00224413]\n", - "[0.0074331 0.00186347]\n", - "[0.00617499 0.00154733]\n", - "[0.00512927 0.00128479]\n", - "[0.00426027 0.00106677]\n", - "[0.00353823 0.00088573]\n", - "[0.00293838 0.00073541]\n", - "[0.0024401 0.00061058]\n", - "[0.00202624 0.00050694]\n", - "[0.00168251 0.00042089]\n", - "[0.00139705 0.00034944]\n", - "[0.00115999 0.00029012]\n", - "[0.00096314 0.00024087]\n", - "[0.00079968 0.00019998]\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEHCAYAAACp9y31AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAqrElEQVR4nO3dd5xU1fnH8c/DUhYBQQGJCAgaRQwCwmogRLCBBSIQVLBFQMSoKLFGJUaNqESMJSY/CRpR1ODPny0EsKCBSKIoHWkWEBGDSO9ly/P748wWdgaWsrt3Z+b7fr3ua2fuc2fus4WHM+eee465OyIikj4qRZ2AiIiULxV+EZE0o8IvIpJmVPhFRNKMCr+ISJpR4RcRSTOVy+qNzexZoDvwvbu3jO07HPhfoCmwDLjY3deX9F716tXzpk2bllWqIiIpaebMmWvcvX7x/VZW4/jNrBOwBRhTpPA/DKxz9+FmdgdwmLv/uqT3ysrK8hkzZpRJniIiqcrMZrp7VvH9ZdbV4+4fAOuK7e4BPB97/DzQs6zOLyIiiZV3H38Dd18Ze/wd0GBPB5rZIDObYWYzVq9eXT7ZiYikgcgu7nroY9pjP5O7j3L3LHfPql8/rotKREQOUJld3N2DVWZ2pLuvNLMjge8P9I2ys7NZsWIFO3bsKMX0JAqZmZk0atSIKlWqRJ2KSFoo78I/DrgSGB77+vcDfaMVK1ZQq1YtmjZtipmVVn5SztydtWvXsmLFCpo1axZ1OiJpocy6esxsLPAR0NzMVpjZVYSC38XMvgDOjj0/IDt27KBu3boq+knOzKhbt64+uYmUozJr8bv7JXsInVVa51DRTw36PYqUr/Lu6hERSS55ebBzJ+zYAdu3h69mkN81OXcurFsH2dmFW+3acMYZIf73v8OaNZCbW7gddRT06hXif/kLrF8fzpO/nXACXHxx2X1P7l7ht3bt2nlxCxcujNtX3gC/7LLLCp5nZ2d7vXr1vFu3bu7u/t1333m3bt28VatW3qJFCz/vvPPc3f2rr77yzMxMb926dcH2/PPPx71/586d/fjjj/dWrVp5VlaWz549uyB23nnn+fr16+Nec8899/iIESMO6vtas2ZNQV4NGjTwhg0bFjzfuXNnia+fPn2633DDDft1zorw+5QUtX27+1dfuX/yifuECe7PP+/+l78Uxh9/3L1nT/czznA/5RT3Fi3cO3QojHft6g67byeeWBjv2DE+fuqphfFWreLjZ51VGG/WLD7es2epfOvADE9QU9XiPwg1atRg/vz5bN++nerVqzNp0iSOOuqogvhvf/tbunTpwpAhQwCYN29eQezYY49lzpw5JZ7jpZdeIisri9GjR3PbbbcxadIkACZOnFi630wRdevWLcjt3nvvpWbNmtx66627HZOTk0Plyon/fLKyssjKirtZUKRsbNwIixfDl1/CV1/B11/Dt9/C+PFQqRLccAM888zur6lWDQYNCo+XL4clS+DQQ6FuXTj6aGjYsPDY/v1D67169fC6zEyoV68w/vjjsGULVKlSuNWqVRifODG08jMyCrdq1Qrj8+eHTxAZGSFfs7CVIRX+g3T++eczYcIELrzwQsaOHcsll1zC1KlTAVi5ciVdu3YtOLZVq1YHfJ4OHTowYsSIgudNmzZlxowZ1KtXjwceeIDnn3+eI444gsaNG9OuXTsApk+fzlVXXUWlSpXo0qULb731FvPnzyc3N5c77riDKVOmsHPnTq6//nquueaaEnPo168fmZmZzJ49m44dO9K3b1+GDBnCjh07qF69OqNHj6Z58+ZMmTKFRx55hPHjx3PvvfeyfPlyli5dyvLly/nVr37FjTfeeMA/B0lju3aFIjlzZuheGTYM6tQJhffeewuPa9AAmjSBzZtDl8sVV0D79nDEEVC/fijahx8e2tZm8Ic/7P28ffvuPV5SI6dIYzChQw7Ze7wMpE7hP/30+H0XXwzXXQfbtsH558fH+/UL25o1cOGFu8emTNmn0/bt25ff/e53dO/enXnz5jFgwICCwn/99dfTp08f/vSnP3H22WfTv39/GsZaEkuWLKFNmzYF7/Pkk09y2mmn7fE8b7/9Nj179ozbP3PmTF5++WXmzJlDTk4Obdu2LSj8/fv35+mnn6ZDhw7ccccdBa/561//Su3atZk+fTo7d+6kY8eOdO3adZ+GU65YsYIPP/yQjIwMNm3axNSpU6lcuTLvvfced911F6+99lrcaxYvXszkyZPZvHkzzZs359prr9WYfdl3U6fCbbfB7Nmh+ENoUV99dSj8F18MbdvCD38ITZuGlnlRnTqFTQqkTuGPSKtWrVi2bBljx47l/GL/uZxzzjksXbqUt99+m7feeouTTz6Z+fPnA/ve1XPZZZexa9cutmzZkvD4qVOn0qtXLw6JtRouuOACADZs2MDmzZvp0KEDAJdeeinjx48H4N1332XevHm8+uqrAGzcuJEvvvhinwr/RRddREZGRsHrrrzySr744gvMjOzs7ISv6datG9WqVaNatWocccQRrFq1ikaNGpV4Lkkz7qFFP2FC6B655Rbo0QNq1oTKleHGG+GUU0ILu1mzwu6QFi3CJvssdQr/3lrohxyy93i9evvcwk/kggsu4NZbb2XKlCmsXbt2t9jhhx/OpZdeyqWXXkr37t354IMPClrk++Kll16iXbt23Hbbbdxwww28/vrrB5xnPnfnySef5Jxzztnv19aoUaPg8d13380ZZ5zBG2+8wbJlyzg90acuoFqR/syMjAxycnL2+7ySwnbsgIcfhpdfhkWLwr6TTw6jW/If//vf0eWXgrQQSykYMGAA99xzDyeddNJu+//5z3+ybds2ADZv3sySJUto0qTJfr+/mXH//fczbdo0Fi9evFusU6dOvPnmm2zfvp3Nmzfzj3/8A4A6depQq1YtPv74YwBefvnlgtecc845PPXUUwUt9M8//5ytW7fud14bN24suJj93HPP7ffrJY3t2gX5gx2qVYPnnw/973/+c7gwO2tW4XBHKXUq/KWgUaNGCS9Yzpw5k6ysLFq1akWHDh0YOHAgp5xyClDYx5+//fGPf9zrOapXr84tt9yy2wVegLZt29KnTx9at27NeeedV/D+EPryr776atq0acPWrVupXbs2AAMHDuTEE0+kbdu2tGzZkmuuueaAWuG33347d955JyeffLJa8bJvNm2C3/8+XHw988zCMfGffgr/+le4Jld0RI2UiTJbiKU0JVqIZdGiRbRQv95ebdmyhZo1awIwfPhwVq5cyRNPPBFxVonp95niNm2Cxx6DJ54INyt16QI33QTnnBOGMEqZ2NNCLKnTxy9xJkyYwEMPPUROTg5HH320umMkOrNnhyGXPXrA0KHhIq1ERoU/hfXp04c+ffpEnYakq08+gY8+giFDoHNn+OwzOP74qLMS1McvIqVtxw64807o0CF07ezcGfar6FcYKvwiUnrmzoV27WD48DDVwezZu09PIBWCunpEpHSsXx/ukK1ZE956C849N+qMZA9U+EXk4OTPeXPYYfDcc/CTn4T5cqTCUlfPQTAzLr/88oLnOTk51K9fn+7duwOwatUqunfvTuvWrTnxxBMLpnRYtmwZ1atX320c/5gxY+Le//TTT6f4MNby8MADDxTklZGRsc/3GuQbOHAgCxcuLOMspULYtAm6doX8OZp69VLRTwJq8R+E8piWOQpDhw5l6NChANSsWTMuz/w5vSvtYfz1M8WnwJXU9N13cN55YX6dK6+MOhvZD2rxH6T8aZmBgmmZ861cuXK3ycgOZlrmfMuWLeO0006jbdu2tG3blg8//LDgXJ06daJNmza0bNmSqVOnkpubS79+/WjZsiUnnXQSjz32GABz5syhffv2tGrVil69erF+/fp9Om/z5s35xS9+QcuWLfnmm2+49tprycrK4kc/+hH33HNPwbFFP6nUrFmToUOH0rp1a9q3b8+qVasO+mcgFcDSpdCxI3z+OfzjH1Dkk68kgUSrs1S0bZ9W4OrcOX77859DbOvWxPHRo0N89er42D6oUaOGz50713v37u3bt2/31q1b++TJkwtW4Hr77be9du3afvrpp/uwYcP822+/dffEK3B98MEHce/fuXNnnz59+m77tm7d6tu3b3d3988//9zzfzaPPPKIDxs2zN3dc3JyfNOmTT5jxgw/++yzC16bv2LXSSed5FOmTHF397vvvtuHDBmy1+8xP2cz848++qggtnbt2oLzde7c2efOnRuXN+Djxo1zd/fbbrvN77///oTn0QpcSWTNGvcmTdzr1nWfNi3qbGQv0ApcZaOsp2UuLjs7m8GDBzNnzhwyMjL4/PPPATjllFMYM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B1XuI1Qaej8255IS53PNNjs07v9nMNgL/iO3/FGhV5LixEObRN7NDY/PGdCL8p4G7TzCz9UWOv9HMesUeNyZ0Ta2NPf8eaFjkuUhCavGLBHuabXM7YXbERO4nFPiWwM+KHVf0E0Jeked57N7gKj5nyh7nUIlNz3s20CG2YtTsYufMjOUrslcq/JLMpgJ9Ygtp1Ce0lD8hXMDtHevrbwCcvg/vNQ74Rey6QXtgo7uvJCw92XQPr6lN4VTM/Q7we8i/LvHT2Dk3EpaWvDS2/zwgf7RObUK30zYzO4GwhCGx44ywjsGyA8xD0ogKvySzN4B5wFzgn8Dtsem2XyP00S8EXgRmARsBzOzG2AyfjYB5sYunENZCWAp8SRjBcx2Au28FlpjZDxOc/2HgITObzYF3m+6IvX4kkD+T5n1AJzNbQOjyyV8n+m2gspktAoYTlsXM1w6YVmTJTJE90uyckpLMrKa7b4ld7PwE6HigazDE+tTbuftvSjXJUmRmTwDj3P39qHORik8XdyVVjY9dKK0K3H8wC++4+xtJMFpmvoq+7Cu1+EVE0oz6+EVE0owKv4hImlHhFxFJMyr8IiJpRoVfRCTN/D+ul/5ixPAjYgAAAABJRU5ErkJggg==\n", - "text/plain": [ - "
" - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "execution_count": null, + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "import os\n", "import numpy as np\n", @@ -1575,7 +1368,7 @@ " RegLasso = linear_model.Lasso(lmb)\n", " RegLasso.fit(X,y)\n", " ypredictLasso = RegLasso.predict(X)\n", - "# print(RegLasso.coef_)\n", + " print(RegLasso_coef_)\n", " MSELassoPredict[i] = MSE(y,ypredictLasso)\n", "# Now plot the results\n", "plt.figure()\n", @@ -1596,33 +1389,12 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[ 2.03099776 -0.17917768 5.18029127]\n", - "Training MSE for OLS\n", - "0.009163470508352228\n", - "Test MSE OLS\n", - "0.008675369724976777\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEKCAYAAAAVaT4rAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAA4aUlEQVR4nO3dd3hUZfbA8e9JIw2SkIRQAoQmJIQQSAIEpIggIBixgh0QWFcprsrqys+ya2PX3jsgLotigaULrkZUQOkISBEIEEQ6IUBIfX9/zBDSIJTM3MzM+TxPnszc95Yzk+Tknfe+91wxxqCUUspzeFkdgFJKKefSxK+UUh5GE79SSnkYTfxKKeVhNPErpZSH0cSvlFIexmGJX0Qmish+EVlfQduDImJEJMJRx1dKKVUxR/b4JwN9yy4UkYbAVcAuBx5bKaXUWTgs8RtjFgOHK2h6GfgroFeOKaWUBXyceTARuRbYY4xZKyLnvV1ERISJiYlxWFxKKeWOVq5cedAYE1l2udMSv4gEAo9iG+Y5n/VHAiMBGjVqxIoVKxwYnVJKuR8R2VnRcmfO6mkGNAHWikgGEA2sEpG6Fa1sjHnPGJNsjEmOjCz3D0sppdRFclqP3xjzC1Dn9HN78k82xhx0VgxKKaUcO51zGrAUaCkimSJyt6OOpZRS6vw5rMdvjLmlkvaYS9l/fn4+mZmZnDp16lJ2oyzm7+9PdHQ0vr6+VoeilMdw6qyeqpSZmUnNmjWJiYnhQmYIqerDGMOhQ4fIzMykSZMmVoejlMdw2ZINp06dIjw8XJO+CxMRwsPD9VObUk7msokf0KTvBvRnqJTzuXTiV0opt5STA19/DevWOWT3mvgvgYhw++23Fz8vKCggMjKSAQMGALBv3z4GDBhA27ZtiYuL4+qrrwYgIyODgIAAEhMTi7+mTJlSbv89evSgZcuWtG3blpSUFNasWVPcdvXVV3P06NFy2zz55JO88MILl/zajh49yltvvXVR254tNqXUebj5ZggNhd694c03HXIIlz25Wx0EBQWxfv16cnJyCAgIYNGiRTRo0KC4/fHHH6d3796MHTsWgHUl/ns3a9asVCI/m6lTp5KcnMykSZMYN24cixYtAmDevHlV+2LKOJ3477333nJtBQUF+Pic/VfH0bEp5TZ27oSPP4YffoD580EE4uOhcWPo2RO6dnXIYbXHf4muvvpq5s6dC8C0adO45ZYzs1j37t1LdHR08fOEhISLPk5qaip79uwpfh4TE8PBg7Zr35555hkuu+wyLr/8cjZv3ly8zvLly0lISCAxMZFx48YRHx8PQGFhIePGjSMlJYWEhATefffdcsd75JFH2LZtW/G26enpdO3albS0NOLi4gAYOHAgSUlJtG7dmvfee69cbBkZGcTGxjJixAhat27NVVddRU5OzkW/B0q5hYIC+OwzW2KPiYHHHrMN7Zz+lPz44/D889CvH3sLvcktKKzyENyix//32RvY+PuxKt1nXP1aPHFN60rXGzx4MP/4xz8YMGAA69atY9iwYXz//fcA3HfffQwaNIg33niDXr16MXToUOrXrw9QnFRPe/311+l6jv/uCxYsYODAgeWWr1y5kk8++YQ1a9ZQUFBA+/btSUpKAmDo0KG8//77pKam8sgjjxRv8+GHHxISEsLy5cvJzc2lS5cuXHXVVaWmVE6YMIH169cXfypJT09n1apVrF+/vni9iRMnUrt2bXJyckhJSeGGG24gPDy8VHxbt25l2rRpvP/++9x888188cUXpYbHlPI4M2fahnOaNIF//APuuMP2DwA4diqf77ccZMm2gyzZdogdB08wdXhHujSv2luXuEXit1JCQgIZGRlMmzateAz/tD59+rB9+3YWLFjA/PnzadeuHevX2+5Lc75DPbfddht5eXkcP368wvW///57rrvuOgIDAwFIS0sDbEM12dnZpKamAnDrrbcyZ84cABYuXMi6dev4/PPPAcjKymLr1q2VzqXv0KFDqXVee+01ZsyYAcDu3bvZunVrucTfpEmT4n9wSUlJZGRkVPqalXIrOTm2sfpatWDkSLj2Wpg9G/r1A29vDmTnMn9pBos27mPptkMUFBmCa/jQsUltbuvYiKaRQVUeklsk/vPpmTtSWloaDz30EOnp6Rw6dKhUW+3atbn11lu59dZbGTBgAIsXLy7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RERm2o+dYf+U8YB9vWUiUrvEbu6wX8y0XkQ62LcPF9v9GTaIyAeAlDjmTBFZaW8bWWI/s4BbLva9VJ5FE79yZddjq6HeFlsv/nl7sr4eiMFWJ/8ObFf6VqbCapsi0gQ4YozJrWCbTUBXY0w7bJVVny3RFm+PIwV4BjhpX28pcGeJ9QLt92O4F5hoX/YE8IMxpjUwA2hUYv1hxpgkIBkYIyLhAMaYI0CN08+VOhe3KdKmPNLlwDR7dcV9IvIdtkR7OfCZMaYI+MNeeOti1QMOnKUtBPjIXnPJYKvlftq39rrz2SKSBcy2L/8FSCix3jSw1dEXkVr2ujHdsP3TwBgzV0SOlFh/jIhcZ3/cENvQ1CH78/1A/RLPlaqQ9viVsjlbtc0cbNURK/IUtgQfD1xTZr2SnxCKSjwvonSHq2zNlLPWULGX5+0FpNrvGLW6zDH97fEqdU6a+JUr+x4YZL+RRiS2nvLP2E7g3mAf648CepzHvmYBd9rPG3QCsowxe7HdejLmLNuEcKYU85CLfA2nz0tcbj9mFrZbS95qX94POD1bJwTbsNNJEWmF7RaG2NcTbPcxyLjIOJQH0cSvXNkMYB2wFvgG+Ku93PYX2MboNwL/BlYBWQAiMsZe4TMaWGc/eQq2eyFsB37DNoPnXgBjzAlgm4g0r+D4/wKeE5HVXPyw6Sn79u8Apytp/h3oJiIbsA35nL5P9ALAR0R+BSZguy3maUnAshK3zFTqrLQ6p3JLIhJsjDluP9n5M9DlYu/BYB9TTzLG/F+VBlmFRORVYJYx5n9Wx6KqPz25q9zVHPuJUj/gqUu58Y4xZoYLzJZZr0lfnS/t8SullIfRMX6llPIwmviVUsrDaOJXSikPo4lfKaU8jCZ+pZTyMJr4lVLKw/w/y8f9sS3i/8EAAAAASUVORK5CYII=\n", - "text/plain": [ - "
" - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "execution_count": null, + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], "source": [ "import os\n", "import numpy as np\n", @@ -1711,6 +1483,14 @@ "\n", "## Linking the regression analysis with a statistical interpretation\n", "\n", + "We will now couple the discussions of ordinary least squares, Ridge\n", + "and Lasso regression with a statistical interpretation, that is we\n", + "move from a linear algebra analysis to a statistical analysis. In\n", + "particular, we will focus on what the regularization terms can result\n", + "in. We will amongst other things show that the regularization\n", + "parameter can reduce considerably the variance of the parameters\n", + "$\\beta$.\n", + "\n", "\n", "The\n", "advantage of doing linear regression is that we actually end up with\n", @@ -2424,7 +2204,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "from numpy import *\n", @@ -2565,7 +2348,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "from numpy import *\n", @@ -2711,7 +2497,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import numpy as np\n", @@ -2940,7 +2729,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -3009,7 +2801,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -3108,7 +2903,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "\"\"\"\n", @@ -3194,7 +2992,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# Common imports\n", @@ -3288,7 +3089,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "# Common imports\n", @@ -3370,7 +3174,10 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": false, + "editable": true + }, "outputs": [], "source": [ "import numpy as np\n", @@ -3411,25 +3218,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 } diff --git a/doc/src/week36/add.do.txt b/doc/src/week36/add.do.txt new file mode 100644 index 000000000..96697790e --- /dev/null +++ b/doc/src/week36/add.do.txt @@ -0,0 +1,2249 @@ +TITLE: Week 36: Statistical interpretation of Linear Regression and Resampling techniques +AUTHOR: Morten Hjorth-Jensen {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +DATE: today + + +!split +===== Plans for week 36 ===== + +* Thursday: Summary from last week on SVD, Statistics, probability theory and linear regression +* Friday: Linear Regression and links with Statistics, Resampling methods and presentation of first project. + +Recommended Reading: +o Lectures on Regression +o Bishop 1.1, 1.2, 2.1, 2.2, 2.3 and 3.1 +o Hastie et al chapter 3 + + +!split +===== Thursday September 9 ===== + + +!split +===== Summary from last Week and Examples ===== + +!split +===== Linear Regression and the SVD ===== + +We used the SVD to analyse the matrix to invert in ordinary lineat regression +!bt +\[ +\bm{X}^T\bm{X}=\bm{V}\bm{\Sigma}^T\bm{U}^T\bm{U}\bm{\Sigma}\bm{V}^T=\bm{V}\bm{\Sigma}^T\bm{\Sigma}\bm{V}^T. +\] +!et +Since the matrices here have dimension $p\times p$, with $p$ corresponding to the singular values, we defined last week the matrix +!bt +\[ +\bm{\Sigma}^T\bm{\Sigma} = \begin{bmatrix} \tilde{\bm{\Sigma}} & \bm{0}\\ \end{bmatrix}\begin{bmatrix} \tilde{\bm{\Sigma}} \\ \bm{0}\end{bmatrix}, +\] +!et +where the tilde-matrix $\tilde{\bm{\Sigma}}$ is a matrix of dimension $p\times p$ containing only the singular values $\sigma_i$, that is + +!bt +\[ +\tilde{\bm{\Sigma}}=\begin{bmatrix} \sigma_0 & 0 & 0 & \dots & 0 & 0 \\ + 0 & \sigma_1 & 0 & \dots & 0 & 0 \\ + 0 & 0 & \sigma_2 & \dots & 0 & 0 \\ + 0 & 0 & 0 & \dots & \sigma_{p-2} & 0 \\ + 0 & 0 & 0 & \dots & 0 & \sigma_{p-1} \\ +\end{bmatrix}, +\] +!et +meaning we can write +!bt +\[ +\bm{X}^T\bm{X}=\bm{V}\tilde{\bm{\Sigma}}^2\bm{V}^T. +\] +!et +Multiplying from the right with $\bm{V}$ (using the orthogonality of $\bm{V}$) we get +!bt +\[ +\left(\bm{X}^T\bm{X}\right)\bm{V}=\bm{V}\tilde{\bm{\Sigma}}^2. +\] +!et + +!split +===== What does it mean? ===== + +This means the vectors $\bm{v}_i$ of the orthogonal matrix $\bm{V}$ +are the eigenvectors of the matrix $\bm{X}^T\bm{X}$ with eigenvalues +given by the singular values squared, that is + +!bt +\[ +\left(\bm{X}^T\bm{X}\right)\bm{v}_i=\bm{v}_i\sigma_i^2. +\] +!et + +In other words, each non-zero singular value of $\bm{X}$ is a positive +square root of an eigenvalue of $\bm{X}^T\bm{X}$. It means also that +the columns of $\bm{V}$ are the eigenvectors of +$\bm{X}^T\bm{X}$. Since we have ordered the singular values of +$\bm{X}$ in a descending order, it means that the column vectors +$\bm{v}_i$ are hierarchically ordered by how much correlation they +encode from the columns of $\bm{X}$. + + +Note that these are also the eigenvectors and eigenvalues of the +Hessian matrix. + +If we now recall the definition of the covariance matrix (not using +Bessel's correction) we have + + +!bt +\[ +\bm{C}[\bm{X}]=\frac{1}{n}\bm{X}^T\bm{X}, +\] +!et + +meaning that every squared non-singular value of $\bm{X}$ divided by $n$ ( +the number of samples) are the eigenvalues of the covariance +matrix. Every singular value of $\bm{X}$ is thus a positive square +root of an eigenvalue of $\bm{X}^T\bm{X}$. If the matrix $\bm{X}$ is +self-adjoint, the singular values of $\bm{X}$ are equal to the +absolute value of the eigenvalues of $\bm{X}$. + +!split +===== And finally $\bm{X}\bm{X}^T$ ===== + +For $\bm{X}\bm{X}^T$ we found + +!bt +\[ +\bm{X}\bm{X}^T=\bm{U}\bm{\Sigma}\bm{V}^T\bm{V}\bm{\Sigma}^T\bm{U}^T=\bm{U}\bm{\Sigma}^T\bm{\Sigma}\bm{U}^T. +\] +!et +Since the matrices here have dimension $n\times n$, we have +!bt +\[ +\bm{\Sigma}\bm{\Sigma}^T = \begin{bmatrix} \tilde{\bm{\Sigma}} \\ \bm{0}\\ \end{bmatrix}\begin{bmatrix} \tilde{\bm{\Sigma}} \bm{0}\\ \end{bmatrix}=\begin{bmatrix} \tilde{\bm{\Sigma}} & \bm{0} \\ \bm{0} & \bm{0}\\ \end{bmatrix}, +\] +!et +leading to +!bt +\[ +\bm{X}\bm{X}^T=\bm{U}\begin{bmatrix} \tilde{\bm{\Sigma}} & \bm{0} \\ \bm{0} & \bm{0}\\ \end{bmatrix}\bm{U}^T. +\] +!et + +Multiplying with $\bm{U}$ from the right gives us the eigenvalue problem +!bt +\[ +(\bm{X}\bm{X}^T)\bm{U}=\bm{U}\begin{bmatrix} \tilde{\bm{\Sigma}} & \bm{0} \\ \bm{0} & \bm{0}\\ \end{bmatrix}. +\] +!et + +It means that the eigenvalues of $\bm{X}\bm{X}^T$ are again given by +the non-zero singular values plus now a series of zeros. The column +vectors of $\bm{U}$ are the eigenvectors of $\bm{X}\bm{X}^T$ and +measure how much correlations are contained in the rows of $\bm{X}$. + +Since we will mainly be interested in the correlations among the features +of our data (the columns of $\bm{X}$, the quantity of interest for us are the non-zero singular +values and the column vectors of $\bm{V}$. + + + +!split +===== Code for SVD and Inversion of Matrices ===== + +How do we use the SVD to invert a matrix $\bm{X}^\bm{X}$ which is singular or near singular? +The simple answer is to use the linear algebra function for pseudoinvers, that is +!bc pycod +Ainv = np.linlag.pinv(A) +!ec + +Let us first look at a matrix which does not causes problems and write our own function where we just use the SVD. + +!bc pycod +import numpy as np +# SVD inversion +def SVDinv(A): + ''' Takes as input a numpy matrix A and returns inv(A) based on singular value decomposition (SVD). + SVD is numerically more stable than the inversion algorithms provided by + numpy and scipy.linalg at the cost of being slower. + ''' + U, s, VT = np.linalg.svd(A) + print('test U') + print( (np.transpose(U) @ U - U @np.transpose(U))) + print('test VT') + print( (np.transpose(VT) @ VT - VT @np.transpose(VT))) + + + D = np.zeros((len(U),len(VT))) + D = np.diag(s) + UT = np.transpose(U); V = np.transpose(VT); invD = np.linalg.inv(D) + return np.matmul(V,np.matmul(invD,UT)) + + +#X = np.array([ [1.0, -1.0, 2.0], [1.0, 0.0, 1.0], [1.0, 2.0, -1.0], [1.0, 1.0, 0.0] ]) +# Non-singular square matrix +X = np.array( [ [1,2,3],[2,4,5],[3,5,6]]) +print(X) +A = np.transpose(X) @ X +# Brute force inversion +B = np.linalg.inv(A) # here we could use np.linalg.pinv(A) +C = SVDinv(A) +print(np.abs(B-C)) + +!ec + +!split +===== Inverse of Rectangular Matrix ===== + +Although our matrix to invert $\bm{X}^T\bm{X}$ is a square matrix, our matrix may be singular. + +The pseudoinverse is the generalization of the matrix inverse for square matrices to +rectangular matrices where the number of rows and columns are not equal. + +It is also called the the Moore-Penrose Inverse after two independent discoverers of the method or the Generalized Inverse. +It is used for the calculation of the inverse for singular or near singular matrices and for rectangular matrices. + +Using the SVD we can obtain the pseudoinverse of a matrix $\bm{A}$ (labeled here as $\bm{A}_{\mathrm{PI}}$ +!bt +\[ +\bm{A}_{\mathrm{PI}}= \bm{V}\bm{D}_{\mathrm{PI}}\bm{U}^T, +\] +!et +where $\bm{D}_{\mathrm{PI}}$ can be calculated by creating a diagonal matrix from $\bm{Sigma}$ where we only keep the singular values (the non-zero values). The following code computes the pseudoinvers of the matrix based on the SVD. + + +!bc pycod +import numpy as np +# SVD inversion +def SVDinv(A): + U, s, VT = np.linalg.svd(A) + # reciprocals of singular values of s + d = 1.0 / s + # create m x n D matrix + D = np.zeros(A.shape) + # populate D with n x n diagonal matrix + D[:A.shape[1], :A.shape[1]] = np.diag(d) + UT = np.transpose(U) + V = np.transpose(VT) + return np.matmul(V,np.matmul(D.T,UT)) + + +A = np.array([ [0.3, 0.4], [0.5, 0.6], [0.7, 0.8],[0.9, 1.0]]) +print(A) +# Brute force inversion of super-collinear matrix +B = np.linalg.pinv(A) +print(B) +# Compare our own algorithm with pinv +C = SVDinv(A) +print(np.abs(C-B)) + +!ec +As you can see from this example, our own decomposition based on the SVD agrees the pseudoinverse algorithm provided by _Numpy_. + + + +!split +===== Ridge and LASSO Regression ===== + +Let us remind ourselves about the expression for the standard Mean Squared Error (MSE) which we used to define our cost function and the equations for the ordinary least squares (OLS) method, that is +our optimization problem is +!bt +\[ +{\displaystyle \min_{\bm{\beta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\beta}\right)^T\left(\bm{y}-\bm{X}\bm{\beta}\right)\right\}. +\] +!et +or we can state it as +!bt +\[ +{\displaystyle \min_{\bm{\beta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2, +\] +!et +where we have used the definition of a norm-2 vector, that is +!bt +\[ +\vert\vert \bm{x}\vert\vert_2 = \sqrt{\sum_i x_i^2}. +\] +!et + +!split +===== From OLS to Ridge and Lasso ===== + +By minimizing the above equation with respect to the parameters +$\bm{\beta}$ we could then obtain an analytical expression for the +parameters $\bm{\beta}$. We can add a regularization parameter $\lambda$ by +defining a new cost function to be optimized, that is + +!bt +\[ +{\displaystyle \min_{\bm{\beta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_2^2 +\] +!et + +which leads to the Ridge regression minimization problem where we +require that $\vert\vert \bm{\beta}\vert\vert_2^2\le t$, where $t$ is +a finite number larger than zero. By defining + +!bt +\[ +C(\bm{X},\bm{\beta})=\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_1, +\] +!et + +we have a new optimization equation +!bt +\[ +{\displaystyle \min_{\bm{\beta}\in +{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_1 +\] +!et +which leads to Lasso regression. Lasso stands for least absolute shrinkage and selection operator. + +Here we have defined the norm-1 as +!bt +\[ +\vert\vert \bm{x}\vert\vert_1 = \sum_i \vert x_i\vert. +\] +!et + + +!split +===== Deriving the Ridge Regression Equations ===== + +Using the matrix-vector expression for Ridge regression and dropping the parameter $1/n$ in front of the standard means squared error equation, we have + +!bt +\[ +C(\bm{X},\bm{\beta})=\left\{(\bm{y}-\bm{X}\bm{\beta})^T(\bm{y}-\bm{X}\bm{\beta})\right\}+\lambda\bm{\beta}^T\bm{\beta}, +\] +!et +and +taking the derivatives with respect to $\bm{\beta}$ we obtain then +a slightly modified matrix inversion problem which for finite values +of $\lambda$ does not suffer from singularity problems. We obtain +the optimal parameters +!bt +\[ +\hat{\bm{\beta}}_{\mathrm{Ridge}} = \left(\bm{X}^T\bm{X}+\lambda\bm{I}\right)^{-1}\bm{X}^T\bm{y}, +\] +!et + +with $\bm{I}$ being a $p\times p$ identity matrix with the constraint that + +!bt +\[ +\sum_{i=0}^{p-1} \beta_i^2 \leq t, +\] +!et + +with $t$ a finite positive number. + +When we compare this with the ordinary least squares result we have +!bt +\[ +\hat{\bm{\beta}}_{\mathrm{OLS}} = \left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}, +\] +!et +which can lead to singular matrices. However, with the SVD, we can always compute the inverse of the matrix $\bm{X}^T\bm{X}$. + + +We see that Ridge regression is nothing but the standard OLS with a +modified diagonal term added to $\bm{X}^T\bm{X}$. The consequences, in +particular for our discussion of the bias-variance tradeoff are rather +interesting. We will see that for specific values of $\lambda$, we may +even reduce the variance of the optimal parameters $\bm{\beta}$. These topics and other related ones, will be discussed after the more linear algebra oriented analysis here. + +!split +===== SVD analysis ===== + +Using our insights about the SVD of the design matrix $\bm{X}$ +We have already analyzed the OLS solutions in terms of the eigenvectors (the columns) of the right singular value matrix $\bm{U}$ as +!bt +\[ +\tilde{\bm{y}}_{\mathrm{OLS}}=\bm{X}\bm{\beta} =\bm{U}\bm{U}^T\bm{y}. +\] +!et + + +For Ridge regression this becomes + +!bt +\[ +\tilde{\bm{y}}_{\mathrm{Ridge}}=\bm{X}\bm{\beta}_{\mathrm{Ridge}} = \bm{U\Sigma V^T}\left(\bm{V}\bm{\Sigma}^2\bm{V}^T+\lambda\bm{I} \right)^{-1}(\bm{U\Sigma V^T})^T\bm{y}=\sum_{j=0}^{p-1}\bm{u}_j\bm{u}_j^T\frac{\sigma_j^2}{\sigma_j^2+\lambda}\bm{y}, +\] +!et + +with the vectors $\bm{u}_j$ being the columns of $\bm{U}$ from the SVD of the matrix $\bm{X}$. + +!split +===== Interpreting the Ridge results ===== + +Since $\lambda \geq 0$, it means that compared to OLS, we have + +!bt +\[ +\frac{\sigma_j^2}{\sigma_j^2+\lambda} \leq 1. +\] +!et + +Ridge regression finds the coordinates of $\bm{y}$ with respect to the +orthonormal basis $\bm{U}$, it then shrinks the coordinates by +$\frac{\sigma_j^2}{\sigma_j^2+\lambda}$. Recall that the SVD has +eigenvalues ordered in a descending way, that is $\sigma_i \geq +\sigma_{i+1}$. + +For small eigenvalues $\sigma_i$ it means that their contributions become less important, a fact which can be used to reduce the number of degrees of freedom. More about this when we have covered the material on a statistical interpretation of various linear regression methods. + + +!split +===== More interpretations ===== + +For the sake of simplicity, let us assume that the design matrix is orthonormal, that is + +!bt +\[ +\bm{X}^T\bm{X}=(\bm{X}^T\bm{X})^{-1} =\bm{I}. +\] +!et + +In this case the standard OLS results in +!bt +\[ +\bm{\beta}^{\mathrm{OLS}} = \bm{X}^T\bm{y}=\sum_{i=0}^{p-1}\bm{u}_j\bm{u}_j^T\bm{y}, +\] +!et + +and + +!bt +\[ +\bm{\beta}^{\mathrm{Ridge}} = \left(\bm{I}+\lambda\bm{I}\right)^{-1}\bm{X}^T\bm{y}=\left(1+\lambda\right)^{-1}\bm{\beta}^{\mathrm{OLS}}, +\] +!et + +that is the Ridge estimator scales the OLS estimator by the inverse of a factor $1+\lambda$, and +the Ridge estimator converges to zero when the hyperparameter goes to +infinity. + +We will come back to more interpreations after we have gone through some of the statistical analysis part. + +For more discussions of Ridge and Lasso regression, "Wessel van Wieringen's":"https://arxiv.org/abs/1509.09169" article is highly recommended. +Similarly, "Mehta et al's article":"https://arxiv.org/abs/1803.08823" is also recommended. + +!split +===== Deriving the Lasso Regression Equations ===== + +Using the matrix-vector expression for Lasso regression and dropping the parameter $1/n$ in front of the standard mean squared error equation, we have the following _cost_ function + +!bt +\[ +C(\bm{X},\bm{\beta})=\left\{(\bm{y}-\bm{X}\bm{\beta})^T(\bm{y}-\bm{X}\bm{\beta})\right\}+\lambda\vert\vert\bm{\beta}\vert\vert_1, +\] +!et + +Taking the derivative with respect to $\bm{\beta}$ and recalling that the derivative of the absolute value is (we drop the boldfaced vector symbol for simplicty) +!bt +\[ +\frac{d \vert \beta\vert}{d \bm{\beta}}=\mathrm{sgn}(\bm{\beta})=\left\{\begin{array}{cc} 1 & \beta > 0 \\ 0 & \beta =0\\-1 & \beta < 0, \end{array}\right. +\] +!et +we have that the derivative of the cost function is + +!bt +\[ +\frac{\partial C(\bm{X},\bm{\beta})}{\partial \bm{\beta}}=-2\bm{X}^T(\bm{y}-\bm{X}\bm{\beta})+\lambda sgn(\bm{\beta})=0, +\] +!et +and reordering we have +!bt +\[ +\bm{X}^T\bm{X}\bm{\beta}+\lambda sgn(\bm{\beta})=2\bm{X}^T\bm{y}. +\] +!et +This equation does not lead to a nice analytical equation as in Ridge regression or ordinary least squares. This equation can however be solved by using standard convex optimization algorithms using for example the Python package "CVXOPT":"https://cvxopt.org/". We will discuss this later. + + + + +!split +===== Simple example to illustrate Ordinary Least Squares, Ridge and Lasso Regression ===== + +Let us assume that our design matrix is given by unit (identity) matrix, that is a square diagonal matrix with ones only along the +diagonal. In this case we have an equal number of rows and columns $n=p$. + +Our model approximation is just $\tilde{\bm{y}}=\bm{\beta}$ and the mean squared error and thereby the cost function for ordinary least sqquares (OLS) is then (we drop the term $1/n$) +!bt +\[ +C(\bm{\beta})=\sum_{i=0}^{p-1}(y_i-\beta_i)^2, +\] +!et +and minimizing we have that +!bt +\[ +\hat{\beta}_i^{\mathrm{OLS}} = y_i. +\] +!et + +!split +===== Ridge Regression ===== + +For Ridge regression our cost function is +!bt +\[ +C(\bm{\beta})=\sum_{i=0}^{p-1}(y_i-\beta_i)^2+\lambda\sum_{i=0}^{p-1}\beta_i^2, +\] +!et +and minimizing we have that +!bt +\[ +\hat{\beta}_i^{\mathrm{Ridge}} = \frac{y_i}{1+\lambda}. +\] +!et + + +!split +===== Lasso Regression ===== + +For Lasso regression our cost function is +!bt +\[ +C(\bm{\beta})=\sum_{i=0}^{p-1}(y_i-\beta_i)^2+\lambda\sum_{i=0}^{p-1}\vert\beta_i\vert=\sum_{i=0}^{p-1}(y_i-\beta_i)^2+\lambda\sum_{i=0}^{p-1}\sqrt{\beta_i^2}, +\] +!et +and minimizing we have that +!bt +\[ +-2\sum_{i=0}^{p-1}(y_i-\beta_i)+\lambda \sum_{i=0}^{p-1}\frac{(\beta_i)}{\vert\beta_i\vert}=0, +\] +!et +which leads to +!bt +\[ +\hat{\bm{\beta}}_i^{\mathrm{Lasso}} = \left\{\begin{array}{ccc}y_i-\frac{\lambda}{2} &\mathrm{if} & y_i> \frac{\lambda}{2}\\ + y_i+\frac{\lambda}{2} &\mathrm{if} & y_i< -\frac{\lambda}{2}\\ + 0 &\mathrm{if} & \vert y_i\vert\le \frac{\lambda}{2}\end{array}\right.\\. +\] +!et + +Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of $\beta_i$ for specific values of $\lambda$. Ridge regression reduces on the other hand the values of $\beta_i$ as function of $\lambda$. + +We will now couple the discussions of ordinary least squares, Ridge and Lasso regression with a statistical interpretation, that is we move from a linear algebra analysis to a statistical analysis. In particular, we will focus on what the regularization terms can result in. +We will amongst other things show that the regularization parameter can reduce considerably the variance of the parameters $\beta$. + + +!split +===== Yet another Example ===== + +Let us assume we have a data set with outputs/targets given by the vector + +!bt +\[ +\bm{y}=\begin{bmatrix}4 \\ 2 \\3\end{bmatrix}, +\] +!et +and our inputs as a $3\times 2$ design matrix +!bt +\[ +\bm{X}=\begin{bmatrix}2 & 0\\ 0 & 1 \\ 0 & 0\end{bmatrix}, +\] +!et +meaning that we have two features and two unknown parameters $\beta_0$ and $\beta_1$ to be determined either by ordinary least squares, Ridge or Lasso regression. + +!split +===== The OLS case ===== + +For ordinary least squares (OLS) we know that the optimal solution is + +!bt +\[ +\hat{\bm{\beta}}^{\mathrm{OLS}}=\left( \bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}. +\] +!et +Inserting the above values we obtain that + +!bt +\[ +\hat{\bm{\beta}}^{\mathrm{OLS}}=\begin{bmatrix}2 \\ 2\end{bmatrix}, +\] +!et + +The code which implements this simpler case is presented after the discussion of Ridge and Lasso. + +!split +===== The Ridge case ===== + +For Ridge regression we have + +!bt +\[ +\hat{\bm{\beta}}^{\mathrm{Ridge}}=\left( \bm{X}^T\bm{X}+\lambda\bm{I}\right)^{-1}\bm{X}^T\bm{y}. +\] +!et +Inserting the above values we obtain that + +!bt +\[ +\hat{\bm{\beta}}^{\mathrm{Ridge}}=\begin{bmatrix}\frac{8}{4+\lambda} \\ \frac{2}{1+\lambda}\end{bmatrix}, +\] +!et + +There is normally a constraint on the value of $\vert\vert \bm{\beta}\vert\vert_2$ via the parameter $\lambda$. +Let us for simplicity assume that $\beta_0^2+\beta_1^2=1$ as constraint. This will allow us to find an expression for the optimal values of $\beta$ and $\lambda$. + +To see this, let us write the cost function for Ridge regression. + + +!split +===== Writing the Cost Function ===== + +We define the MSE without the $1/n$ factor and have then, using that +!bt +\[ +\bm{X}\bm{\beta}=\begin{bmatrix} 2\beta_0 \\ \beta_1 \\0 \end{bmatrix}, +\] +!et + +!bt +\[ +C(\bm{\beta})=(4-2\beta_0)^2+(2-\beta_1)^2+\lambda(\beta_0^2+\beta_1^2), +\] +!et +and taking the derivative with respect to $\beta_0$ we get +!bt +\[ +\beta_0=\frac{8}{4+\lambda}, +\] +!et +and for $\beta_1$ we obtain +!bt +\[ +\beta_1=\frac{2}{1+\lambda}, +\] +!et + +Using the constraint for $\beta_0^2+\beta_1^2=1$ we can constrain $\lambda$ by solving +!bt +\[ +\left(\frac{8}{4+\lambda}\right)^2+\left(\frac{2}{1+\lambda}\right)^2=1, +\] +!et +which gives $\lambda=4.571$ and $\beta_0=0.933$ and $\beta_1=0.359$. + +!split +===== Lasso case ===== + +For Lasso we need now, keeping a constraint on $\vert\beta_0\vert+\vert\beta_1\vert=1$, to take the derivative of the absolute values of $\beta_0$ +and $\beta_1$. This gives us the following derivatives of the cost function +!bt +\[ +C(\bm{\beta})=(4-2\beta_0)^2+(2-\beta_1)^2+\lambda(\vert\beta_0\vert+\vert\beta_1\vert), +\] +!et + +!bt +\[ +\frac{\partial C(\bm{\beta})}{\partial \beta_0}=-4(4-2\beta_0)+\lambda\mathrm{sgn}(\beta_0)=0, +\] +!et +and +!bt +\[ +\frac{\partial C(\bm{\beta})}{\partial \beta_1}=-2(2-\beta_1)+\lambda\mathrm{sgn}(\beta_1)=0. +\] +!et +We have now four cases to solve besides the trivial cases $\beta_0$ and/or $\beta_1$ are zero, namely +o $\beta_0 > 0$ and $\beta_1 > 0$, +o $\beta_0 > 0$ and $\beta_1 < 0$, +o $\beta_0 < 0$ and $\beta_1 > 0$, +o $\beta_0 < 0$ and $\beta_1 < 0$. + +!split +===== The first Case ===== + +If we consider the first case, we have then +!bt +\[ +-4(4-2\beta_0)+\lambda=0, +\] +!et +and +!bt +\[ +-2(2-\beta_1)+\lambda=0. +\] +!et +which yields + +!bt +\[ +\beta_0=\frac{16+\lambda}{8}, +\] +!et +and +!bt +\[ +\beta_1=\frac{4+\lambda}{2}. +\] +!et + +Using the constraint on $\beta_0$ and $\beta_1$ we can then find the optimal value of $\lambda$ for the different cases. We leave this as an exercise to you. + +!split +===== Simple code for solving the above problem ===== + +Here we set up the OLS, Ridge and Lasso functionality in order to study the above example. Note that here we have opted for a set of values of $\lambda$, meaning that we need to perform a search in order to find the optimal values. + +First we study and compare the OLS and Ridge results. The next code compares all three methods. + + +!bc pycod +import os +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +def R2(y_data, y_model): + return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2) +def MSE(y_data,y_model): + n = np.size(y_model) + return np.sum((y_data-y_model)**2)/n + + +# A seed just to ensure that the random numbers are the same for every run. +# Useful for eventual debugging. + +X = np.array( [ [ 2, 0], [0, 1], [0,0]]) +y = np.array( [4, 2, 3]) + + +# matrix inversion to find beta +OLSbeta = np.linalg.inv(X.T @ X) @ X.T @ y +print(OLSbeta) +# and then make the prediction +ytildeOLS = X @ OLSbeta +print("Training MSE for OLS") +print(MSE(y,ytildeOLS)) +ypredictOLS = X @ OLSbeta + +# Repeat now for Ridge regression and various values of the regularization parameter +I = np.eye(2,2) +# Decide which values of lambda to use +nlambdas = 100 +MSEPredict = np.zeros(nlambdas) +lambdas = np.logspace(-4, 4, nlambdas) +for i in range(nlambdas): + lmb = lambdas[i] + Ridgebeta = np.linalg.inv(X.T @ X+lmb*I) @ X.T @ y +# print(Ridgebeta) + # and then make the prediction + ypredictRidge = X @ Ridgebeta + MSEPredict[i] = MSE(y,ypredictRidge) +# print(MSEPredict[i]) + # Now plot the results +plt.figure() +plt.plot(np.log10(lambdas), MSEPredict, 'r--', label = 'MSE Ridge Test') +plt.xlabel('log10(lambda)') +plt.ylabel('MSE') +plt.legend() +plt.show() + +!ec + +We see here that we reach a plateau. What is actually happening? + + +!split +===== With Lasso Regression ===== + +!bc pycod +import os +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt +from sklearn import linear_model + +def R2(y_data, y_model): + return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2) +def MSE(y_data,y_model): + n = np.size(y_model) + return np.sum((y_data-y_model)**2)/n + + +# A seed just to ensure that the random numbers are the same for every run. +# Useful for eventual debugging. + +X = np.array( [ [ 2, 0], [0, 1], [0,0]]) +y = np.array( [4, 2, 3]) + + +# matrix inversion to find beta +OLSbeta = np.linalg.inv(X.T @ X) @ X.T @ y +print(OLSbeta) +# and then make the prediction +ytildeOLS = X @ OLSbeta +print("Training MSE for OLS") +print(MSE(y,ytildeOLS)) +ypredictOLS = X @ OLSbeta + +# Repeat now for Ridge regression and various values of the regularization parameter +I = np.eye(2,2) +# Decide which values of lambda to use +nlambdas = 100 +MSERidgePredict = np.zeros(nlambdas) +MSELassoPredict = np.zeros(nlambdas) +lambdas = np.logspace(-4, 4, nlambdas) +for i in range(nlambdas): + lmb = lambdas[i] + Ridgebeta = np.linalg.inv(X.T @ X+lmb*I) @ X.T @ y + print(Ridgebeta) + # and then make the prediction + ypredictRidge = X @ Ridgebeta + MSERidgePredict[i] = MSE(y,ypredictRidge) + RegLasso = linear_model.Lasso(lmb) + RegLasso.fit(X,y) + ypredictLasso = RegLasso.predict(X) + print(RegLasso_coef_) + MSELassoPredict[i] = MSE(y,ypredictLasso) +# Now plot the results +plt.figure() +plt.plot(np.log10(lambdas), MSERidgePredict, 'r--', label = 'MSE Ridge Train') +plt.plot(np.log10(lambdas), MSELassoPredict, 'r--', label = 'MSE Lasso Train') +plt.xlabel('log10(lambda)') +plt.ylabel('MSE') +plt.legend() +plt.show() + +!ec + +!split +===== Another Example, now with a polynomial fit ===== + +!bc pycod +import os +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt +from sklearn.model_selection import train_test_split +from sklearn import linear_model + +def R2(y_data, y_model): + return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2) +def MSE(y_data,y_model): + n = np.size(y_model) + return np.sum((y_data-y_model)**2)/n + + +# A seed just to ensure that the random numbers are the same for every run. +# Useful for eventual debugging. +np.random.seed(3155) + +x = np.random.rand(100) +y = 2.0+5*x*x+0.1*np.random.randn(100) + +# number of features p (here degree of polynomial +p = 3 +# The design matrix now as function of a given polynomial +X = np.zeros((len(x),p)) +X[:,0] = 1.0 +X[:,1] = x +X[:,2] = x*x +# We split the data in test and training data +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) + +# matrix inversion to find beta +OLSbeta = np.linalg.inv(X_train.T @ X_train) @ X_train.T @ y_train +print(OLSbeta) +# and then make the prediction +ytildeOLS = X_train @ OLSbeta +print("Training MSE for OLS") +print(MSE(y_train,ytildeOLS)) +ypredictOLS = X_test @ OLSbeta +print("Test MSE OLS") +print(MSE(y_test,ypredictOLS)) + +# Repeat now for Lasso and Ridge regression and various values of the regularization parameter +I = np.eye(p,p) +# Decide which values of lambda to use +nlambdas = 100 +MSEPredict = np.zeros(nlambdas) +MSETrain = np.zeros(nlambdas) +MSELassoPredict = np.zeros(nlambdas) +MSELassoTrain = np.zeros(nlambdas) +lambdas = np.logspace(-4, 4, nlambdas) +for i in range(nlambdas): + lmb = lambdas[i] + Ridgebeta = np.linalg.inv(X_train.T @ X_train+lmb*I) @ X_train.T @ y_train + # include lasso using Scikit-Learn + RegLasso = linear_model.Lasso(lmb) + RegLasso.fit(X_train,y_train) + # and then make the prediction + ytildeRidge = X_train @ Ridgebeta + ypredictRidge = X_test @ Ridgebeta + ytildeLasso = RegLasso.predict(X_train) + ypredictLasso = RegLasso.predict(X_test) + MSEPredict[i] = MSE(y_test,ypredictRidge) + MSETrain[i] = MSE(y_train,ytildeRidge) + MSELassoPredict[i] = MSE(y_test,ypredictLasso) + MSELassoTrain[i] = MSE(y_train,ytildeLasso) + +# Now plot the results +plt.figure() +plt.plot(np.log10(lambdas), MSETrain, label = 'MSE Ridge train') +plt.plot(np.log10(lambdas), MSEPredict, 'r--', label = 'MSE Ridge Test') +plt.plot(np.log10(lambdas), MSELassoTrain, label = 'MSE Lasso train') +plt.plot(np.log10(lambdas), MSELassoPredict, 'r--', label = 'MSE Lasso Test') + +plt.xlabel('log10(lambda)') +plt.ylabel('MSE') +plt.legend() +plt.show() + + + + +!ec + + +!split +===== Linking the regression analysis with a statistical interpretation ===== + + +The +advantage of doing linear regression is that we actually end up with +analytical expressions for several statistical quantities. +Standard least squares and Ridge regression allow us to +derive quantities like the variance and other expectation values in a +rather straightforward way. + + +It is assumed that $\varepsilon_i +\sim \mathcal{N}(0, \sigma^2)$ and the $\varepsilon_{i}$ are +independent, i.e.: +!bt +\begin{align*} +\mbox{Cov}(\varepsilon_{i_1}, +\varepsilon_{i_2}) & = \left\{ \begin{array}{lcc} \sigma^2 & \mbox{if} +& i_1 = i_2, \\ 0 & \mbox{if} & i_1 \not= i_2. \end{array} \right. +\end{align*} +!et +The randomness of $\varepsilon_i$ implies that +$\mathbf{y}_i$ is also a random variable. In particular, +$\mathbf{y}_i$ is normally distributed, because $\varepsilon_i \sim +\mathcal{N}(0, \sigma^2)$ and $\mathbf{X}_{i,\ast} \, \bm{\beta}$ is a +non-random scalar. To specify the parameters of the distribution of +$\mathbf{y}_i$ we need to calculate its first two moments. + +Recall that $\bm{X}$ is a matrix of dimensionality $n\times p$. The +notation above $\mathbf{X}_{i,\ast}$ means that we are looking at the +row number $i$ and perform a sum over all values $p$. + + +!split +===== Assumptions made ===== + +The assumption we have made here can be summarized as (and this is going to be useful when we discuss the bias-variance trade off) +that there exists a function $f(\bm{x})$ and a normal distributed error $\bm{\varepsilon}\sim \mathcal{N}(0, \sigma^2)$ +which describe our data +!bt +\[ +\bm{y} = f(\bm{x})+\bm{\varepsilon} +\] +!et + +We approximate this function with our model from the solution of the linear regression equations, that is our +function $f$ is approximated by $\bm{\tilde{y}}$ where we want to minimize $(\bm{y}-\bm{\tilde{y}})^2$, our MSE, with +!bt +\[ +\bm{\tilde{y}} = \bm{X}\bm{\beta}. +\] +!et + +!split +===== Expectation value and variance ===== + +We can calculate the expectation value of $\bm{y}$ for a given element $i$ +!bt +\begin{align*} +\mathbb{E}(y_i) & = +\mathbb{E}(\mathbf{X}_{i, \ast} \, \bm{\beta}) + \mathbb{E}(\varepsilon_i) +\, \, \, = \, \, \, \mathbf{X}_{i, \ast} \, \beta, +\end{align*} +!et +while +its variance is +!bt +\begin{align*} \mbox{Var}(y_i) & = \mathbb{E} \{ [y_i +- \mathbb{E}(y_i)]^2 \} \, \, \, = \, \, \, \mathbb{E} ( y_i^2 ) - +[\mathbb{E}(y_i)]^2 \\ & = \mathbb{E} [ ( \mathbf{X}_{i, \ast} \, +\beta + \varepsilon_i )^2] - ( \mathbf{X}_{i, \ast} \, \bm{\beta})^2 \\ & += \mathbb{E} [ ( \mathbf{X}_{i, \ast} \, \bm{\beta})^2 + 2 \varepsilon_i +\mathbf{X}_{i, \ast} \, \bm{\beta} + \varepsilon_i^2 ] - ( \mathbf{X}_{i, +\ast} \, \beta)^2 \\ & = ( \mathbf{X}_{i, \ast} \, \bm{\beta})^2 + 2 +\mathbb{E}(\varepsilon_i) \mathbf{X}_{i, \ast} \, \bm{\beta} + +\mathbb{E}(\varepsilon_i^2 ) - ( \mathbf{X}_{i, \ast} \, \bm{\beta})^2 +\\ & = \mathbb{E}(\varepsilon_i^2 ) \, \, \, = \, \, \, +\mbox{Var}(\varepsilon_i) \, \, \, = \, \, \, \sigma^2. +\end{align*} +!et +Hence, $y_i \sim \mathcal{N}( \mathbf{X}_{i, \ast} \, \bm{\beta}, \sigma^2)$, that is $\bm{y}$ follows a normal distribution with +mean value $\bm{X}\bm{\beta}$ and variance $\sigma^2$ (not be confused with the singular values of the SVD). + +!split +===== Expectation value and variance for $\bm{\beta}$ ===== + +With the OLS expressions for the parameters $\bm{\beta}$ we can evaluate the expectation value +!bt +\[ +\mathbb{E}(\bm{\beta}) = \mathbb{E}[ (\mathbf{X}^{\top} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1}\mathbf{X}^{T} \mathbb{E}[ \mathbf{Y}]=(\mathbf{X}^{T} \mathbf{X})^{-1} \mathbf{X}^{T}\mathbf{X}\bm{\beta}=\bm{\beta}. +\] +!et +This means that the estimator of the regression parameters is unbiased. + +We can also calculate the variance + +The variance of $\bm{\beta}$ is +!bt +\begin{eqnarray*} +\mbox{Var}(\bm{\beta}) & = & \mathbb{E} \{ [\bm{\beta} - \mathbb{E}(\bm{\beta})] [\bm{\beta} - \mathbb{E}(\bm{\beta})]^{T} \} +\\ +& = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} - \bm{\beta}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} - \bm{\beta}]^{T} \} +\\ +% & = & \mathbb{E} \{ [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y}] \, [(\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y}]^{T} \} - \bm{\beta} \, \bm{\beta}^{T} +% \\ +% & = & \mathbb{E} \{ (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \mathbf{Y} \, \mathbf{Y}^{T} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} \} - \bm{\beta} \, \bm{\beta}^{T} +% \\ +& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \mathbb{E} \{ \mathbf{Y} \, \mathbf{Y}^{T} \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \bm{\beta} \, \bm{\beta}^{T} +\\ +& = & (\mathbf{X}^{T} \mathbf{X})^{-1} \, \mathbf{X}^{T} \, \{ \mathbf{X} \, \bm{\beta} \, \bm{\beta}^{T} \, \mathbf{X}^{T} + \sigma^2 \} \, \mathbf{X} \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \bm{\beta} \, \bm{\beta}^{T} +% \\ +% & = & (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, \bm{\beta} \, \bm{\beta}^T \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T % \mathbf{X})^{-1} +% \\ +% & & + \, \, \sigma^2 \, (\mathbf{X}^T \mathbf{X})^{-1} \, \mathbf{X}^T \, \mathbf{X} \, (\mathbf{X}^T \mathbf{X})^{-1} - \bm{\beta} \bm{\beta}^T +\\ +& = & \bm{\beta} \, \bm{\beta}^{T} + \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1} - \bm{\beta} \, \bm{\beta}^{T} +\, \, \, = \, \, \, \sigma^2 \, (\mathbf{X}^{T} \mathbf{X})^{-1}, +\end{eqnarray*} +!et + +where we have used that $\mathbb{E} (\mathbf{Y} \mathbf{Y}^{T}) = +\mathbf{X} \, \bm{\beta} \, \bm{\beta}^{T} \, \mathbf{X}^{T} + +\sigma^2 \, \mathbf{I}_{nn}$. From $\mbox{Var}(\bm{\beta}) = \sigma^2 +\, (\mathbf{X}^{T} \mathbf{X})^{-1}$, one obtains an estimate of the +variance of the estimate of the $j$-th regression coefficient: +$\bm{\sigma}^2 (\bm{\beta}_j ) = \bm{\sigma}^2 \sqrt{ +[(\mathbf{X}^{T} \mathbf{X})^{-1}]_{jj} }$. This may be used to +construct a confidence interval for the estimates. + + +In a similar way, we can obtain analytical expressions for say the +expectation values of the parameters $\bm{\beta}$ and their variance +when we employ Ridge regression, allowing us again to define a confidence interval. + +It is rather straightforward to show that +!bt +\[ +\mathbb{E} \big[ \bm{\beta}^{\mathrm{Ridge}} \big]=(\mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I}_{pp})^{-1} (\mathbf{X}^{\top} \mathbf{X})\bm{\beta}^{\mathrm{OLS}}. +\] +!et +We see clearly that +$\mathbb{E} \big[ \bm{\beta}^{\mathrm{Ridge}} \big] \not= \bm{\beta}^{\mathrm{OLS}}$ for any $\lambda > 0$. We say then that the ridge estimator is biased. + +We can also compute the variance as + +!bt +\[ +\mbox{Var}[\bm{\beta}^{\mathrm{Ridge}}]=\sigma^2[ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1} \mathbf{X}^{T} \mathbf{X} \{ [ \mathbf{X}^{\top} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T}, +\] +!et +and it is easy to see that if the parameter $\lambda$ goes to infinity then the variance of Ridge parameters $\bm{\beta}$ goes to zero. + +With this, we can compute the difference + +!bt +\[ +\mbox{Var}[\bm{\beta}^{\mathrm{OLS}}]-\mbox{Var}(\bm{\beta}^{\mathrm{Ridge}})=\sigma^2 [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}[ 2\lambda\mathbf{I} + \lambda^2 (\mathbf{X}^{T} \mathbf{X})^{-1} ] \{ [ \mathbf{X}^{T} \mathbf{X} + \lambda \mathbf{I} ]^{-1}\}^{T}. +\] +!et +The difference is non-negative definite since each component of the +matrix product is non-negative definite. +This means the variance we obtain with the standard OLS will always for $\lambda > 0$ be larger than the variance of $\bm{\beta}$ obtained with the Ridge estimator. This has interesting consequences when we discuss the so-called bias-variance trade-off below. + + +!split +===== Deriving OLS from a probability distribution ===== + +Our basic assumption when we derived the OLS equations was to assume +that our output is determined by a given continuous function +$f(\bm{x})$ and a random noise $\bm{\epsilon}$ given by the normal +distribution with zero mean value and an undetermined variance +$\sigma^2$. + +We found above that the outputs $\bm{y}$ have a mean value given by +$\bm{X}\hat{\bm{\beta}}$ and variance $\sigma^2$. Since the entries to +the design matrix are not stochastic variables, we can assume that the +probability distribution of our targets is also a normal distribution +but now with mean value $\bm{X}\hat{\bm{\beta}}$. This means that a +single output $y_i$ is given by the Gaussian distribution + +!bt +\[ +y_i\sim \mathcal{N}(\bm{X}_{i,*}\bm{\beta}, \sigma^2)=\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\bm{X}_{i,*}\bm{\beta})^2}{2\sigma^2}\right]}. +\] +!et + +!split +===== Independent and Identically Distrubuted (iid) ===== + +We assume now that the various $y_i$ values are stochastically distributed according to the above Gaussian distribution. +We define this distribution as +!bt +\[ +p(y_i\vert \bm{X};\bm{\beta})=\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\bm{X}_{i,*}\bm{\beta})^2}{2\sigma^2}\right]}, +\] +!et +which reads as finding the likelihood of an event $y_i$ given the input variables $\bm{X}$ and the parameters (to be determined) $\bm{\beta}$. + +Since these events are assumed to be independent and identicall distributed we can build the probability distribution function (PDF) for all possible event $\bm{y}$ as the product of the single events, that is we have + +!bt +\[ +p(\bm{y}\vert \bm{X};\bm{\beta})=\prod_{i=0}^{n-1}\frac{1}{\sqrt{2\pi\sigma^2}}\exp{\left[-\frac{(y_i-\bm{X}_{i,*}\bm{\beta})^2}{2\sigma^2}\right]}=\prod_{i=0}^{n-1}p(y_i\vert \bm{X};\bm{\beta}). +\] +!et + +!split +===== Maximum Likelihood Estimation (MLE) ===== + +In statistics, maximum likelihood estimation (MLE) is a method of +estimating the parameters of an assumed probability distribution, +given some observed data. This is achieved by maximizing a likelihood +function so that, under the assumed statistical model, the observed +data is the most probable. + + +We will assume here that our events are given by the above Gaussian +distribution and we will determine the optimal parameters $\beta$ by +maximizing the above PDF. However, computing the derivatives of a +product function is cumbersome and can easily lead to overflow and/or +underflowproblems, with potentials for loss of numerical precision. + + +In practice, it is more convenient to maximize the logarithm of the +PDF because it is a monotonically increasing function of the argument. +Alternatively, and this will be our option, we will minimize the +negative of the logarithm since this is a monotonically decreasing +function. + +Note also that maximization/minimization of the logarithm of the PDF +is equivalent to the maximization/minimization of the function itself. + + + +!split +===== A new Cost Function ===== + +We could now define a new cost function to minimize, namely the negative logarithm of the above PDF + +!bt +\[ +C(\bm{\beta}=-\log{\prod_{i=0}^{n-1}p(y_i\vert \bm{X};\bm{\beta})}=-\sum_{i=0}^{n-1}\log{p(y_i\vert \bm{X};\bm{\beta})}, +\] +!et +which becomes +!bt +\[ +C(\bm{\beta}=\frac{n}{2}\log{2\pi\sigma^2}+\frac{\vert\vert (\bm{y}-\bm{X}\bm{\beta})\vert\vert_2^2}{2\sigma^2}. +\] +!et + +Taking the derivative of the *new* cost function with respect to the parameters $\beta$ we recognize our familiar OLS equation, namely + +!bt +\[ +\bm{X}^T\left(\bm{y}-\bm{X}\bm{\beta}\right) =0, +\] +!et +which leads to the well-known OLS equation for the optimal paramters $\beta$ +!bt +\[ +\hat{\bm{\beta}}^{\mathrm{OLS}}=\left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}! +\] +!et + + +Before we make a similar analysis for Ridge and Lasso regression, we need a new reminder on statistics. + +!split +===== More basic Statistics and Bayes' theorem ===== + +A central theorem in statistics is Bayes' theorem. This theorem plays a similar role as the good old Pythagoras' theorem in geometry. +Bayes' theorem is extremely simple to derive. But to do so we need some basic axioms from statistics. + +Assume we have two domains of events $X=[x_0,x_1,\dots,x_{n-1}]$ and $Y=[y_0,y_1,\dots,y_{n-1}]$. + +We define also the likelihood for $X$ and $Y$ as $p(X)$ and $p(Y)$ respectively. +The likelihood of a specific event $x_i$ (or $y_i$) is then written as $p(X=x_i)$ or just $p(x_i)=p_i$. + +!bblock Union of events is given by +!bt +\[ +p(X \cup Y)= p(X)+p(Y)-p(X \cap Y). +\] +!et +!eblock + + +!bblock The product rule (aka joint probability) is given by +!bt +\[ +p(X \cup Y)= p(X,Y)= p(X\vert Y)p(Y)=p(Y\vert X)p(x), +\] +!et +where we read $p(X\vert Y)$ as the likelihood of obtaining $X$ given $Y$. +!eblock + +If we have independent events then $p(X,Y)=p(X)p(Y)$. + + +!split +===== Marginal Probability ===== + +The marginal probability is defined in terms of only of the set of variables $X,Y$. For a discrete probability we have +!bblock Discrete Probability +!bt +\[ +p(X)=\sum_{i=0}^{n-1}p(X,Y=y_i)=\sum_{i=0}^{n-1}p(X\vert Y=y_i)p(Y=y_i)=\sum_{i=0}^{n-1}p(X\vert y_i)p(y_i). +\] +!et +!eblock + + +!split +===== Conditional Probability ===== + +The conditional probability, if $p(Y) > 0$, is +!bblock +!bt +\[ +p(X\vert Y)= \frac{p(X,Y)}{p(Y)}=\frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}. +\] +!et +!eblock + + +!split +===== Bayes' Theorem ===== + +If we combine the conditional probability with the marginal probability and the standard product rule, we have +!bt +\[ +p(X\vert Y)= \frac{p(X,Y)}{p(Y)}, +\] +!et +which we can rewrite as + +!bt +\[ +p(X\vert Y)= \frac{p(X,Y)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}=\frac{p(Y\vert X)p(X)}{\sum_{i=0}^{n-1}p(Y\vert X=x_i)p(x_i)}, +\] +!et +which is Bayes' theorem. More text to be added here by Friday September 10. + + +!split +===== Frliday September 10 ===== + +Depending on where we end on Thursday September 9, we will revise the material for Friday. On Friday we will also discuss project 1. + + +!split +===== Why resampling methods ===== + +Before we proceed, we need to rethink what we have been doing. In our +eager to fit the data, we have omitted several important elements in +our regression analysis. In what follows we will +o look at statistical properties, including a discussion of mean values, variance and the so-called bias-variance tradeoff +o introduce resampling techniques like cross-validation, bootstrapping and jackknife and more + +This will allow us to link the standard linear algebra methods we have discussed above to a statistical interpretation of the methods. + + + + + +!split +===== Resampling methods ===== +!bblock +Resampling methods are an indispensable tool in modern +statistics. They involve repeatedly drawing samples from a training +set and refitting a model of interest on each sample in order to +obtain additional information about the fitted model. For example, in +order to estimate the variability of a linear regression fit, we can +repeatedly draw different samples from the training data, fit a linear +regression to each new sample, and then examine the extent to which +the resulting fits differ. Such an approach may allow us to obtain +information that would not be available from fitting the model only +once using the original training sample. + +Two resampling methods are often used in Machine Learning analyses, +o The _bootstrap method_ +o and _Cross-Validation_ + +In addition there are several other methods such as the Jackknife and the Blocking methods. We will discuss in particular +cross-validation and the bootstrap method. + + +!eblock + + +!split +===== Resampling approaches can be computationally expensive ===== +!bblock + +Resampling approaches can be computationally expensive, because they +involve fitting the same statistical method multiple times using +different subsets of the training data. However, due to recent +advances in computing power, the computational requirements of +resampling methods generally are not prohibitive. In this chapter, we +discuss two of the most commonly used resampling methods, +cross-validation and the bootstrap. Both methods are important tools +in the practical application of many statistical learning +procedures. For example, cross-validation can be used to estimate the +test error associated with a given statistical learning method in +order to evaluate its performance, or to select the appropriate level +of flexibility. The process of evaluating a model’s performance is +known as model assessment, whereas the process of selecting the proper +level of flexibility for a model is known as model selection. The +bootstrap is widely used. + +!eblock + +!split +===== Why resampling methods ? ===== +!bblock Statistical analysis + +* Our simulations can be treated as *computer experiments*. This is particularly the case for Monte Carlo methods +* The results can be analysed with the same statistical tools as we would use analysing experimental data. +* As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors. + + +!eblock + +!split +===== Statistical analysis ===== +!bblock + +* As in other experiments, many numerical experiments have two classes of errors: + * Statistical errors + * Systematical errors +* Statistical errors can be estimated using standard tools from statistics +* Systematical errors are method specific and must be treated differently from case to case. +!eblock + + + + + +!split +===== Resampling methods ===== + +With all these analytical equations for both the OLS and Ridge +regression, we will now outline how to assess a given model. This will +lead us to a discussion of the so-called bias-variance tradeoff (see +below) and so-called resampling methods. + +One of the quantities we have discussed as a way to measure errors is +the mean-squared error (MSE), mainly used for fitting of continuous +functions. Another choice is the absolute error. + +In the discussions below we will focus on the MSE and in particular since we will split the data into test and training data, +we discuss the +o prediction error or simply the _test error_ $\mathrm{Err_{Test}}$, where we have a fixed training set and the test error is the MSE arising from the data reserved for testing. We discuss also the +o training error $\mathrm{Err_{Train}}$, which is the average loss over the training data. + +As our model becomes more and more complex, more of the training data tends to used. The training may thence adapt to more complicated structures in the data. This may lead to a decrease in the bias (see below for code example) and a slight increase of the variance for the test error. +For a certain level of complexity the test error will reach minimum, before starting to increase again. The +training error reaches a saturation. + + + + +!split +===== Resampling methods: Jackknife and Bootstrap ===== + +Two famous +resampling methods are the _independent bootstrap_ and _the jackknife_. + +The jackknife is a special case of the independent bootstrap. Still, the jackknife was made +popular prior to the independent bootstrap. And as the popularity of +the independent bootstrap soared, new variants, such as _the dependent bootstrap_. + +The Jackknife and independent bootstrap work for +independent, identically distributed random variables. +If these conditions are not +satisfied, the methods will fail. Yet, it should be said that if the data are +independent, identically distributed, and we only want to estimate the +variance of $\overline{X}$ (which often is the case), then there is no +need for bootstrapping. + +!split +===== Resampling methods: Jackknife ===== + +The Jackknife works by making many replicas of the estimator $\widehat{\theta}$. +The jackknife is a resampling method where we systematically leave out one observation from the vector of observed values $\bm{x} = (x_1,x_2,\cdots,X_n)$. +Let $\bm{x}_i$ denote the vector +!bt +\[ +\bm{x}_i = (x_1,x_2,\cdots,x_{i-1},x_{i+1},\cdots,x_n), +\] +!et + +which equals the vector $\bm{x}$ with the exception that observation +number $i$ is left out. Using this notation, define +$\widehat{\theta}_i$ to be the estimator +$\widehat{\theta}$ computed using $\vec{X}_i$. + + +!split +===== Jackknife code example ===== +!bc pycod +from numpy import * +from numpy.random import randint, randn +from time import time + +def jackknife(data, stat): + n = len(data);t = zeros(n); inds = arange(n); t0 = time() + ## 'jackknifing' by leaving out an observation for each i + for i in range(n): + t[i] = stat(delete(data,i) ) + + # analysis + print("Runtime: %g sec" % (time()-t0)); print("Jackknife Statistics :") + print("original bias std. error") + print("%8g %14g %15g" % (stat(data),(n-1)*mean(t)/n, (n*var(t))**.5)) + + return t + + +# Returns mean of data samples +def stat(data): + return mean(data) + + +mu, sigma = 100, 15 +datapoints = 10000 +x = mu + sigma*random.randn(datapoints) +# jackknife returns the data sample +t = jackknife(x, stat) + +!ec + + +!split +===== Resampling methods: Bootstrap ===== +!bblock +Bootstrapping is a nonparametric approach to statistical inference +that substitutes computation for more traditional distributional +assumptions and asymptotic results. Bootstrapping offers a number of +advantages: +o The bootstrap is quite general, although there are some cases in which it fails. +o Because it does not require distributional assumptions (such as normally distributed errors), the bootstrap can provide more accurate inferences when the data are not well behaved or when the sample size is small. +o It is possible to apply the bootstrap to statistics with sampling distributions that are difficult to derive, even asymptotically. +o It is relatively simple to apply the bootstrap to complex data-collection plans (such as stratified and clustered samples). +!eblock + + +!split +===== Resampling methods: Bootstrap background ===== + +Since $\widehat{\theta} = \widehat{\theta}(\bm{X})$ is a function of random variables, +$\widehat{\theta}$ itself must be a random variable. Thus it has +a pdf, call this function $p(\bm{t})$. The aim of the bootstrap is to +estimate $p(\bm{t})$ by the relative frequency of +$\widehat{\theta}$. You can think of this as using a histogram +in the place of $p(\bm{t})$. If the relative frequency closely +resembles $p(\vec{t})$, then using numerics, it is straight forward to +estimate all the interesting parameters of $p(\bm{t})$ using point +estimators. + + +!split +===== Resampling methods: More Bootstrap background ===== + +In the case that $\widehat{\theta}$ has +more than one component, and the components are independent, we use the +same estimator on each component separately. If the probability +density function of $X_i$, $p(x)$, had been known, then it would have +been straight forward to do this by: +o Drawing lots of numbers from $p(x)$, suppose we call one such set of numbers $(X_1^*, X_2^*, \cdots, X_n^*)$. +o Then using these numbers, we could compute a replica of $\widehat{\theta}$ called $\widehat{\theta}^*$. + +By repeated use of (1) and (2), many +estimates of $\widehat{\theta}$ could have been obtained. The +idea is to use the relative frequency of $\widehat{\theta}^*$ +(think of a histogram) as an estimate of $p(\bm{t})$. + +!split +===== Resampling methods: Bootstrap approach ===== + +But +unless there is enough information available about the process that +generated $X_1,X_2,\cdots,X_n$, $p(x)$ is in general +unknown. Therefore, "Efron in 1979":"https://projecteuclid.org/euclid.aos/1176344552" asked the +question: What if we replace $p(x)$ by the relative frequency +of the observation $X_i$; if we draw observations in accordance with +the relative frequency of the observations, will we obtain the same +result in some asymptotic sense? The answer is yes. + + +Instead of generating the histogram for the relative +frequency of the observation $X_i$, just draw the values +$(X_1^*,X_2^*,\cdots,X_n^*)$ with replacement from the vector +$\bm{X}$. + +!split +===== Resampling methods: Bootstrap steps ===== + +The independent bootstrap works like this: + +o Draw with replacement $n$ numbers for the observed variables $\bm{x} = (x_1,x_2,\cdots,x_n)$. +o Define a vector $\bm{x}^*$ containing the values which were drawn from $\bm{x}$. +o Using the vector $\bm{x}^*$ compute $\widehat{\theta}^*$ by evaluating $\widehat \theta$ under the observations $\bm{x}^*$. +o Repeat this process $k$ times. + +When you are done, you can draw a histogram of the relative frequency +of $\widehat \theta^*$. This is your estimate of the probability +distribution $p(t)$. Using this probability distribution you can +estimate any statistics thereof. In principle you never draw the +histogram of the relative frequency of $\widehat{\theta}^*$. Instead +you use the estimators corresponding to the statistic of interest. For +example, if you are interested in estimating the variance of $\widehat +\theta$, apply the etsimator $\widehat \sigma^2$ to the values +$\widehat \theta ^*$. + + +!split +===== Code example for the Bootstrap method ===== + +The following code starts with a Gaussian distribution with mean value +$\mu =100$ and variance $\sigma=15$. We use this to generate the data +used in the bootstrap analysis. The bootstrap analysis returns a data +set after a given number of bootstrap operations (as many as we have +data points). This data set consists of estimated mean values for each +bootstrap operation. The histogram generated by the bootstrap method +shows that the distribution for these mean values is also a Gaussian, +centered around the mean value $\mu=100$ but with standard deviation +$\sigma/\sqrt{n}$, where $n$ is the number of bootstrap samples (in +this case the same as the number of original data points). The value +of the standard deviation is what we expect from the central limit +theorem. + + +!bc pycod +from numpy import * +from numpy.random import randint, randn +from time import time +import matplotlib.mlab as mlab +import matplotlib.pyplot as plt + +# Returns mean of bootstrap samples +def stat(data): + return mean(data) + +# Bootstrap algorithm +def bootstrap(data, statistic, R): + t = zeros(R); n = len(data); inds = arange(n); t0 = time() + # non-parametric bootstrap + for i in range(R): + t[i] = statistic(data[randint(0,n,n)]) + + # analysis + print("Runtime: %g sec" % (time()-t0)); print("Bootstrap Statistics :") + print("original bias std. error") + print("%8g %8g %14g %15g" % (statistic(data), std(data),mean(t),std(t))) + return t + + +mu, sigma = 100, 15 +datapoints = 10000 +x = mu + sigma*random.randn(datapoints) +# bootstrap returns the data sample +t = bootstrap(x, stat, datapoints) +# the histogram of the bootstrapped data +n, binsboot, patches = plt.hist(t, 50, normed=1, facecolor='red', alpha=0.75) + +# add a 'best fit' line +y = mlab.normpdf( binsboot, mean(t), std(t)) +lt = plt.plot(binsboot, y, 'r--', linewidth=1) +plt.xlabel('Smarts') +plt.ylabel('Probability') +plt.axis([99.5, 100.6, 0, 3.0]) +plt.grid(True) + +plt.show() + +!ec + + +!split +===== Various steps in cross-validation ===== + +When the repetitive splitting of the data set is done randomly, +samples may accidently end up in a fast majority of the splits in +either training or test set. Such samples may have an unbalanced +influence on either model building or prediction evaluation. To avoid +this $k$-fold cross-validation structures the data splitting. The +samples are divided into $k$ more or less equally sized exhaustive and +mutually exclusive subsets. In turn (at each split) one of these +subsets plays the role of the test set while the union of the +remaining subsets constitutes the training set. Such a splitting +warrants a balanced representation of each sample in both training and +test set over the splits. Still the division into the $k$ subsets +involves a degree of randomness. This may be fully excluded when +choosing $k=n$. This particular case is referred to as leave-one-out +cross-validation (LOOCV). + +!split +===== How to set up the cross-validation for Ridge and/or Lasso ===== + +* Define a range of interest for the penalty parameter. + +* Divide the data set into training and test set comprising samples $\{1, \ldots, n\} \setminus i$ and $\{ i \}$, respectively. + +* Fit the linear regression model by means of ridge estimation for each $\lambda$ in the grid using the training set, and the corresponding estimate of the error variance $\bm{\sigma}_{-i}^2(\lambda)$, as +!bt +\begin{align*} +\bm{\beta}_{-i}(\lambda) & = ( \bm{X}_{-i, \ast}^{T} +\bm{X}_{-i, \ast} + \lambda \bm{I}_{pp})^{-1} +\bm{X}_{-i, \ast}^{T} \bm{y}_{-i} +\end{align*} +!et + +* Evaluate the prediction performance of these models on the test set by $\log\{L[y_i, \bm{X}_{i, \ast}; \bm{\beta}_{-i}(\lambda), \bm{\sigma}_{-i}^2(\lambda)]\}$. Or, by the prediction error $|y_i - \bm{X}_{i, \ast} \bm{\beta}_{-i}(\lambda)|$, the relative error, the error squared or the R2 score function. + +* Repeat the first three steps such that each sample plays the role of the test set once. + +* Average the prediction performances of the test sets at each grid point of the penalty bias/parameter. It is an estimate of the prediction performance of the model corresponding to this value of the penalty parameter on novel data. It is defined as +!bt +\begin{align*} +\frac{1}{n} \sum_{i = 1}^n \log\{L[y_i, \mathbf{X}_{i, \ast}; \bm{\beta}_{-i}(\lambda), \bm{\sigma}_{-i}^2(\lambda)]\}. +\end{align*} +!et + +!split +===== Cross-validation in brief ===== + +For the various values of $k$ + +o shuffle the dataset randomly. +o Split the dataset into $k$ groups. +o For each unique group: + o Decide which group to use as set for test data + o Take the remaining groups as a training data set + o Fit a model on the training set and evaluate it on the test set + o Retain the evaluation score and discard the model +o Summarize the model using the sample of model evaluation scores + + + +!split +===== Code Example for Cross-validation and $k$-fold Cross-validation ===== + +The code here uses Ridge regression with cross-validation (CV) resampling and $k$-fold CV in order to fit a specific polynomial. +!bc pycod +import numpy as np +import matplotlib.pyplot as plt +from sklearn.model_selection import KFold +from sklearn.linear_model import Ridge +from sklearn.model_selection import cross_val_score +from sklearn.preprocessing import PolynomialFeatures + +# A seed just to ensure that the random numbers are the same for every run. +# Useful for eventual debugging. +np.random.seed(3155) + +# Generate the data. +nsamples = 100 +x = np.random.randn(nsamples) +y = 3*x**2 + np.random.randn(nsamples) + +## Cross-validation on Ridge regression using KFold only + +# Decide degree on polynomial to fit +poly = PolynomialFeatures(degree = 6) + +# Decide which values of lambda to use +nlambdas = 500 +lambdas = np.logspace(-3, 5, nlambdas) + +# Initialize a KFold instance +k = 5 +kfold = KFold(n_splits = k) + +# Perform the cross-validation to estimate MSE +scores_KFold = np.zeros((nlambdas, k)) + +i = 0 +for lmb in lambdas: + ridge = Ridge(alpha = lmb) + j = 0 + for train_inds, test_inds in kfold.split(x): + xtrain = x[train_inds] + ytrain = y[train_inds] + + xtest = x[test_inds] + ytest = y[test_inds] + + Xtrain = poly.fit_transform(xtrain[:, np.newaxis]) + ridge.fit(Xtrain, ytrain[:, np.newaxis]) + + Xtest = poly.fit_transform(xtest[:, np.newaxis]) + ypred = ridge.predict(Xtest) + + scores_KFold[i,j] = np.sum((ypred - ytest[:, np.newaxis])**2)/np.size(ypred) + + j += 1 + i += 1 + + +estimated_mse_KFold = np.mean(scores_KFold, axis = 1) + +## Cross-validation using cross_val_score from sklearn along with KFold + +# kfold is an instance initialized above as: +# kfold = KFold(n_splits = k) + +estimated_mse_sklearn = np.zeros(nlambdas) +i = 0 +for lmb in lambdas: + ridge = Ridge(alpha = lmb) + + X = poly.fit_transform(x[:, np.newaxis]) + estimated_mse_folds = cross_val_score(ridge, X, y[:, np.newaxis], scoring='neg_mean_squared_error', cv=kfold) + + # cross_val_score return an array containing the estimated negative mse for every fold. + # we have to the the mean of every array in order to get an estimate of the mse of the model + estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds) + + i += 1 + +## Plot and compare the slightly different ways to perform cross-validation + +plt.figure() + +plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score') +plt.plot(np.log10(lambdas), estimated_mse_KFold, 'r--', label = 'KFold') + +plt.xlabel('log10(lambda)') +plt.ylabel('mse') + +plt.legend() + +plt.show() + +!ec + + +!split +===== The bias-variance tradeoff ===== + + +We will discuss the bias-variance tradeoff in the context of +continuous predictions such as regression. However, many of the +intuitions and ideas discussed here also carry over to classification +tasks. Consider a dataset $\mathcal{L}$ consisting of the data +$\mathbf{X}_\mathcal{L}=\{(y_j, \boldsymbol{x}_j), j=0\ldots n-1\}$. + +Let us assume that the true data is generated from a noisy model + +!bt +\[ +\bm{y}=f(\boldsymbol{x}) + \bm{\epsilon} +\] +!et + +where $\epsilon$ is normally distributed with mean zero and standard deviation $\sigma^2$. + +In our derivation of the ordinary least squares method we defined then +an approximation to the function $f$ in terms of the parameters +$\bm{\beta}$ and the design matrix $\bm{X}$ which embody our model, +that is $\bm{\tilde{y}}=\bm{X}\bm{\beta}$. + +Thereafter we found the parameters $\bm{\beta}$ by optimizing the means squared error via the so-called cost function +!bt +\[ +C(\bm{X},\bm{\beta}) =\frac{1}{n}\sum_{i=0}^{n-1}(y_i-\tilde{y}_i)^2=\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]. +\] +!et + +We can rewrite this as +!bt +\[ +\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\frac{1}{n}\sum_i(f_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2+\frac{1}{n}\sum_i(\tilde{y}_i-\mathbb{E}\left[\bm{\tilde{y}}\right])^2+\sigma^2. +\] +!et + +The three terms represent the square of the bias of the learning +method, which can be thought of as the error caused by the simplifying +assumptions built into the method. The second term represents the +variance of the chosen model and finally the last terms is variance of +the error $\bm{\epsilon}$. + +To derive this equation, we need to recall that the variance of $\bm{y}$ and $\bm{\epsilon}$ are both equal to $\sigma^2$. The mean value of $\bm{\epsilon}$ is by definition equal to zero. Furthermore, the function $f$ is not a stochastics variable, idem for $\bm{\tilde{y}}$. +We use a more compact notation in terms of the expectation value +!bt +\[ +\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\mathbb{E}\left[(\bm{f}+\bm{\epsilon}-\bm{\tilde{y}})^2\right], +\] +!et +and adding and subtracting $\mathbb{E}\left[\bm{\tilde{y}}\right]$ we get +!bt +\[ +\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\mathbb{E}\left[(\bm{f}+\bm{\epsilon}-\bm{\tilde{y}}+\mathbb{E}\left[\bm{\tilde{y}}\right]-\mathbb{E}\left[\bm{\tilde{y}}\right])^2\right], +\] +!et +which, using the abovementioned expectation values can be rewritten as +!bt +\[ +\mathbb{E}\left[(\bm{y}-\bm{\tilde{y}})^2\right]=\mathbb{E}\left[(\bm{y}-\mathbb{E}\left[\bm{\tilde{y}}\right])^2\right]+\mathrm{Var}\left[\bm{\tilde{y}}\right]+\sigma^2, +\] +!et +that is the rewriting in terms of the so-called bias, the variance of the model $\bm{\tilde{y}}$ and the variance of $\bm{\epsilon}$. + + + + + +!split +===== Example code for Bias-Variance tradeoff ===== +!bc pycod +import matplotlib.pyplot as plt +import numpy as np +from sklearn.linear_model import LinearRegression, Ridge, Lasso +from sklearn.preprocessing import PolynomialFeatures +from sklearn.model_selection import train_test_split +from sklearn.pipeline import make_pipeline +from sklearn.utils import resample + +np.random.seed(2018) + +n = 500 +n_boostraps = 100 +degree = 18 # A quite high value, just to show. +noise = 0.1 + +# Make data set. +x = np.linspace(-1, 3, n).reshape(-1, 1) +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2) + np.random.normal(0, 0.1, x.shape) + +# Hold out some test data that is never used in training. +x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) + +# Combine x transformation and model into one operation. +# Not neccesary, but convenient. +model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) + +# The following (m x n_bootstraps) matrix holds the column vectors y_pred +# for each bootstrap iteration. +y_pred = np.empty((y_test.shape[0], n_boostraps)) +for i in range(n_boostraps): + x_, y_ = resample(x_train, y_train) + + # Evaluate the new model on the same test data each time. + y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() + +# Note: Expectations and variances taken w.r.t. different training +# data sets, hence the axis=1. Subsequent means are taken across the test data +# set in order to obtain a total value, but before this we have error/bias/variance +# calculated per data point in the test set. +# Note 2: The use of keepdims=True is important in the calculation of bias as this +# maintains the column vector form. Dropping this yields very unexpected results. +error = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) +bias = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) +variance = np.mean( np.var(y_pred, axis=1, keepdims=True) ) +print('Error:', error) +print('Bias^2:', bias) +print('Var:', variance) +print('{} >= {} + {} = {}'.format(error, bias, variance, bias+variance)) + +plt.plot(x[::5, :], y[::5, :], label='f(x)') +plt.scatter(x_test, y_test, label='Data points') +plt.scatter(x_test, np.mean(y_pred, axis=1), label='Pred') +plt.legend() +plt.show() + +!ec + + +!split +===== Understanding what happens ===== +!bc pycod +import matplotlib.pyplot as plt +import numpy as np +from sklearn.linear_model import LinearRegression, Ridge, Lasso +from sklearn.preprocessing import PolynomialFeatures +from sklearn.model_selection import train_test_split +from sklearn.pipeline import make_pipeline +from sklearn.utils import resample + +np.random.seed(2018) + +n = 40 +n_boostraps = 100 +maxdegree = 14 + + +# Make data set. +x = np.linspace(-3, 3, n).reshape(-1, 1) +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape) +error = np.zeros(maxdegree) +bias = np.zeros(maxdegree) +variance = np.zeros(maxdegree) +polydegree = np.zeros(maxdegree) +x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2) + +for degree in range(maxdegree): + model = make_pipeline(PolynomialFeatures(degree=degree), LinearRegression(fit_intercept=False)) + y_pred = np.empty((y_test.shape[0], n_boostraps)) + for i in range(n_boostraps): + x_, y_ = resample(x_train, y_train) + y_pred[:, i] = model.fit(x_, y_).predict(x_test).ravel() + + polydegree[degree] = degree + error[degree] = np.mean( np.mean((y_test - y_pred)**2, axis=1, keepdims=True) ) + bias[degree] = np.mean( (y_test - np.mean(y_pred, axis=1, keepdims=True))**2 ) + variance[degree] = np.mean( np.var(y_pred, axis=1, keepdims=True) ) + print('Polynomial degree:', degree) + print('Error:', error[degree]) + print('Bias^2:', bias[degree]) + print('Var:', variance[degree]) + print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree])) + +plt.plot(polydegree, error, label='Error') +plt.plot(polydegree, bias, label='bias') +plt.plot(polydegree, variance, label='Variance') +plt.legend() +plt.show() + + + + +!ec + +!split +===== Summing up ===== + + + + +The bias-variance tradeoff summarizes the fundamental tension in +machine learning, particularly supervised learning, between the +complexity of a model and the amount of training data needed to train +it. Since data is often limited, in practice it is often useful to +use a less-complex model with higher bias, that is a model whose asymptotic +performance is worse than another model because it is easier to +train and less sensitive to sampling noise arising from having a +finite-sized training dataset (smaller variance). + + + +The above equations tell us that in +order to minimize the expected test error, we need to select a +statistical learning method that simultaneously achieves low variance +and low bias. Note that variance is inherently a nonnegative quantity, +and squared bias is also nonnegative. Hence, we see that the expected +test MSE can never lie below $Var(\epsilon)$, the irreducible error. + + +What do we mean by the variance and bias of a statistical learning +method? The variance refers to the amount by which our model would change if we +estimated it using a different training data set. Since the training +data are used to fit the statistical learning method, different +training data sets will result in a different estimate. But ideally the +estimate for our model should not vary too much between training +sets. However, if a method has high variance then small changes in +the training data can result in large changes in the model. In general, more +flexible statistical methods have higher variance. + + +You may also find this recent "article":"https://www.pnas.org/content/116/32/15849" of interest. + +!split +===== Another Example from Scikit-Learn's Repository ===== +!bc pycod +""" +============================ +Underfitting vs. Overfitting +============================ + +This example demonstrates the problems of underfitting and overfitting and +how we can use linear regression with polynomial features to approximate +nonlinear functions. The plot shows the function that we want to approximate, +which is a part of the cosine function. In addition, the samples from the +real function and the approximations of different models are displayed. The +models have polynomial features of different degrees. We can see that a +linear function (polynomial with degree 1) is not sufficient to fit the +training samples. This is called **underfitting**. A polynomial of degree 4 +approximates the true function almost perfectly. However, for higher degrees +the model will **overfit** the training data, i.e. it learns the noise of the +training data. +We evaluate quantitatively **overfitting** / **underfitting** by using +cross-validation. We calculate the mean squared error (MSE) on the validation +set, the higher, the less likely the model generalizes correctly from the +training data. +""" + +print(__doc__) + +import numpy as np +import matplotlib.pyplot as plt +from sklearn.pipeline import Pipeline +from sklearn.preprocessing import PolynomialFeatures +from sklearn.linear_model import LinearRegression +from sklearn.model_selection import cross_val_score + + +def true_fun(X): + return np.cos(1.5 * np.pi * X) + +np.random.seed(0) + +n_samples = 30 +degrees = [1, 4, 15] + +X = np.sort(np.random.rand(n_samples)) +y = true_fun(X) + np.random.randn(n_samples) * 0.1 + +plt.figure(figsize=(14, 5)) +for i in range(len(degrees)): + ax = plt.subplot(1, len(degrees), i + 1) + plt.setp(ax, xticks=(), yticks=()) + + polynomial_features = PolynomialFeatures(degree=degrees[i], + include_bias=False) + linear_regression = LinearRegression() + pipeline = Pipeline([("polynomial_features", polynomial_features), + ("linear_regression", linear_regression)]) + pipeline.fit(X[:, np.newaxis], y) + + # Evaluate the models using crossvalidation + scores = cross_val_score(pipeline, X[:, np.newaxis], y, + scoring="neg_mean_squared_error", cv=10) + + X_test = np.linspace(0, 1, 100) + plt.plot(X_test, pipeline.predict(X_test[:, np.newaxis]), label="Model") + plt.plot(X_test, true_fun(X_test), label="True function") + plt.scatter(X, y, edgecolor='b', s=20, label="Samples") + plt.xlabel("x") + plt.ylabel("y") + plt.xlim((0, 1)) + plt.ylim((-2, 2)) + plt.legend(loc="best") + plt.title("Degree {}\nMSE = {:.2e}(+/- {:.2e})".format( + degrees[i], -scores.mean(), scores.std())) +plt.show() +!ec + + +!split +===== More examples on bootstrap and cross-validation and errors ===== + +!bc pycod +# Common imports +import os +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt +from sklearn.linear_model import LinearRegression, Ridge, Lasso +from sklearn.model_selection import train_test_split +from sklearn.utils import resample +from sklearn.metrics import mean_squared_error +# Where to save the figures and data files +PROJECT_ROOT_DIR = "Results" +FIGURE_ID = "Results/FigureFiles" +DATA_ID = "DataFiles/" + +if not os.path.exists(PROJECT_ROOT_DIR): + os.mkdir(PROJECT_ROOT_DIR) + +if not os.path.exists(FIGURE_ID): + os.makedirs(FIGURE_ID) + +if not os.path.exists(DATA_ID): + os.makedirs(DATA_ID) + +def image_path(fig_id): + return os.path.join(FIGURE_ID, fig_id) + +def data_path(dat_id): + return os.path.join(DATA_ID, dat_id) + +def save_fig(fig_id): + plt.savefig(image_path(fig_id) + ".png", format='png') + +infile = open(data_path("EoS.csv"),'r') + +# Read the EoS data as csv file and organize the data into two arrays with density and energies +EoS = pd.read_csv(infile, names=('Density', 'Energy')) +EoS['Energy'] = pd.to_numeric(EoS['Energy'], errors='coerce') +EoS = EoS.dropna() +Energies = EoS['Energy'] +Density = EoS['Density'] +# The design matrix now as function of various polytrops + +Maxpolydegree = 30 +X = np.zeros((len(Density),Maxpolydegree)) +X[:,0] = 1.0 +testerror = np.zeros(Maxpolydegree) +trainingerror = np.zeros(Maxpolydegree) +polynomial = np.zeros(Maxpolydegree) + +trials = 100 +for polydegree in range(1, Maxpolydegree): + polynomial[polydegree] = polydegree + for degree in range(polydegree): + X[:,degree] = Density**(degree/3.0) + +# loop over trials in order to estimate the expectation value of the MSE + testerror[polydegree] = 0.0 + trainingerror[polydegree] = 0.0 + for samples in range(trials): + x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=0.2) + model = LinearRegression(fit_intercept=True).fit(x_train, y_train) + ypred = model.predict(x_train) + ytilde = model.predict(x_test) + testerror[polydegree] += mean_squared_error(y_test, ytilde) + trainingerror[polydegree] += mean_squared_error(y_train, ypred) + + testerror[polydegree] /= trials + trainingerror[polydegree] /= trials + print("Degree of polynomial: %3d"% polynomial[polydegree]) + print("Mean squared error on training data: %.8f" % trainingerror[polydegree]) + print("Mean squared error on test data: %.8f" % testerror[polydegree]) + +plt.plot(polynomial, np.log10(trainingerror), label='Training Error') +plt.plot(polynomial, np.log10(testerror), label='Test Error') +plt.xlabel('Polynomial degree') +plt.ylabel('log10[MSE]') +plt.legend() +plt.show() + +!ec + + +!split +===== The same example but now with cross-validation ===== + +!bc pycod +# Common imports +import os +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt +from sklearn.linear_model import LinearRegression, Ridge, Lasso +from sklearn.metrics import mean_squared_error +from sklearn.model_selection import KFold +from sklearn.model_selection import cross_val_score + + +# Where to save the figures and data files +PROJECT_ROOT_DIR = "Results" +FIGURE_ID = "Results/FigureFiles" +DATA_ID = "DataFiles/" + +if not os.path.exists(PROJECT_ROOT_DIR): + os.mkdir(PROJECT_ROOT_DIR) + +if not os.path.exists(FIGURE_ID): + os.makedirs(FIGURE_ID) + +if not os.path.exists(DATA_ID): + os.makedirs(DATA_ID) + +def image_path(fig_id): + return os.path.join(FIGURE_ID, fig_id) + +def data_path(dat_id): + return os.path.join(DATA_ID, dat_id) + +def save_fig(fig_id): + plt.savefig(image_path(fig_id) + ".png", format='png') + +infile = open(data_path("EoS.csv"),'r') + +# Read the EoS data as csv file and organize the data into two arrays with density and energies +EoS = pd.read_csv(infile, names=('Density', 'Energy')) +EoS['Energy'] = pd.to_numeric(EoS['Energy'], errors='coerce') +EoS = EoS.dropna() +Energies = EoS['Energy'] +Density = EoS['Density'] +# The design matrix now as function of various polytrops + +Maxpolydegree = 30 +X = np.zeros((len(Density),Maxpolydegree)) +X[:,0] = 1.0 +estimated_mse_sklearn = np.zeros(Maxpolydegree) +polynomial = np.zeros(Maxpolydegree) +k =5 +kfold = KFold(n_splits = k) + +for polydegree in range(1, Maxpolydegree): + polynomial[polydegree] = polydegree + for degree in range(polydegree): + X[:,degree] = Density**(degree/3.0) + OLS = LinearRegression() +# loop over trials in order to estimate the expectation value of the MSE + estimated_mse_folds = cross_val_score(OLS, X, Energies, scoring='neg_mean_squared_error', cv=kfold) +#[:, np.newaxis] + estimated_mse_sklearn[polydegree] = np.mean(-estimated_mse_folds) + +plt.plot(polynomial, np.log10(estimated_mse_sklearn), label='Test Error') +plt.xlabel('Polynomial degree') +plt.ylabel('log10[MSE]') +plt.legend() +plt.show() + +!ec + +!split +===== Cross-validation with Ridge ===== +!bc pycod +import numpy as np +import matplotlib.pyplot as plt +from sklearn.model_selection import KFold +from sklearn.linear_model import Ridge +from sklearn.model_selection import cross_val_score +from sklearn.preprocessing import PolynomialFeatures + +# A seed just to ensure that the random numbers are the same for every run. +np.random.seed(3155) +# Generate the data. +n = 100 +x = np.linspace(-3, 3, n).reshape(-1, 1) +y = np.exp(-x**2) + 1.5 * np.exp(-(x-2)**2)+ np.random.normal(0, 0.1, x.shape) +# Decide degree on polynomial to fit +poly = PolynomialFeatures(degree = 10) + +# Decide which values of lambda to use +nlambdas = 500 +lambdas = np.logspace(-3, 5, nlambdas) +# Initialize a KFold instance +k = 5 +kfold = KFold(n_splits = k) +estimated_mse_sklearn = np.zeros(nlambdas) +i = 0 +for lmb in lambdas: + ridge = Ridge(alpha = lmb) + estimated_mse_folds = cross_val_score(ridge, x, y, scoring='neg_mean_squared_error', cv=kfold) + estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds) + i += 1 +plt.figure() +plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score') +plt.xlabel('log10(lambda)') +plt.ylabel('MSE') +plt.legend() +plt.show() + + +!ec + + + diff --git a/doc/src/week36/week36.do.txt b/doc/src/week36/week36.do.txt index 96697790e..99196f716 100644 --- a/doc/src/week36/week36.do.txt +++ b/doc/src/week36/week36.do.txt @@ -6,7 +6,7 @@ DATE: today !split ===== Plans for week 36 ===== -* Thursday: Summary from last week on SVD, Statistics, probability theory and linear regression +* Thursday: Summary from last week on SVD, Statistics, probability theory and linear regression. "Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h21/forelesningsvideoer/LectureSeptember9.mp4?vrtx=view-as-webpage". * Friday: Linear Regression and links with Statistics, Resampling methods and presentation of first project. Recommended Reading: @@ -523,10 +523,8 @@ which leads to \] !et -Plotting these results (figure in handwritten notes for week 36) shows clearly that Lasso regression suppresses (sets to zero) values of $\beta_i$ for specific values of $\lambda$. Ridge regression reduces on the other hand the values of $\beta_i$ as function of $\lambda$. +Plotting these results ("figure in handwritten notes for week 36":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/2021/NotesSeptember9.pdf") shows clearly that Lasso regression suppresses (sets to zero) values of $\beta_i$ for specific values of $\lambda$. Ridge regression reduces on the other hand the values of $\beta_i$ as function of $\lambda$. -We will now couple the discussions of ordinary least squares, Ridge and Lasso regression with a statistical interpretation, that is we move from a linear algebra analysis to a statistical analysis. In particular, we will focus on what the regularization terms can result in. -We will amongst other things show that the regularization parameter can reduce considerably the variance of the parameters $\beta$. !split @@ -896,15 +894,20 @@ plt.ylabel('MSE') plt.legend() plt.show() - - - !ec !split ===== Linking the regression analysis with a statistical interpretation ===== +We will now couple the discussions of ordinary least squares, Ridge +and Lasso regression with a statistical interpretation, that is we +move from a linear algebra analysis to a statistical analysis. In +particular, we will focus on what the regularization terms can result +in. We will amongst other things show that the regularization +parameter can reduce considerably the variance of the parameters +$\beta$. + The advantage of doing linear regression is that we actually end up with