shortcuts/notebooks/regressions.ipynb

576 lines
202 KiB
Plaintext
Raw Normal View History

2024-09-30 23:58:32 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
2024-10-04 04:09:41 +00:00
"# Regressions\n"
2024-09-30 23:58:32 +00:00
]
},
{
"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+PDhu3fvzszM3Lx5s81e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ESiTQazfXr1yMjI2UyGUEQNTU1ACASieh0em1trdls5vF4HA6HHLv12rVrAoEgMjLSx8eH3J1Wq83IyJDJZF27dmWxWOQcmUxG7p1EEERubm5hYaFjc2dT3OUSImqthASwKa3erx9ERDhs+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",
"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+oyGEkJaBEjzRr7Q0LFuGrCzmuYcHlizB00HXhBBC9Ih60RM9kskQE4PMzGdbXFzw6694OoCLEEKIvtA9+BanoADffYc5c7BoEc6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ddofu3bsnJCSwY+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/J4PG1t7Xnz5mlqar579y44ODg3N7dbt27u7u4dO3YEAC6XGxgYmJubO3LkyEmTJhH9D0IItRQmeIQQQkgB4S16hBBCSAFhgkcIIYQUECZ4JCvYQxshhGQIEzySOj4fsg5cyAk8yOEQHQpCCLUZmOCRdKWmwlxfDixfof7DxvmTS1+9IjoghBBqGzDBt1X//C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nTu/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
]
2024-10-01 02:37:42 +00:00
},
2024-10-01 13:41:13 +00:00
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[33m0.9999999469410812\u001b[39m"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"linregPoly.score(df.select('y').rows(), pl.DataFrame({\"py\":predY}).rows());"
]
},
2024-10-01 02:37:42 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ElasticNet"
]
},
{
"cell_type": "code",
2024-10-01 13:41:13 +00:00
"execution_count": 5,
2024-10-01 02:37:42 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAGACAIAAAD9Gkc5AABy2UlEQVR4nOzdB1QTWRcA4BtCRzooKCIoTVABK5ZVEez+NsQCqCAqCisL9t7WsquuqyyiKK6o2HtbrKjYFRtSRaQKCCgtEErKf0IwhtASUoZyv5OzJ3mZeXNhIzcz89670kwmExBCCCHUskgTHQBCSLzu3r17+/ZtMpm8fft2omNBCEmOFNEBIIRE4O3bt56engoKClZWViNHjrS3t3d3d8/NzQUAe3v7Ll26hISEEB0jQkiiMMEj1BJYW1tv3ry5tLR07ty5t27dun79+vfv3/v27Uuj0fjv5MqVK+KMESEkUZjgEWqB5OXlFy5cmJSU9Pr167q24Rl/k5GRsXjxYolEhxCSBEzwCLVMioqKAPD161eediaTuXv37tGjR7u6ug4ZMiQgIAAA4uPjXV1dMzMzZ8yYcezYMYJCRgiJEg6yQ6hlCg8Pl5OT69WrF097SEiIn59fTEyMoqJiTk6OkZFRhw4dJkyY4ODgEBsbe+rUKYLiRQiJGCZ4hFqU6Ojoc+fOvXz5Mjg4ODAwsEOHDjwbHD58eNSoUezze21t7eHDhx85cmTChAkExYsQEhe8RI9Qi5KXl5efnz9s2LDY2NjZs2fX3CA5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6lqK2tra+vb2dnp6CgwE8PY8aModddfatNmzba2tpmZmYzZsx4+/attbX19OnTE+taubPSvHnzJFNXplZ4Bt8q5OfDp0/Qt2+1xg4dQFa28
]
},
2024-10-01 13:41:13 +00:00
"execution_count": 5,
2024-10-01 02:37:42 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"const elasticNetPoly = regr.ElasticNet(1000, 0.0001);\n",
"elasticNetPoly.fit(polyX.rows(), polyY.rows());\n",
"const predEnetY = elasticNetPoly.predict(polyX.rows());\n",
"\n",
"comparePredicted(df.x, df.y, predEnetY);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lasso"
]
},
{
"cell_type": "code",
2024-10-01 13:41:13 +00:00
"execution_count": 6,
2024-10-01 02:37:42 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAGACAIAAAD9Gkc5AABxn0lEQVR4nOzdB1hT1xcA8BPC3nsriojgRFEcuEAcVCvuVUEUBUVb9wBtRf+uorVFLYqioKBixVH3RItbREVARKaAgCB7hJHx/0IwQlgJGY/A+X18/fLuW0cacvLeu/dcSQaDAQghhBBqXySJDgAhJFz37t27c+cOmUzevXs30bEghERHgugAEEIC8ObNG3d3dzk5OQsLi/Hjx9vZ2bm4uHz9+hUA7OzsunXrFhwcTHSMCCGRwgSPUHvQv3//7du3V1RULF68+Pbt29euXcvPz7eysqJSqdwf5N9//xVmjAghkcIEj1A7JCsru2zZspSUlMjIyKa24eh/k5mZuWbNGpFEhxASBUzwCLVP8vLyAPDlyxeOdgaDsX//fnt7e2dn51GjRvn6+gJAfHy8s7NzVlbW3LlzT506RVDICCFBwk52CLVP4eHhMjIylpaWHO3BwcEHDhx4//69vLx8bm6uiYmJgYGBg4PD9OnT4+Lizp49S1C8CCEBwwSPULsSGxt7/vz5ly9fBgYG+vn5GRgYcGxw/PjxCRMmsK7vtbS0xo4dGxAQ4ODgQFC8CCF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Az9iO4oLF6Cm8OJ3CgqtT/CSkmBrC3PmtCa7Uyhw5Ag0mCIZIYT4MmbMmM6dO6upqcnLy9fMbiWvpaXVuXPnMWPGyMnJcXOEH374gdb07FuKiopaWlpmZmZz58598+ZN//7958yZk9RU5c4aS5YsEc28Mo3CK/gOobAQEhPByqpeo4EBSEu3/
]
},
2024-10-01 13:41:13 +00:00
"execution_count": 6,
2024-10-01 02:37:42 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"const lassoPoly = regr.Lasso(1000, 0.0001);\n",
"lassoPoly.fit(polyX.rows(), polyY.rows());\n",
"const predLassoY = lassoPoly.predict(polyX.rows());\n",
"\n",
"comparePredicted(df.x, df.y, predLassoY);"
]
2024-10-01 13:41:13 +00:00
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[33m0.8637104981289901\u001b[39m"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lassoPoly.score(df.select('y').rows(), pl.DataFrame({\"py\":predLassoY}).rows());\n"
]
2024-10-04 04:09:41 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Logistic Regression\n",
"\n",
"Logistic regression is applicable for classification problems when there are linear relationships in the data.\n",
"\n",
"For example we'll use a simple linear pattern for predictions:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.dataresource+json": {
"bytes": null,
"data": [
{
"is_even": 1,
"x": 0,
"x2": -0.9906467224227306,
"x3": 0.00261179419023964
},
{
"is_even": 0,
"x": 1,
"x2": 0.00202764718654894,
"x3": 0.0013126936809724655
},
{
"is_even": 1,
"x": 2,
"x2": -0.9972687463767552,
"x3": -1.9905576758692132
},
{
"is_even": 0,
"x": 3,
"x2": 0.009024117668298463,
"x3": 1.0021275936361942
},
{
"is_even": 1,
"x": 4,
"x2": -0.9968599379688912,
"x3": -0.9947633704461447
},
{
"is_even": 0,
"x": 5,
"x2": 0.0019298798125454942,
"x3": -0.9913865823439642
},
{
"is_even": 1,
"x": 6,
"x2": -0.9967558047825875,
"x3": 0.00801993440722967
},
{
"is_even": 0,
"x": 7,
"x2": 0.007736464312311071,
"x3": 0.00034330022067074583
},
{
"is_even": 1,
"x": 8,
"x2": -0.9959077406033643,
"x3": -1.994011690184521
},
{
"is_even": 0,
"x": 9,
"x2": 0.002684616942261051,
"x3": 1.0072230674765243
}
],
"description": null,
"dialect": null,
"encoding": null,
"format": null,
"hash": null,
"homepage": null,
"licenses": null,
"mediatype": null,
"path": null,
"schema": {
"fields": [
{
"constraints": null,
"description": null,
"example": null,
"format": null,
"name": "x",
"rdfType": null,
"title": null,
"type": "number"
},
{
"constraints": null,
"description": null,
"example": null,
"format": null,
"name": "x2",
"rdfType": null,
"title": null,
"type": "number"
},
{
"constraints": null,
"description": null,
"example": null,
"format": null,
"name": "x3",
"rdfType": null,
"title": null,
"type": "number"
},
{
"constraints": null,
"description": null,
"example": null,
"format": null,
"name": "is_even",
"rdfType": null,
"title": null,
"type": "number"
}
],
"foreignKeys": null,
"missingValues": null,
"primaryKey": null
},
"sources": null,
"title": null
},
"text/html": [
"<table><thead><tr><th>x</th><th>x2</th><th>x3</th><th>is_even</th></tr></thead><tbody><tr><td>0</td><td>-0.9906467224227306</td><td>0.00261179419023964</td><td>1</td></tr><tr><td>1</td><td>0.00202764718654894</td><td>0.0013126936809724655</td><td>0</td></tr><tr><td>2</td><td>-0.9972687463767552</td><td>-1.9905576758692132</td><td>1</td></tr><tr><td>3</td><td>0.009024117668298463</td><td>1.0021275936361942</td><td>0</td></tr><tr><td>4</td><td>-0.9968599379688912</td><td>-0.9947633704461447</td><td>1</td></tr><tr><td>5</td><td>0.0019298798125454942</td><td>-0.9913865823439642</td><td>0</td></tr><tr><td>6</td><td>-0.9967558047825875</td><td>0.00801993440722967</td><td>1</td></tr><tr><td>7</td><td>0.007736464312311071</td><td>0.00034330022067074583</td><td>0</td></tr><tr><td>8</td><td>-0.9959077406033643</td><td>-1.994011690184521</td><td>1</td></tr><tr><td>9</td><td>0.002684616942261051</td><td>1.0072230674765243</td><td>0</td></tr></tbody></table>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"const clsDf = pl.DataFrame({ \n",
" x: new Array(100).fill(0).map((_, i) => i ),\n",
" x2: new Array(100).fill(0).map((_, i) => i % 2 - 1 + Math.random() / 100),\n",
" x3: new Array(100).fill(0).map((_, i) => i % 2 - i % 3 + Math.random() / 100),\n",
" }).select(\n",
" pl.all(),\n",
" pl.col('x').modulo(2).eq(0).add(0).alias('is_even'),\n",
");\n",
"clsDf.head(10);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice that I left `x` in training data which is a continuos sequence that couln't be generalized by this model, however the model should guess a correct class in most cases. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"tags": [
"hide_code",
"parameters"
]
},
"outputs": [],
"source": [
"const drawBin = (x1, y1, t = \"Example\") => {\n",
" const xTrue = clsDf.x.toArray().map((v, i) => v % 2)\n",
" const yTrue = clsDf.is_even.toArray()\n",
" y1 = y1.map((v, i) => v + i * 0.02)\n",
" x1 = x1.map((v, i) => v % 2)\n",
" return plot.DrawPlot(\n",
" { \n",
" title: \"\",\n",
" width: 2.5,\n",
" height: 2,\n",
" XLabel: \"X\", \n",
" YLabel: \"Y\", \n",
" }, \n",
" { type: \"scatter\", data: [xTrue, yTrue], lineDashes: [3, 4], glypRadius: 12, glyphColor: \"#00f\", glyphShape: \"ring\" },\n",
" { type: \"scatter\", data: [x1, y1], legend: t, lineDashes: [3, 4], glypRadius: 3, glyphColor: \"#f00\", glyphShape: \"ring\" },\n",
" );\n",
"}\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import {trainTestSplit} from \"../split.ts\";\n",
"\n",
"\n",
"const {testX, trainX, testY, trainY} = trainTestSplit(clsDf, 0.05, true, \"is_even\");\n",
"\n",
"const drawTestBin = () => drawBin(testX.x.toArray(), testY.is_even.toArray(), \"Test Data\");\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADACAIAAAC1TXloAAAaF0lEQVR4nOydCVhTV9rHTxJIJOybgCiCYIkDMootbuNu1a+t49KOtNNPB2fQ1qJOfQBFRT9XqkMddUa62oIjo0NFXNCKSgUFC1ZFMYgJICiLZYssYclCcr+HXOYSQ5YbCCa5vr+Hx+eee97z8l755+Q9y73XAsMwRCFoNFJm1LpooBcLYwdgMJSlrEWvuBn+L8iaetAo0EM7OaGmpu6DIUNQZyepJvb2qLW1+4DNRu3tgxyfmVBaWvqf//yntbV148aNrq6uhnVeW1ubmJj4/Pnz8PBwf39/wzpXxuwFTXTMaq7j7Fl08mRP3bJl6L339GhrJly8eDEpKSk7OzsgIIDFYllYWEydOnXTpk0MBqMf3h4/fuzn58fj8fz9/c+fPx8eHs7lct3c3AwSqkwms7CwyMjImD9/vkEcqgczZxDq+VHDhg3YwYOYSNR9LBZjCQnY2rV9reh0zR7MhIyMDIRQfn4+hmHV1dW+vr4ffPBB/1yVlZUhhHg8HoZhpaWlUVFRYrFYi31RUVF1dTVJ511dXQihjIyM/sVGEvogflYGGbx/tbRU17+eOYNGjECffopYrO4ik4k++QRxOCg1VcVQJkNWVoj8aNLE8fT0DAsLS0tLE4lE/WhOp/fqwc/PLz4+nslkarGPjo6uqKgg6Zw2kP/i5mak+DzoxFwHhQUFPQcSibrqH35AiYmqJ1etQv/7v30Tj46OHjX/8EN3YmLu2NjYiMVigUBw9erVo0ePxsTE5OTk/PDDDxUVFY2NjevXr0cIiUSikJCQmJgYxX+gJDY2Ni8vz9vbu+u/onn+/PnBgwczMzNPnTo1fPhwhNC9e/e2bt1qbW3d1tYmEAjOnDlz5MiRS5cuSSQSPz+/r776qqOjIyoqqr6+nkajjRgx4sCBAzRad0I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pafX39smXLSkpKpk2bdvv27ddff/3o0aObN29euHBhWlpaYt/9Ff1i2DD07JkuIzc3lJSEBIL23FyXKVMQuQ2+Y8YYJEDAaBhgP7RYLO5S2gllbW2NEKqoqCDWlvBtjcOHD9drb8qePXsWL14cGBioGrGeN5vw+XzyO8rN7k4Wva7O7MCHB3p9BRmgh2YpUDmpvFKKb78a+C8CAJ2Y7uYkTQx292lG3TPQF/MTNM5gLFBTddH7lcIsBd2/3Yhk0LrvBTADzFLQ+GqMYTtU3Jv2fS+A6WOWglbsZ0cG1DTuR3HnB2DemNAG/zNnzqSkpBDFqqoq/A4ItRD7ri0sSN49qRFin8yg3l0PvBxMSNBLFBDFPXv2aLfH9+PLZN3/9ntqgk7vaQuTG9TAXFMOHEKF/cs9iE8CqJkymLegcS06OiJcnX2WdzRiY9PzGbC2BjVTChNKOfrN8+cIF7REonvtmuQzHQEzhQqCxsHVqfxw0f+iZqsDSJmqmH3KoQKG9fz03dDi6NhbC1AVqgmaoLGxR7s8Hh8/wDMTgNpQVtDAqwkIGqAUJjQolEqlynfUSs33sVyA8TAhQV+5cuXMmTNE8fHjx3/4wx+MGhFgfpiQoN9WQBR1Ln0DQF8ghwYoBQgaoBQgaIBSgKABSgGCBigFCBqgFCBogFKAoAFKYUILKwUFBb/88gtR5HK5Wm6SBQC1mJCgnZ2dlR+2W1hYaNRwALPEhAQ9UgFRzM3NNWo4gFkCOTRAKUDQAKUAQQOUAgQNUAoQNEApQNAApQBBA5QCBA1QChNaWNHr+dAAoJYeQd+9e3fChAnGDUXf50MDQF96Uo6DBw8O/A2cAGB0egT9888/z549G/YDAeZOj6DDw8O/+OKLmJiY9evXt7S0qBjl5eUZI
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"const logreg = regr.Logistic({\n",
" epochs: 5000,\n",
" learningRate: 0.001,\n",
"});\n",
"logreg.fit(trainX.rows(), trainY.rows());\n",
"\n",
"const predLogReg = logreg.predict(testX.rows());\n",
"\n",
"const yPred1 = predLogReg.map((x) => x[0]);\n",
"\n",
"drawBin(\n",
" testX.x.toArray(), \n",
" yPred1,\n",
" \"Predicted\"\n",
");"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"tags": [
"hide_code",
"parameters"
]
},
"outputs": [
{
"data": {
"text/markdown": [
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADACAIAAAC1TXloAAAZiklEQVR4nOydCVRT19bHd8KkzAjUCUEEJD4pr0LV0larYq2v1gkH7HM5tI4Vi7IABUU/B0Rd4OvDp/ZZWZ+g/bRYxbF14ilWLVQBRYQSBESmgkABQ8ic+y1yeTEmIdxAMMl1/xaLdc85+5y7D/xzsu85595rShAE0AgGg5IZvTqNvMRU3w7oDEUpa9AraUb+RlnTD6a+HdAB/fp1CLRPn3aNapYpaWBrC6Ssraxel5fIa4Fh7CGHfGBW049z5+DkyY6y+fNh7lwt6hoJLi4uw4cPt7GxEQqF9+/fZ7FYdnZ2PB6vvLz8xx9/9Pf3716zWVlZSUlJ58+f9/DwcHR0bGpqMjU1HTZs2Jo1a8aMGaPrTugUwpgB6PhRQ1gY8c03BJ/ffiwQEAcPEmvXqloxmZ23YAwEBweTB/n5+QBw8uRJMhkfH5+ZmUmlhevXr0ulUtX8J0+eAMDx48fJZHNz84YNG8zMzNatW6e5wXv37jU1NWnZD51hxCEHOb6amakbX8+ehSFDYP16sLBoT5qbw5o1wGLB6dNKhhIJ9O0L1K8mDY2FCxeqzQ8MDBw0aFCX1QUCweLFi6VSaZeWdnZ2e/fujYmJSUxM/OmnnzRYrl69urGxscsGtaO5GcRiSpb6+iT1kJwcjSPrggUEj6ecKRAQ8+apNSebSk3VtZevEaURurW1ddWqVXNlREREkGPwnTt3JkyY8Pe///2TTz5JSUmpqakJDg4GgPnz5yckJCg1qDRCkwgEAltb2xkzZpDJqVOnzp0799NPP502bVpDQwOHw1mzZg0ATJs2bePGjQRBXLp0afLkyYsWLfL39z9w4IDWvRKLibg4YsY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V3dydzZLsqqlxcXLSaV4+NjZ01a5aPj4+yx1rebMKWT9tRwOjuZNGqd0YHeXmg1VeQDkZoCxlKmXI1k5PzQ4YM6fmJEKRLDHdzUmf09vBpRMMzoorxCZqkNxaoabDojRiloGUrj72Cxn0viBFglIImV2N0O6CSrWnc94IYAUYpaNnGMdChpsl2ZHdvIMaNAW3wP3v2bGpqqjxZWVlJ3nOhFvm+a1NTqndPdgZ5kywAfPJJj9pBDAEDEvRsGfJkbGysZntyP75E0v6721MTTGZHXZzcoAfGGnKQyFXYvdhD/klANdMG4xY0qUUHByDVqe7mCfVYW3d8BqysUM20woBCjm7z559ACloo7HrtmuIzHREjhQ6CJiHVqfhw0f+iZqsDSpmuGH3IoQT5cFGCANUNLQ4OL0sRukI3QctpaOjQblERmzwgIxOE3tBW0MibCQoaoRUGdFEoEokU76jV4n53BPkvBiToa9eunT17Vp4sLS2dN2+eXj1CjA8DEvQ0GfJkl0vfCKIKxtAIrUBBI7QCBY3QChQ0QitQ0AitQEEjtAIFjdAKFDRCKwxoYSU3N/fevXvyZH5+voabZBFELQYkaEdHR8WH7ebl5enVHcQoMSBBu8mQJ+/cuaNXdxCjBGNohFagoBFagYJGaAUKGqEVKGiEVqCgEVqBgkZoBQoaoRUGtLCi1fOhEUQtHYLOycnx9/fXryvaPh8aQVTpCDm++eabnr+BE0H0Toegf/3110mTJuF+IMTY6RD08uXLDx06FBUVFRoa2tLSomSUmZmpD98QRGs6YuhNmzYBwOXLl9PS0qZMmRISErJ48WKyiM/nX758OSAgQEMr33//fUFBAYvFWrx4sdILvZOTk8vLy8ljFou1YMGCXusLgqhM2wUFBV29enXXrl3u7u4+Mt555x3N4XVMTExZWVlcXFxZWVl0dLRS6aVLl3rBbQRRj/K03c2bN1evXl1cXBwYGGhvbw8Ai
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"drawTestBin()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0, 1, 1, 0, 1 ] should be [ 0, 1, 1, 0, 1 ]\n"
]
}
],
"source": [
"console.log(yPred1, \"should be\", testY.is_even.toArray());"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[33m1.6635532311438688\u001b[39m"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"logreg.loss();"
]
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
}