2024-09-29 12:14:44 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2024-09-29 18:27:50 +00:00
|
|
|
"execution_count": 1,
|
2024-09-29 12:14:44 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
2024-09-29 18:27:50 +00:00
|
|
|
"Stats initialized\n",
|
2024-09-29 12:14:44 +00:00
|
|
|
"\n",
|
|
|
|
"Linear Regression Line:\n",
|
2024-09-30 17:12:28 +00:00
|
|
|
"\tEstimated offset is: -2.258540\n",
|
|
|
|
"\tEstimated slope is: -0.024285\n",
|
|
|
|
"\tR^2 is: 0.882633\n"
|
2024-09-29 12:14:44 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2024-09-30 17:12:28 +00:00
|
|
|
"import stats from \"../stat/mod.ts\";\n",
|
2024-09-29 12:14:44 +00:00
|
|
|
"\n",
|
|
|
|
"const xs = [];\n",
|
|
|
|
"const ys = [];\n",
|
|
|
|
"\n",
|
|
|
|
"for (let i = 0; i < 100; i++) {\n",
|
2024-09-29 14:32:23 +00:00
|
|
|
" xs.push(i);\n",
|
2024-09-30 17:12:28 +00:00
|
|
|
" ys.push(1 - Math.log(2 * i + 3 + Math.random() * 10));\n",
|
2024-09-29 12:14:44 +00:00
|
|
|
"}\n",
|
|
|
|
"\n",
|
|
|
|
"const linreg = stats.LinearRegression(xs, ys, [], false);\n",
|
|
|
|
"const r = stats.RSquared(xs, ys, [], linreg.alpha, linreg.beta);\n",
|
|
|
|
"\n",
|
|
|
|
"console.log(\"\\nLinear Regression Line:\");\n",
|
|
|
|
"console.log(\"\\tEstimated offset is: \", linreg.alpha.toFixed(6));\n",
|
|
|
|
"console.log(\"\\tEstimated slope is: \", linreg.beta.toFixed(6));\n",
|
2024-09-29 14:32:23 +00:00
|
|
|
"console.log(\"\\tR^2 is: \", r.toFixed(6));"
|
2024-09-29 12:14:44 +00:00
|
|
|
]
|
2024-09-29 18:27:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2024-09-30 17:12:28 +00:00
|
|
|
"execution_count": 7,
|
2024-09-29 18:27:50 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/markdown": [
|
2024-09-30 17:12:28 +00:00
|
|
|
"![name](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtAAAAHgCAIAAAADp837AABwpElEQVR4nOzdB1gU194G8HeXXgWk2giIgL1iReyIDSvYsBdsQTQW7OVqNMYYNXaNsWEjKonGEFvs3ajEghgUURRREWUpywL7Pev6ISr23R0W3t/lMTuz58z8J9f78N4zZ87oyuVyEBEREamTWOgCiIiIqPDTFboAIipAypYtW7p0aXNzc7lcvn///goVKpQoUSI9PT0mJmb58uWtWrUSukAi0lYMHET0Sp06dTZv3gwgISHBwcGhf//+I0aMALBhw4bs7OyPOcLBgwfr1Kljamqq/mKJSJvwlgoRvdK3b99893t6erq6uub7Vd55YNnZ2YGBgampqWorkIi0FUc4iOgVb2/vfPfb29uPGjXq4cOHhoaGenp6P//8s76+/pkzZ8aMGVOmTJmnT582adJk0KBB33zzTUxMTGBgYLVq1aZPn67x8omo4OIIBxF92MyZM2/fvh0eHr5169a4uDhlmAgKCurbt29oaOhvv/1mampqYWExbNgwACtXrmTaIKI3MHAQ0YeFhobmzhitW7fuiRMnAGRmZu7du/f58+d6enpDhw4VukYiKtB4S4WIPiArK+v+/fs7d+6MjIxUzidVzgmdO3dunz59Spcu7efnN3PmzBIlSghdKREVXAwcRPQBurq6+vr6fn5+QUFBefe3bNkyNjY2PDx86tSpLVq0uHr1qnA1ElFBx1sqRPRhrq6uly9ffmPnqVOnDA0Nu3Xrtm7dumvXrkkkEuX+nJwcIWokogKNgYOI8qFMD2lpacqnXkNCQtavX//dd99dvH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count": 7,
|
2024-09-29 18:27:50 +00:00
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2024-09-30 17:12:28 +00:00
|
|
|
"import plot from \"../plot/mod.ts?6\";\n",
|
2024-09-29 18:27:50 +00:00
|
|
|
"\n",
|
2024-09-30 17:12:28 +00:00
|
|
|
"plot.DrawPlot(\n",
|
|
|
|
" { \n",
|
|
|
|
" title: \"Test\", \n",
|
|
|
|
" //XLabel: \"X\", \n",
|
|
|
|
" YLabel: \"Y\", \n",
|
|
|
|
" width: 7.5, \n",
|
|
|
|
" height: 5 \n",
|
|
|
|
" }, \n",
|
|
|
|
" { type: \"scatter\", data: [xs, ys], legend: \"Data\", glyphStyleColor: \"#ff0000\" },\n",
|
|
|
|
" { type: \"line\", data: [xs, ys], legend: \"Line\", lineStyleColor: \"#00ff00\" },\n",
|
|
|
|
");\n"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 3,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
|
|
|
"{ alpha: \u001b[33m-2.258539916346346\u001b[39m, beta: \u001b[33m-0.02428470043839821\u001b[39m }"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"execution_count": 3,
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"stats.LinearRegression(xs, ys, [], false);"
|
2024-09-29 18:27:50 +00:00
|
|
|
]
|
2024-09-29 12:14:44 +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
|
|
|
|
}
|