shortcuts/notebooks/regressions.ipynb

233 lines
176 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
]
2024-10-01 02:37:42 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ElasticNet"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqAAAAGACAIAAAD9Gkc5AABy2UlEQVR4nOzdB1QTWRcA4BtCRzooKCIoTVABK5ZVEez+NsQCqCAqCisL9t7WsquuqyyiKK6o2HtbrKjYFRtSRaQKCCgtEErKf0IwhtASUoZyv5OzJ3mZeXNhIzcz89670kwmExBCCCHUskgTHQBCSLzu3r17+/ZtMpm8fft2omNBCEmOFNEBIIRE4O3bt56engoKClZWViNHjrS3t3d3d8/NzQUAe3v7Ll26hISEEB0jQkiiMMEj1BJYW1tv3ry5tLR07ty5t27dun79+vfv3/v27Uuj0fjv5MqVK+KMESEkUZjgEWqB5OXlFy5cmJSU9Pr167q24Rl/k5GRsXjxYolEhxCSBEzwCLVMioqKAPD161eediaTuXv37tGjR7u6ug4ZMiQgIAAA4uPjXV1dMzMzZ8yYcezYMYJCRgiJEg6yQ6hlCg8Pl5OT69WrF097SEiIn59fTEyMoqJiTk6OkZFRhw4dJkyY4ODgEBsbe+rUKYLiRQiJGCZ4hFqU6Ojoc+fOvXz5Mjg4ODAwsEOHDjwbHD58eNSoUezze21t7eHDhx85cmTChAkExYsQEhe8RI9Qi5KXl5efnz9s2LDY2NjZs2fX3CA5Oblt27acl7q6usnJyZKNESEkCXgGj1CLMmjQoHnz5tWzgZKSUllZGedlaWmplpaWREJDCEkUnsEj1LpYWlp++vSJ8zIuLq579+7s5wwGg7i4EEIihgkeoRaCSqUCQElJSc31p5mV2M9Xr1796NGj+/fv02i006dPp6WlLVu2DABMTEwyMzNv374dGRlJRPgIIREj4Vr0CLUACQkJx48fZ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IUCiU6OhoAIiMjNTQ04uPjASA+Pr5nz57Z2dn5+fkZGRlFRUWdOnXq0qXL/Pnzx48fX1JS8u3bt7S0NAqF8uDBg9LSUltb29u3b3fs2LF///5KSkqbNm1auHDh5s2bc3Nzt27dev78eRKJlJmZmZqaWlhYGBcXZ2Zm9s8///Tv39/V1bVXr16pqalSUlKfPn0aMmSIdM0zchFpKmvRsxN8UFBQzbfi4+NNTU2JCKoFKimBoiJo147oOMQJPzBIIPiBacE+fPgQHR2dl5eno6MzcODAtpUnNykpKXFxcewNevToER0dzZ4rb2Njk5CQ8O3bNwAwMzPr1KlTZmbm7du3tbS0bG1to6Ki8vLyzM3NU1NTs7KysrOzdXR0Ro8eLf/jqnhMTMyrV6+0tbVtbGzYt+FfvXr1/ft39rv29vZkMjk3Nzc8PLysrGzEiBGRkZFlZWWDBg1qw1kqRNQwwSOhMJkgwTGhfMEPDBIIfmCQQJrRBwZH0bdSTCZkZ0N5uVCdFBfD0aOQnCyyqBBCCIlKU1mLHkkYkwnBwTB5MvA94oRXYSGcPg0yMuK6o48QQgJxdXWt661169Z16dKlcd0+f/781KlTnMnxpaWlVlZWXbp0GTdunHz1UetNDSb4VkpKCuTkoKSkkbvTaHDqFCgowNSp0IhPeGEhtGlT33A8hBASVGpqanBwsLKyckJCQr9+/Q4fPvy///2PSqXu3LkzJyeHnwSfm5urpaXF02hjY6OlpWVsbLx//34HB4enT5+WlJRs3rx5yZIl//zzz/jx4+vpsKCgQFFRUUZGRugfrjHwT2xrceECVC68+JOSUuMTvLQ0DBsG06c3JrtTqXDgANQokYwQQkKxs7PT19dXV1dXVFSsrG6lqK2tra+vb2dnp6CgwE8PY8aModddfatNmzba2tpmZmYzZsx4+/attbX19OnTE+taubPSvHnzJFNXplZ4Bt8q5OfDp0/Qt2+1xg4dQFa28
]
},
"execution_count": 4,
"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",
"execution_count": 5,
"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/PjxCRMmsK7vtbS0xo4dGxAQ4ODgQFC8CCFhwVv0CLUrBQUFhYWFtra2cXFxCxYsaLhBamqqtrY2e1FPTy81NVW0MSKERAGv4BFqV4YPH75kyZJmNlBQUKisrGQvVlRUaGpqiiQ0hJBI4RU8Qh1Lv379EhMT2YsfPnzo06cP6zWdTicuLoSQgGGCR6idoFAoAFBeXt6w/jSjBuu1p6fno0ePHjx4QKVSQ0JC0tPT169fDwCmpqZZWVl37tx59+4dEeEjhASMhLXoEWoHEhISgoKCWJfgsrKya9asYXWjY5WqffToEY1GU1VVdXN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tLS2NjYwHg3bt36urq8fHxABAfHz9gwICcnJzCwsLMzMySkhIjI6Nu3bq5urpOnjy5vLw8Ly8vPT29tLT04cOHFRUVNjY2d+7c6dSp09ChQxUUFLZt27Zs2bLt27d//fp1586doaGhJBIpKysrLS2tuLj4w4cPZmZmBw8eHDp0qLOzs6WlZVpamoSERGJi4qhRoyQbXpELSFupRc9K8P7+/g1XxcfH9+jRg4ig2qHycigpAR0douMQJnzDIJ7gG6Ydi46Ojo2NLSgo0NXVtba21q65uPn06dOHDx9YG/Tt2zc2NpY1Vn7IkCEJCQl5eXkAYGZmZmRklJWVdefOHU1NTRsbm5iYmIKCgp49e6alpWVnZ+fk5Ojq6trb28t+uyv+/v37iIgILS2tIUOGsB7DR0RE5Ofns9ba2dmRyeSvX7+Gh4dXVlaOGzfu3bt3lZWVw4cPV2SXChE0TPCILwwGiLBPKFfwDYN4gm8YxBMxesNgL/oOisGAnByoquLrIGVlcPIkpKYKLCqEEEKC0lZq0SMRYzAgMBCmTQOue5xwKi6GkBCQkhLWE32EEOKJs7NzU6t+/fXXbt26te6wz58/P3v2LHtwfEVFhYWFRbdu3SZNmiRbv9d6W4MJvoOSkAAZGSgvb+XuVCqcPQtycjBrFrTiHV5cDIqKzXXHQwghXqWlpQUGBiopKSUkJAwePPj48eM//vgjhULZu3dvbm4uNwn+69evmpqaHI1DhgzR1NTs3r374cOHp0+f/vTp0/Ly8u3bt69du/bgwYOTJ09u5oBFRUXy8vJSUlJ8/+NaAz9iO4oLF6Cm8OJ3CgqtT/CSkmBrC3PmtCa7Uyhw5Ag0mCIZIYT4MmbMmM6dO6upqcnLy9fMbiWvpaXVuXPnMWPGyMnJcXOEH374gdb07FuKiopaWlpmZmZz58598+ZN//7958yZk9RU5c4aS5YsEc28Mo3CK/gOobAQEhPByqpeo4EBSEu3/
]
},
"execution_count": 5,
"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-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
}