Update week35.ipynb

This commit is contained in:
Morten Hjorth-Jensen
2024-08-28 15:26:56 +02:00
parent 771b25d8ea
commit f65268f981
+12 -12
View File
@@ -1205,7 +1205,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"id": "b550fbbe",
"metadata": {},
"outputs": [
@@ -1213,7 +1213,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[ 2.00000000e+00 -5.21804822e-15 5.00000000e+00]\n"
"[ 1.93918379 1.05631924 1.04975077 5.1874182 -2.22521131]\n"
]
}
],
@@ -1222,15 +1222,15 @@
"# First we set up the data\n",
"import numpy as np\n",
"x = np.random.rand(100)\n",
"y = 2.0+5*x*x#+0.1*np.random.randn(100)\n",
"y = 2.0+5*x*x+0.1*np.random.randn(100)\n",
"# and then the design matrix X including the intercept\n",
"# The design matrix now as function of a fourth-order polynomial\n",
"X = np.zeros((len(x),3))\n",
"X = np.zeros((len(x),5))\n",
"X[:,0] = 1.0\n",
"X[:,1] = x\n",
"X[:,2] = x**2\n",
"#X[:,3] = x**3\n",
"#X[:,4] = x**4\n",
"X[:,3] = x**3\n",
"X[:,4] = x**4\n",
"beta = (np.linalg.inv(X.T @ X) @ X.T ) @ y\n",
"print(beta)\n",
"# and then make the prediction\n",
@@ -1269,7 +1269,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 3,
"id": "ae3d0b17",
"metadata": {},
"outputs": [],
@@ -1288,7 +1288,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 4,
"id": "9b073a72",
"metadata": {},
"outputs": [
@@ -1296,7 +1296,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"1.0\n"
"0.9951013500487981\n"
]
}
],
@@ -1314,7 +1314,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"id": "7ad18065",
"metadata": {},
"outputs": [
@@ -1322,7 +1322,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"1.9895184688083084e-22\n"
"0.010861520579271734\n"
]
}
],
@@ -1643,7 +1643,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 7,
"id": "f48cac43",
"metadata": {},
"outputs": [