shortcuts/notebooks/regressions.ipynb

171 lines
99 KiB
Plaintext
Raw Normal View History

2024-09-30 23:58:32 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Regressions\n",
"\n",
"$X = (0,1)$\n",
"\n",
"$Y = sin(2\\pi X)$"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAEgCAIAAADT5FumAABLrklEQVR4nOzdB3hT5foA8Dd7NknTNt1NW0YLpZVNywYFRIELCCIgQ1FwsQQHV0XkqlfF+5d78TpAryCyRAQEFBAQQfZqKdBS6N4zHdnr/J/00FBCWjqSnCR9f08enpyRc9720LznO+c778ckCAIQQgghT8OkOgCEnE6pVAqFwsZzTCYTg8Fwwa7t7ujgwYNHjx4VCASrVq1yQQwIeSs61QEg5CwlJSUzZswYP3780qVLx48fHxcXl5ycTC4aMmTIggULnB1Abm6uWCzev3+/zfxHH300KChox44dNvMPHz48depUHo83ePDgxx57LKnezJkzL1265OxQEfJEmMCQ15o1a1bnzp337du3YcOGffv2zZw5s7q6mlz0wgsvTJ061dkBBAUFLV++vFevXi1cf/To0S+//LJWq33//fd//fXXM2fOHDp0KDAwcMCAAe+++27znz1w4IDRaHRE1Ah5DLyEiLwTQRAnTpyYOXOmdc706dPZbDb5fvbs2U19ikajtXD7969pM5PD4dx/kZBch06n2739TH7cuhGRSPR///d/RqPx/ffff/TRR5OSkuwGo9PpnnvuuZycHCYT/6JRB4ItMOSdaDRaVFTUypUrT5w4Qc6JiooKDQ0FgCNHjowbN27x4sUAcOvWraeeemrixImvv/56jx49+Hw+mXLOnz8/YcKEl19+GQCys7OXLl0aHx+v0WgA4Mcffxw4cODcuXOHDx++b98+MietXbv20UcfJWd+/vnn5B4///zz3r177927l5zMyMgYNWrU448//uyzz/744492MyWZ1Wxy2+rVq81m8/fffw8ACoVi6NCh06dPHzly5Pjx41UqVWlp6dy5c0tKSmbNmvXJJ58AwPr160eNGjVr1qz4+PiNGzc6/5eNEEUIhLzUoUOHyL4bcXFx//rXv+rq6qyL5s2b97e//Y18v2rVqoSEBK1WazabV61aRafTlUolQRAvvPDCuHHjyHX++usvsjOIwWDg8/kXL14kCCIrK+uXX34hCGLr1q1hYWHkp8rLyyUSyU8//UR+0M/P77vvviMIQq/XR0ZGrlq1ipz/6aefxsbG3h/z8ePHAeD48eM288PCwkaMGEEQRFlZ2RdffEEQhMFgEAgE3377LUEQR44cAQCtVmvdOBnMF198IRKJnPCrRcgtYAsMea3Ro0enpaW98847arV62bJl8fHxhYWFdtdks9kcDodGo02cONFsNldUVDS1TbPZbDKZdu3aZTQao6Kixo8fDwDffvvtmDFjBAIBAPj7+48ZM+a7776z+eChQ4dycnLa3HNEKpUqFAoACAgIePHFFwGAyWRGRkaWlZXdv/KyZcvIYLp06VJbW6vVatu2U4TcHCYw5M3CwsJWr16dmZm5cePGoqKif/zjH82v/8B7SGw2+9NPP/3Pf/4jl8tXrFihVqsBICcnRyaTWdcJDg7Oycmx+WBWVhaXyw0MDGzbD1JUVNS5c2cAUKvVK1eunD9//vLly0tKSuxehzx79uzzzz+/ePHi9evXt213CHkEvOWLvBNBEOnp6d26dSPvh82ZM+f3339PT09v/5ZfeeWVGTNmbNmy5b333svNzd26datAINDpdNYVdDqdv7+/zacEAoHZbG5hDxEbWVlZFRUVffr0IbufSCSSDRs20Gi0Q4cO2V152LBhFy9ejI+PP3r06M6dO9u2U4TcH7bAkHcymUwffPBB4zl0Or1Tp04t3wKLxaqtrbWZqdFoUlJSpFLpwoULV69eff78eQB46KGHbt++bV0nLS0tPj7e5oOxsbF6vf7atWtt+FlWr14dERGxaNEiADh37lzv3r3t5iSz2QwAV65codPpcXFxTXUJQchrYAsMea09e/asW7duypQpfn5++/bt++23306dOnX/auTdYOt767/x8fFfffXVhg0bZDLZn3/+Sc4nb6dt27aNzWafOnVq2LBhALBixYphw4YdOXJk+PDhu3fvzszM3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1NQQBCESiTQazfXr1yMjI2UyGUEQNTU1ACASieh0em1trdls5vF4HA6HHLv12rVrAoEgMjLSx8eH3J1Wq83IyJDJZF27dmWxWOQcmUxG7p1EEERubm5hYaFjc2dT3OUSImqthASwKa3erx9ERDhs+0wmvPsufPEFvPkmfPklvPUW0PE/C0LuZMCAAZmZmWPHjj1z5gw5JzQ0FABqamo+/fRTX1/foqIiANi6dauvr++rr746e/bsGTNmREdHp6am6nS6f//7376+vvn5+QBw8ODB7t27r127lhzQoF+/fidOnPjll1/GNXTc2rFjx6hRo06fPr19+/a4uLjTp08DQEZGxlNPPTVixAhynfLy8hEjRixevDglJWXHjh2u+BVQPST0HXV1dfPmzbO7KD093eXheIaqKuK994ixY4lx44g1awiViuqAWgmPrLfCI+syy5cvp9efWsbExHz55Zcmk4mcn5ycDAAFBQUEQZAjjJMDIBiNxoCAgNWrVxMEQQ7uk5OTQ36kZ8+eH330EUEQzz///Pz588mZv/32G0EQJSUlAoHgwIEDFRUVBEF8/PHHXbp0MRgMBEGsWrWqb9++5MoLFixITEw0m83WW0JHjhxx6o9P2SVEnU5nvVxL3o3U6/VUBeOhfH1h5co7z2khhDqgNWvWvPLKK5s3b/72229ffPHF8+fP/+9//2tmfQaD0b179/sHumssKCjoyy+/HDFixJQpUx599FEAOHbsmEaj6d+/P7nCww8//MYbb9y6dYscMNZq9+7dCxcudOUAqpQlMA6Hs3HjRuukSqVatmwZVcF4NMxeCHVkcrn87bfffuONN5577rnvvvvuk08+uX9A8MYemGDefPPN0tLSZ555ZtGiRe+9996LL75YVFTk4+Nj/
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"// deno-lint-ignore-file\n",
"\n",
"import { display } from \"https://deno.land/x/display@v0.1.1/mod.ts\";\n",
"import pl from \"npm:nodejs-polars\";\n",
"import plot from \"../plot/mod.ts\";\n",
"\n",
"const data = await Deno.readTextFile(\"assets/X_Y_Sinusoid_Data.csv\");\n",
"const df = pl.readCSV(data, { sep: \",\" });\n",
"\n",
"const real = pl.DataFrame({ x: new Array(100).fill(0).map((_, i) => i / 100)}).select(\n",
" pl.col('x'),\n",
" pl.col('x').mul(2).mul(3.14).sin().alias('y')\n",
");\n",
"\n",
"const draw = (x, y, title = \"Sinusoid Data\") => \n",
" plot.DrawPlot(\n",
" { \n",
" title,\n",
" width: 6,\n",
" height: 3,\n",
" XLabel: \"X\", \n",
" YLabel: \"Y\", \n",
" }, \n",
" { type: \"line\", data: [real.x, real.y], legend: \"Sinusoid\", lineDashes: [3, 4], lineColor: \"#ff8888\", lineWidth: 1 },\n",
" { type: \"scatter\", data: [x, y], legend: \"Data\", lineDashes: [3, 4], lineWidth: 2, glyphColor: \"#4444ff\", glyphShape: \"circle\" },\n",
" { type: \"trend\", data: [x, y], legend: \"Trend\", lineDashes: [4, 2], lineColor: '#aacccc', lineWidth: .5 },\n",
" );\n",
"\n",
2024-10-01 00:00:01 +00:00
" const comparePredicted = (x, y, predicted) => plot.DrawPlot(\n",
" { \n",
" width: 7,\n",
" height: 4,\n",
" XLabel: \"X\", \n",
" YLabel: \"Y\", \n",
" }, \n",
" { type: \"line\", data: [real.x, real.y], legend: \"Sinusoid\", lineDashes: [3, 4], lineColor: \"#ff8888\", lineWidth: 1 },\n",
" { type: \"linePoints\", data: [x, y], legend: \"Test Data\", lineDashes: [3, 4], lineColor: \"#8888ff\", glyphColor: \"#4444ff\", glyphShape: \"circle\" },\n",
" { type: \"linePoints\", data: [x, predicted], lineWidth: .5, legend: \"Predicted\", glyphColor: '#f00', glyphShape: \"pyramid\" },\n",
");\n",
"\n",
2024-09-30 23:58:32 +00:00
"\n",
"draw(df.x, df.y);"
]
},
2024-10-01 00:00:01 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Polynomial Tranformation\n",
"\n",
"First we try to predict values without polynomial transformation:"
]
},
2024-09-30 23:58:32 +00:00
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
2024-10-01 00:00:01 +00:00
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAGACAIAAAD9Gkc5AABiSklEQVR4nOzdB1xT5/4/8E8Ie08FwYECIqKCqOCoC2e1WrVaR+sorbZ6f73W2/Gv3tZxu9vrbWtv1XvtVVtb99a6Fy7cigIiooAsAZmBMDL+r8PBGELAhJzkJOH7fuV1b3Jycp4v8TTf5znnGZZyuRyEEEIIMS+WfAdACNGv48ePHz16VCgUfvnll3zHQggxHAu+AyCEcODGjRvz58+3s7MLCwsbOXLksGHDYmJiCgoKAAwbNqxTp06bNm3iO0ZCiEFRgifEHISHh69YsaKysvLNN988cuTIgQMHCgsL+/TpI5FIND/I3r179RkjIcSgKMETYoZsbW3feeedhw8fXrt2rbF9VPrfZGdnL1q0yCDREUIMgRI8IebJ3t4ewOPHj1W2y+XylStXjh49evbs2YMGDfr5558BJCcnz549OycnZ9q0ab/++itPIRNCuESd7AgxT7GxsTY2NhERESrbN23a9OOPPyYmJtrb2+fn5wcEBPj6+o4fP37SpElJSUmbN2/mKV5CCMcowRNiVhISErZv33758uUNGzasXbvW19dXZYdffvll1KhRbPvey8tr+PDh69evHz9+PE/xEkL0hS7RE2JWioqKiouLhw4dmpSUNGvWrIY7pKWltWrVSvHSx8cnLS3NsDESQgyBWvCEmJUBAwa89dZbTezg4OBQVVWleFlZWenp6WmQ0AghBkUteEJalh49ety/f1/x8u7du926dWOfy2Qy/uIihHCMEjwhZkIsFgOoqKhoOP+0vBb7fPHixWfPnj116pREItmyZcujR48++OADAEFBQTk5OUePHo2Pj+cjfEIIxwQ0Fz0hZiAlJeW3335jm+C2traLFi1iu9GxU9WePXtWKpW6urrOmzfPyckpNTV1w4YNubm53bt3Hz9+fLt27QBIJJKlS5fm5uaOHj36lVde4fsPIoToihI8IYQQYoboEj0hhBBihijBE0IIIWaIEjwhhBBihmgcPNE7mQwpKZBIEBQEKyu+oyGEkJaBEjzRr7Q0LFuGrCzmuYcHlizB00HXhBBC9Ih60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Wjdmu849IlOGKIVOmHM2O3btxMSEoqKiry9vfv379+qtnGTnp5+9+5ddofu3bsnJCSwY+WjoqJSUlKePHkCIDg4uH379jk5OUePHvX09BwyZMidO3eKiopCQkIyMjJyc3Pz8vK8vb1Hjx5t+/SqeGJi4pUrV7y8vKKiotjb8FeuXCksLGTfHTZsmFAoLCgoiI2NraqqGjFiRHx8fFVV1YABAxwVU4VwjRI80YlcDgP2CdUInTBEK3TCEK2Y0AlDvehbKLkceXmortbpIOXl2LgRaWmcRUUIIYQrxjIXPTEwuRwbNmDiRGjc40RVaSm2bIGVlb7u6BNCiFZmz57d2FuffPJJp06dmnfYuLi4zZs3KwbHV1ZWhoWFderUaezYsbb1e60bG0rwLZSFBWxsUFHRzI9LJNi8GXZ2mDIFzTjDS0vh6NhUdzxCCNFWRkbGhg0bnJycUlJSIiMjf/nll5deekksFn/77bf5+fmaJPiCggJPT0+VjVFRUZ6enoGBgatXr540adKFCxcqKipWrFjxt7/9bdWqVePGjWvigCUlJfb29lZWVjr/cc1BP7Etxc6dqJ148RkHh+YneEtLDB2KqVObk93FYqxZgwZLJBNCiE6io6PbtWvn5uZmb29fu7qVvZeXV7t27aKjo+3s7DQ5wosvvihtfPUtR0dHLy+v4ODgadOm3bhxIzw8fOrUqamNzdxZ66233jLMujJqU
2024-09-30 23:58:32 +00:00
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import regr from '../regr/mod.ts';\n",
"\n",
2024-10-01 00:00:01 +00:00
"const linregWoPoly = regr.Linear();\n",
2024-09-30 23:58:32 +00:00
"\n",
2024-10-01 00:00:01 +00:00
"linregWoPoly.fit(df.drop('y').rows(), df.select('y').rows());\n",
"const predWoPoly = linregWoPoly.predict(df.drop('y').rows());\n",
2024-09-30 23:58:32 +00:00
"\n",
2024-10-01 00:00:01 +00:00
"comparePredicted(df.x, df.y, predWoPoly);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now augment our dataset with high degree polynomial:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAGACAIAAAD9Gkc5AABrbklEQVR4nOzdB1xT1xoA8C8ESAggSzbKHuIoOFDrRC1uURQUB6Iozlrc84miVmutrdU6Wq2IVrAi7llBxUXdIgiCyt4bAtnJ+0GUIgImkOSS8P1//N7LXed80pAv594zlAUCASCEEEJIsSgTHQBCSLpu3rx548YNMpm8fft2omNBCMmOEtEBIIQk4Pnz5wsXLlRTU3Nycho+fPiwYcP8/PwKCwsBYNiwYdbW1idOnCA6RoSQTGGCR0gRODs7BwUFMZnMOXPmXL9+/dKlS8XFxS4uLlwuV/RCzp8/L80YEUIyhQkeIQVEpVIXLFiQkpLy9OnTxs6p1/8mOzt72bJlMokOISQLmOARUkw0Gg0A8vLy6u0XCAS7d+8eOXKkr6/voEGD9u/fDwBv3rzx9fXNycnx9vYOCQkhKGSEkCRhJzuEFFN0dDSFQunRo0e9/SdOnPj1119fv35No9EKCgpsbGxMTU3d3d0nTpyYkJAQGhpKULwIIQnDBI+QQomPjz99+vSjR4+Cg4MPHTpkampa74QjR46MGDFC2L7X19f/5ptvjh496u7uTlC8CCFpwVv0CCmUkpKS0tLSIUOGJCQkzJw58/MTUlNTDQwMajeNjY1TU1NlGyNCSBawBY+QQunfv//cuXObOEFdXZ3FYtVuMpnM9u3byyQ0hJBMYQseobblq6++evv2be1mYmJi165dha/5fD5xcSGEJAwTPEIKgsFgAEBVVdXn808Laghfr1u37u7du7du3eJyuWFhYRkZGStXrgQAOzu7nJycGzduxMbGEhE+QkjCSDgXPUIKIDk5+fjx48ImOJVKXbZsmbAbnXCq2rt37/J4PG1t7Xnz5mlqar579y44ODg3N7dbt27u7u4dO3YEAC6XGxgYmJubO3LkyEmTJhH9D0IItRQmeIQQQkgB4S16hBBCSAFhgkcIIYQUECZ4JCvYQxshhGQIEzySOj4fsg5cyAk8yOEQHQ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um/fvtpNOp0eEBBAVDBtx5kzjxwcehkYAI+n98VbVWIJDw+/f//2nTu/Kys3eltISwvs7BxfvHhtbOwowaoRQuhzVCp18ODBy5cv79q1a0pKys6dO//44w9VVVU6nR4fHw8AsbGxurq6b968AYA3b9507949Pz+/tLQ0Ozu7oqLC3Nzc2tra399/3LhxVVVVRUVFGRkZdDr99u3bTCbT1dX1xo0bHTp06Nu3r7q6+ubNmxcsWBAUFFRYWLht27bw8HASiZSTk5Oenl5eXp6YmOjg4LB3796+ffv6+vr26NEjPT1dSUnp7du3gwYNUv68RS4hpFZyY1yY4A8fPvz5oTdv3tjb2xMRlAJavHjpnDnLnZzMAMDHxyckJEQixYaEhMTGxu7ateuLZz569Oj27durVq2SSL0NwjcMEgu+YRTYq1ev4uPjS0pKjIyM+vXrZ1AzRjctLS0xMVF4Qrdu3eLj43k8HgD06dMnOTm5qKgIABwcHMzNzXNycm7cuNG+fXtXV9e4uLiSkhJHR8f09PTc3Nz8/HwjI6ORI0dSP94Vf/369ePHj/X19fv06SN8DP/48ePi4mLh0WHDhpHJ5MLCwujoaBaL5ebmFhsby2Kx+vfvr6GhIaV/Pk5004ZwOJyiolxhdgcAJSUJ9MAQCODgwQM5OTmiZHcA6NWrl4hnIoRQC3WtUW+neY3aTeM6t7579uxZ90xjY+OZM2cKX7u4uAhfVFVV9evX7/O6HGvU3dOrV69657Rv397Dw0P4unZ8vPRgL/o25OrVqyNHjhS+FgiAyQQ2u0UFVlaCt/dPKSmlQUFBIl5CIpG0tbVLSkpaVDFCC
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import { polynomialTransform } from '../encoding.ts';\n",
2024-09-30 23:58:32 +00:00
"\n",
2024-10-01 00:00:01 +00:00
"\n",
"\n",
"const polyFeatures = polynomialTransform(df.drop('y'), 36, false, false)\n",
"\n",
"const [polyX, polyY] = [polyFeatures, df.select('y')]\n",
"\n",
"const linregPoly = regr.Linear();\n",
"\n",
"linregPoly.fit(polyX.rows(), polyY.rows());\n",
"const predY = linregPoly.predict(polyX.rows());\n",
"\n",
"comparePredicted(df.x, df.y, predY);\n"
2024-09-30 23:58:32 +00:00
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Deno",
"language": "typescript",
"name": "deno"
},
"language_info": {
"codemirror_mode": "typescript",
"file_extension": ".ts",
"mimetype": "text/x.typescript",
"name": "typescript",
"nbconvert_exporter": "script",
"pygments_lexer": "typescript",
"version": "5.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}