{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Regressions\n",
    "\n",
    "$X = (0,1)$\n",
    "\n",
    "$Y = sin(2\\pi X)$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "![name](data:image/png;base64,[encoded data, 29804 characters])"
      ]
     },
     "execution_count": 24,
     "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: 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: \"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",
    "\n",
    "draw(df.x, df.y);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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
}
