link to website

This commit is contained in:
Pawel Sarkowicz
2026-03-31 16:05:58 -04:00
parent f81d01fe52
commit 290e8bc3e6
6 changed files with 134 additions and 1241 deletions

View File

@@ -6,6 +6,8 @@ This repository demonstrates how core linear algebra concepts -- least squares,
Rather than treating data science as a collection of tools, this project builds everything from first principles and connects theory to implementation through jupyter notebooks. Rather than treating data science as a collection of tools, this project builds everything from first principles and connects theory to implementation through jupyter notebooks.
The compiled notebooks in this project can be viewed as a single webpage on my [website](https://pawelsarkowicz.xyz/posts/ds_for_la).
## Structure ## Structure

File diff suppressed because one or more lines are too long

View File

@@ -53,7 +53,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -78,34 +78,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"id": "b48e6d97", "id": "b48e6d97",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"QA = [[ 1. 0. 0.]\n",
" [-0. 1. 0.]\n",
" [-0. -0. 1.]\n",
" [-0. -0. -0.]]\n",
"\n",
"RA = [[1. 1. 1.]\n",
" [0. 1. 1.]\n",
" [0. 0. 1.]]\n",
"\n",
"QB = [[-0.5 0.8660254 0. ]\n",
" [-0.5 -0.28867513 0.81649658]\n",
" [-0.5 -0.28867513 -0.40824829]\n",
" [-0.5 -0.28867513 -0.40824829]]\n",
"\n",
"RB = [[-2. -1.5 -1. ]\n",
" [ 0. -0.8660254 -0.57735027]\n",
" [ 0. 0. -0.81649658]]\n"
]
}
],
"source": [ "source": [
"print(f\"QA = {QA}\\n\")\n", "print(f\"QA = {QA}\\n\")\n",
"print(f\"RA = {RA}\\n\")\n", "print(f\"RA = {RA}\\n\")\n",
@@ -144,7 +120,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -171,23 +147,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": null,
"id": "3f71de8a", "id": "3f71de8a",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[ 1.00000000e+00],\n",
" [ 6.40987562e-17],\n",
" [-5.00000000e-01]])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"beta" "beta"
] ]
@@ -202,23 +165,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": null,
"id": "dcda7f8d", "id": "dcda7f8d",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[ 1.00000000e+00],\n",
" [ 2.22044605e-16],\n",
" [-5.00000000e-01]])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"np.linalg.lstsq(A,b)[0]" "np.linalg.lstsq(A,b)[0]"
] ]
@@ -236,7 +186,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -278,30 +228,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": null,
"id": "3d1e5bab", "id": "3d1e5bab",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Q = [[-0.4472136 0.32838365 0.40496317]\n",
" [-0.4472136 -0.63745061 -0.22042299]\n",
" [-0.4472136 0.42496708 -0.7689174 ]\n",
" [-0.4472136 0.32838365 0.40496317]\n",
" [-0.4472136 -0.44428376 0.17941406]] \n",
"\n",
"R = [[-2.23606798e+00 -3.95784032e+03 -7.15541753e+00]\n",
" [ 0.00000000e+00 -5.17687164e+02 -1.50670145e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 7.27908474e-01]] \n",
"\n",
"beta = [[-3.05053797e-13]\n",
" [ 3.00000000e-01]\n",
" [ 5.00000000e+00]]\n"
]
}
],
"source": [ "source": [
"print(f\"Q = {Q} \\n\\nR = {R} \\n\\nbeta = {beta}\")" "print(f\"Q = {Q} \\n\\nR = {R} \\n\\nbeta = {beta}\")"
] ]
@@ -334,7 +264,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -352,24 +282,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": null,
"id": "5bfd7362", "id": "5bfd7362",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[1.00000000e+00, 2.89687929e-17, 2.89687929e-17, 2.89687929e-17],\n",
" [2.89687929e-17, 1.00000000e+00, 7.07349921e-17, 7.07349921e-17],\n",
" [2.89687929e-17, 7.07349921e-17, 5.00000000e-01, 5.00000000e-01],\n",
" [2.89687929e-17, 7.07349921e-17, 5.00000000e-01, 5.00000000e-01]])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"P" "P"
] ]
@@ -486,7 +402,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -509,25 +425,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"id": "5336313f", "id": "5336313f",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"U = [[-0.70710678 -0.70710678]\n",
" [-0.70710678 0.70710678]]\n",
"\n",
"S = [5. 3.]\n",
"\n",
"Vh.T = [[-7.07106781e-01 -2.35702260e-01 -6.66666667e-01]\n",
" [-7.07106781e-01 2.35702260e-01 6.66666667e-01]\n",
" [-6.47932334e-17 -9.42809042e-01 3.33333333e-01]]\n"
]
}
],
"source": [ "source": [
"print(f\"U = {U}\\n\\nS = {S}\\n\\nVh.T = {Vh.T}\")" "print(f\"U = {U}\\n\\nS = {S}\\n\\nVh.T = {Vh.T}\")"
] ]
@@ -547,7 +448,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -572,38 +473,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25, "execution_count": null,
"id": "a13a3391", "id": "a13a3391",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"U_A = [[ 0.73697623 0.59100905 0.32798528 0. ]\n",
" [ 0.59100905 -0.32798528 -0.73697623 0. ]\n",
" [ 0.32798528 -0.73697623 0.59100905 0. ]\n",
" [ 0. 0. 0. 1. ]]\n",
"\n",
"S_A = [2.2469796 0.80193774 0.55495813]\n",
"\n",
"Vh_A.T = [[ 0.32798528 0.73697623 0.59100905]\n",
" [ 0.59100905 0.32798528 -0.73697623]\n",
" [ 0.73697623 -0.59100905 0.32798528]]\n",
"\n",
"U_B = [[-2.41816250e-01 7.12015746e-01 -6.59210496e-01 0.00000000e+00]\n",
" [-4.52990541e-01 5.17957311e-01 7.25616837e-01 6.71536163e-17]\n",
" [-6.06763739e-01 -3.35226641e-01 -1.39502200e-01 -7.07106781e-01]\n",
" [-6.06763739e-01 -3.35226641e-01 -1.39502200e-01 7.07106781e-01]]\n",
"\n",
"S_B = [2.8092118 0.88646771 0.56789441]\n",
"\n",
"Vh_B.T = [[-0.67931306 0.63117897 -0.37436195]\n",
" [-0.59323331 -0.17202654 0.7864357 ]\n",
" [-0.43198148 -0.75632002 -0.49129626]]\n"
]
}
],
"source": [ "source": [
"print(f\"U_A = {U_A}\\n\\nS_A = {S_A}\\n\\nVh_A.T = {Vh_A.T}\\n\\nU_B = {U_B}\\n\\nS_B = {S_B}\\n\\nVh_B.T = {Vh_B.T}\")" "print(f\"U_A = {U_A}\\n\\nS_A = {S_A}\\n\\nVh_A.T = {Vh_A.T}\\n\\nU_B = {U_B}\\n\\nS_B = {S_B}\\n\\nVh_B.T = {Vh_B.T}\")"
] ]
@@ -663,7 +536,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -700,23 +573,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": null,
"id": "862ed810", "id": "862ed810",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[ 2.74080345e+15],\n",
" [ 2.74080345e+15],\n",
" [-2.74080345e+15]])"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"beta" "beta"
] ]
@@ -731,21 +591,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": null,
"id": "2d3df55d", "id": "2d3df55d",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([3.00000000e+00, 1.00000000e+00, 1.21618839e-16])"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"S" "S"
] ]
@@ -761,7 +610,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -780,24 +629,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31, "execution_count": null,
"id": "2657ea4b", "id": "2657ea4b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"A_pinv=[[ 0.11111111 -0.44444444 0.55555556 0. ]\n",
" [ 0.11111111 0.55555556 -0.44444444 0. ]\n",
" [ 0.22222222 0.11111111 0.11111111 0. ]]\n",
"\n",
"beta=[[0.22222222]\n",
" [0.22222222]\n",
" [0.44444444]]\n"
]
}
],
"source": [ "source": [
"print(f\"A_pinv={A_pinv}\\n\\nbeta={beta}\")" "print(f\"A_pinv={A_pinv}\\n\\nbeta={beta}\")"
] ]
@@ -827,7 +662,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -862,21 +697,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": null,
"id": "8aa6bca9", "id": "8aa6bca9",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"np.float64(4329.082589067693)"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"cond_X" "cond_X"
] ]

File diff suppressed because one or more lines are too long

View File

@@ -33,7 +33,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -68,219 +68,30 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"id": "8514ed8b", "id": "8514ed8b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Square ft</th>\n",
" <th>Square m</th>\n",
" <th>Bedrooms</th>\n",
" <th>Price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>5.000000</td>\n",
" <td>5.000000</td>\n",
" <td>5.00000</td>\n",
" <td>5.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>1770.000000</td>\n",
" <td>164.000000</td>\n",
" <td>3.20000</td>\n",
" <td>547.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>258.843582</td>\n",
" <td>24.052027</td>\n",
" <td>0.83666</td>\n",
" <td>81.516869</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>1550.000000</td>\n",
" <td>144.000000</td>\n",
" <td>2.00000</td>\n",
" <td>475.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>1600.000000</td>\n",
" <td>148.000000</td>\n",
" <td>3.00000</td>\n",
" <td>490.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>1600.000000</td>\n",
" <td>148.000000</td>\n",
" <td>3.00000</td>\n",
" <td>500.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>2000.000000</td>\n",
" <td>185.000000</td>\n",
" <td>4.00000</td>\n",
" <td>620.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>2100.000000</td>\n",
" <td>195.000000</td>\n",
" <td>4.00000</td>\n",
" <td>650.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Square ft Square m Bedrooms Price\n",
"count 5.000000 5.000000 5.00000 5.000000\n",
"mean 1770.000000 164.000000 3.20000 547.000000\n",
"std 258.843582 24.052027 0.83666 81.516869\n",
"min 1550.000000 144.000000 2.00000 475.000000\n",
"25% 1600.000000 148.000000 3.00000 490.000000\n",
"50% 1600.000000 148.000000 3.00000 500.000000\n",
"75% 2000.000000 185.000000 4.00000 620.000000\n",
"max 2100.000000 195.000000 4.00000 650.000000"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"df.describe()" "df.describe()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"id": "0eb032aa", "id": "0eb032aa",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Square ft</th>\n",
" <th>Square m</th>\n",
" <th>Bedrooms</th>\n",
" <th>Price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Square ft</th>\n",
" <td>1.000000</td>\n",
" <td>0.999886</td>\n",
" <td>0.900426</td>\n",
" <td>0.998810</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Square m</th>\n",
" <td>0.999886</td>\n",
" <td>1.000000</td>\n",
" <td>0.894482</td>\n",
" <td>0.998395</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Bedrooms</th>\n",
" <td>0.900426</td>\n",
" <td>0.894482</td>\n",
" <td>1.000000</td>\n",
" <td>0.909066</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Price</th>\n",
" <td>0.998810</td>\n",
" <td>0.998395</td>\n",
" <td>0.909066</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Square ft Square m Bedrooms Price\n",
"Square ft 1.000000 0.999886 0.900426 0.998810\n",
"Square m 0.999886 1.000000 0.894482 0.998395\n",
"Bedrooms 0.900426 0.894482 1.000000 0.909066\n",
"Price 0.998810 0.998395 0.909066 1.000000"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"df.corr()" "df.corr()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"id": "6a166792", "id": "6a166792",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"np.float64(8222.19067218415)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"np.linalg.cond(X)" "np.linalg.cond(X)"
] ]
@@ -330,7 +141,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -363,128 +174,60 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"id": "799ea5da", "id": "799ea5da",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"np.float64(4.999999999999999)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"sigma1" "sigma1"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"id": "e17ad031", "id": "e17ad031",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[-0.70710678],\n",
" [-0.70710678]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"u1" "u1"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"id": "b75d1b41", "id": "b75d1b41",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[-7.07106781e-01, -7.07106781e-01, -6.47932334e-17]])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"v1T" "v1T"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": null,
"id": "cda3bc1a", "id": "cda3bc1a",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[2.50000000e+00, 2.50000000e+00, 2.29078674e-16],\n",
" [2.50000000e+00, 2.50000000e+00, 2.29078674e-16]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"A1" "A1"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"id": "5741dc92", "id": "5741dc92",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"np.float64(3.0)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"frobenius_error" "frobenius_error"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"id": "b1171244", "id": "b1171244",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"np.float64(3.0)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"operator_error" "operator_error"
] ]
@@ -513,7 +256,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -555,46 +298,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": null,
"id": "4288abb2", "id": "4288abb2",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([1770. , 164. , 3.2, 547. ])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"X_means" "X_means"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": null,
"id": "31c2ebf2", "id": "31c2ebf2",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"array([[-1.70e+02, -1.60e+01, -2.00e-01, -4.70e+01],\n",
" [ 3.30e+02, 3.10e+01, 8.00e-01, 1.03e+02],\n",
" [-2.20e+02, -2.00e+01, -1.20e+00, -7.20e+01],\n",
" [-1.70e+02, -1.60e+01, -2.00e-01, -5.70e+01],\n",
" [ 2.30e+02, 2.10e+01, 8.00e-01, 7.30e+01]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"X_centered" "X_centered"
] ]
@@ -610,31 +327,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": null,
"id": "d944d257", "id": "d944d257",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"U = [[-0.32486018 -0.81524197 -0.01735449 -0.17188722 0.4472136 ]\n",
" [ 0.63705869 0.10707263 -0.3450375 -0.51345964 0.4472136 ]\n",
" [-0.42643013 0.35553416 -0.61058318 0.34487822 0.4472136 ]\n",
" [-0.33034709 0.436448 0.61781883 -0.3445052 0.4472136 ]\n",
" [ 0.44457871 -0.08381281 0.35515633 0.68497384 0.4472136 ]]\n",
"\n",
"S = [5.44828440e+02 7.61035608e+00 8.91429037e-01 2.41987799e-01]\n",
"\n",
"Vh.T = [[ 0.95017495 0.29361033 0.08182661 0.06530651]\n",
" [ 0.08827897 0.06690917 -0.71081981 -0.69459714]\n",
" [ 0.00276797 -0.04366082 0.69629997 -0.71641638]\n",
" [ 0.29894268 -0.95258064 -0.05662119 0.00417714]]\n",
"\n",
"Condition number of X_centered = 2251.4707027583063\n"
]
}
],
"source": [ "source": [
"print(f\"U = {U}\\n\\nS = {S}\\n\\nVh.T = {Vh.T}\\n\")\n", "print(f\"U = {U}\\n\\nS = {S}\\n\\nVh.T = {Vh.T}\\n\")\n",
"print(\"Condition number of X_centered = \", np.linalg.cond(X_centered))" "print(\"Condition number of X_centered = \", np.linalg.cond(X_centered))"
@@ -650,7 +346,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -675,37 +371,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[-168.1743765 -15.62476472 -0.48991109 -52.91078079]\n",
" [ 329.79403078 30.64054254 0.96072753 103.7593243 ]\n",
" [-220.7553464 -20.50996365 -0.64308544 -69.45373002]\n",
" [-171.01485494 -15.88866823 -0.49818573 -53.80444804]\n",
" [ 230.15054706 21.38285405 0.67045472 72.40963456]] \n",
" k=1: relative Frobenius reconstruction error on centered data = 0.0141 \n",
"\n",
"[[-1.69996018e+02 -1.60398881e+01 -2.19027093e-01 -4.70007022e+01]\n",
" [ 3.30033282e+02 3.06950642e+01 9.25150039e-01 1.02983104e+02]\n",
" [-2.19960913e+02 -2.03289247e+01 -7.61220318e-01 -7.20311670e+01]\n",
" [-1.70039621e+02 -1.56664278e+01 -6.43206200e-01 -5.69684681e+01]\n",
" [ 2.29963269e+02 2.13401763e+01 6.98303572e-01 7.30172337e+01]] \n",
" k=2: relative Frobenius reconstruction error on centered data = 0.0017 \n",
"\n",
"[[-1.69997284e+02 -1.60288915e+01 -2.29799059e-01 -4.69998263e+01]\n",
" [ 3.30008114e+02 3.09136956e+01 7.10984571e-01 1.03000519e+02]\n",
" [-2.20005450e+02 -1.99420315e+01 -1.14021052e+00 -7.20003486e+01]\n",
" [-1.69994556e+02 -1.60579058e+01 -2.59724807e-01 -5.69996518e+01]\n",
" [ 2.29989175e+02 2.11151332e+01 9.18749820e-01 7.29993076e+01]] \n",
" k=3: relative Frobenius reconstruction error on centered data = 0.0004 \n",
"\n"
]
}
],
"source": [ "source": [
"for k in [1, 2, 3]:\n", "for k in [1, 2, 3]:\n",
"\t# Define our reduced matrix\n", "\t# Define our reduced matrix\n",

File diff suppressed because one or more lines are too long