diff --git a/KernelRegression.ipynb b/KernelRegression.ipynb
index 251906b..8ed79cb 100644
--- a/KernelRegression.ipynb
+++ b/KernelRegression.ipynb
@@ -22634,7 +22634,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.8"
+ "version": "3.8.5"
}
},
"nbformat": 4,
diff --git a/files/est_weights.png b/files/est_weights.png
new file mode 100644
index 0000000..3855016
Binary files /dev/null and b/files/est_weights.png differ
diff --git a/kernel_regression.ipynb b/kernel_regression.ipynb
index d8eb819..47f3a29 100644
--- a/kernel_regression.ipynb
+++ b/kernel_regression.ipynb
@@ -57,8 +57,1158 @@
"* jądro Gaussa\n",
"\\begin{equation}\n",
"K(x) = \\frac1{h\\sqrt{2\\pi}}e^{-\\frac12(\\frac{x - x_i}h)^2}\n",
- "\\end{equation}\n",
- "
"
+ "\\end{equation}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "italic-credits",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ " \n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "application/vnd.plotly.v1+json": {
+ "config": {
+ "plotlyServerURL": "https://plot.ly"
+ },
+ "data": [
+ {
+ "hovertemplate": "x=%{x}
y=%{y}",
+ "legendgroup": "",
+ "line": {
+ "color": "#636efa",
+ "dash": "solid"
+ },
+ "mode": "lines",
+ "name": "",
+ "orientation": "v",
+ "showlegend": false,
+ "type": "scatter",
+ "x": [
+ -4,
+ -3.9,
+ -3.8,
+ -3.6999999999999997,
+ -3.5999999999999996,
+ -3.4999999999999996,
+ -3.3999999999999995,
+ -3.2999999999999994,
+ -3.1999999999999993,
+ -3.099999999999999,
+ -2.999999999999999,
+ -2.899999999999999,
+ -2.799999999999999,
+ -2.699999999999999,
+ -2.5999999999999988,
+ -2.4999999999999987,
+ -2.3999999999999986,
+ -2.2999999999999985,
+ -2.1999999999999984,
+ -2.0999999999999983,
+ -1.9999999999999982,
+ -1.8999999999999981,
+ -1.799999999999998,
+ -1.699999999999998,
+ -1.5999999999999979,
+ -1.4999999999999978,
+ -1.3999999999999977,
+ -1.2999999999999976,
+ -1.1999999999999975,
+ -1.0999999999999974,
+ -0.9999999999999973,
+ -0.8999999999999972,
+ -0.7999999999999972,
+ -0.6999999999999971,
+ -0.599999999999997,
+ -0.4999999999999969,
+ -0.3999999999999968,
+ -0.2999999999999967,
+ -0.19999999999999662,
+ -0.09999999999999654,
+ 3.552713678800501e-15,
+ 0.1000000000000032,
+ 0.20000000000000373,
+ 0.30000000000000426,
+ 0.4000000000000039,
+ 0.5000000000000036,
+ 0.6000000000000041,
+ 0.7000000000000046,
+ 0.8000000000000043,
+ 0.9000000000000039,
+ 1.0000000000000044,
+ 1.100000000000005,
+ 1.2000000000000046,
+ 1.3000000000000043,
+ 1.4000000000000048,
+ 1.5000000000000053,
+ 1.600000000000005,
+ 1.7000000000000046,
+ 1.8000000000000052,
+ 1.9000000000000057,
+ 2.0000000000000053,
+ 2.100000000000005,
+ 2.2000000000000055,
+ 2.300000000000006,
+ 2.4000000000000057,
+ 2.5000000000000053,
+ 2.600000000000006,
+ 2.7000000000000064,
+ 2.800000000000006,
+ 2.9000000000000057,
+ 3.000000000000006,
+ 3.1000000000000068,
+ 3.2000000000000064,
+ 3.300000000000006,
+ 3.4000000000000066,
+ 3.500000000000007,
+ 3.6000000000000068,
+ 3.7000000000000064,
+ 3.800000000000007,
+ 3.9000000000000075
+ ],
+ "xaxis": "x",
+ "y": [
+ 0.00013383022576488537,
+ 0.00019865547139277272,
+ 0.00029194692579146027,
+ 0.0004247802705507522,
+ 0.000611901930113773,
+ 0.0008726826950457617,
+ 0.001232219168473021,
+ 0.0017225689390536843,
+ 0.0023840882014648486,
+ 0.0032668190561999273,
+ 0.004431848411938019,
+ 0.005952532419775869,
+ 0.00791545158297999,
+ 0.010420934814422628,
+ 0.013582969233685661,
+ 0.017528300493568592,
+ 0.02239453029484297,
+ 0.028327037741601276,
+ 0.03547459284623157,
+ 0.04398359598042735,
+ 0.05399096651318825,
+ 0.06561581477467683,
+ 0.07895015830089443,
+ 0.09404907737688725,
+ 0.11092083467945592,
+ 0.12951759566589216,
+ 0.14972746563574535,
+ 0.1713685920478079,
+ 0.19418605498321354,
+ 0.21785217703255116,
+ 0.24197072451914403,
+ 0.2660852498987555,
+ 0.28969155276148345,
+ 0.31225393336676194,
+ 0.3332246028918003,
+ 0.3520653267643001,
+ 0.36827014030332383,
+ 0.38138781546052447,
+ 0.39104269397545616,
+ 0.3969525474770119,
+ 0.3989422804014327,
+ 0.39695254747701164,
+ 0.3910426939754556,
+ 0.3813878154605236,
+ 0.3682701403033227,
+ 0.35206532676429886,
+ 0.33322460289179884,
+ 0.3122539333667603,
+ 0.2896915527614818,
+ 0.2660852498987539,
+ 0.2419707245191423,
+ 0.21785217703254933,
+ 0.19418605498321187,
+ 0.1713685920478064,
+ 0.14972746563574385,
+ 0.1295175956658907,
+ 0.11092083467945468,
+ 0.0940490773768862,
+ 0.07895015830089343,
+ 0.06561581477467589,
+ 0.05399096651318749,
+ 0.04398359598042675,
+ 0.035474592846231015,
+ 0.028327037741600784,
+ 0.022394530294842594,
+ 0.017528300493568304,
+ 0.013582969233685408,
+ 0.010420934814422415,
+ 0.007915451582979832,
+ 0.005952532419775758,
+ 0.004431848411937925,
+ 0.003266819056199852,
+ 0.0023840882014647936,
+ 0.001722568939053646,
+ 0.0012322191684729913,
+ 0.0008726826950457385,
+ 0.0006119019301137573,
+ 0.0004247802705507417,
+ 0.0002919469257914525,
+ 0.00019865547139276686
+ ],
+ "yaxis": "y"
+ }
+ ],
+ "layout": {
+ "legend": {
+ "tracegroupgap": 0
+ },
+ "template": {
+ "data": {
+ "bar": [
+ {
+ "error_x": {
+ "color": "#2a3f5f"
+ },
+ "error_y": {
+ "color": "#2a3f5f"
+ },
+ "marker": {
+ "line": {
+ "color": "#E5ECF6",
+ "width": 0.5
+ }
+ },
+ "type": "bar"
+ }
+ ],
+ "barpolar": [
+ {
+ "marker": {
+ "line": {
+ "color": "#E5ECF6",
+ "width": 0.5
+ }
+ },
+ "type": "barpolar"
+ }
+ ],
+ "carpet": [
+ {
+ "aaxis": {
+ "endlinecolor": "#2a3f5f",
+ "gridcolor": "white",
+ "linecolor": "white",
+ "minorgridcolor": "white",
+ "startlinecolor": "#2a3f5f"
+ },
+ "baxis": {
+ "endlinecolor": "#2a3f5f",
+ "gridcolor": "white",
+ "linecolor": "white",
+ "minorgridcolor": "white",
+ "startlinecolor": "#2a3f5f"
+ },
+ "type": "carpet"
+ }
+ ],
+ "choropleth": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "type": "choropleth"
+ }
+ ],
+ "contour": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "contour"
+ }
+ ],
+ "contourcarpet": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "type": "contourcarpet"
+ }
+ ],
+ "heatmap": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "heatmap"
+ }
+ ],
+ "heatmapgl": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "heatmapgl"
+ }
+ ],
+ "histogram": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "histogram"
+ }
+ ],
+ "histogram2d": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "histogram2d"
+ }
+ ],
+ "histogram2dcontour": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "histogram2dcontour"
+ }
+ ],
+ "mesh3d": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "type": "mesh3d"
+ }
+ ],
+ "parcoords": [
+ {
+ "line": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "parcoords"
+ }
+ ],
+ "pie": [
+ {
+ "automargin": true,
+ "type": "pie"
+ }
+ ],
+ "scatter": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatter"
+ }
+ ],
+ "scatter3d": [
+ {
+ "line": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatter3d"
+ }
+ ],
+ "scattercarpet": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattercarpet"
+ }
+ ],
+ "scattergeo": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattergeo"
+ }
+ ],
+ "scattergl": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattergl"
+ }
+ ],
+ "scattermapbox": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattermapbox"
+ }
+ ],
+ "scatterpolar": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatterpolar"
+ }
+ ],
+ "scatterpolargl": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatterpolargl"
+ }
+ ],
+ "scatterternary": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatterternary"
+ }
+ ],
+ "surface": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "surface"
+ }
+ ],
+ "table": [
+ {
+ "cells": {
+ "fill": {
+ "color": "#EBF0F8"
+ },
+ "line": {
+ "color": "white"
+ }
+ },
+ "header": {
+ "fill": {
+ "color": "#C8D4E3"
+ },
+ "line": {
+ "color": "white"
+ }
+ },
+ "type": "table"
+ }
+ ]
+ },
+ "layout": {
+ "annotationdefaults": {
+ "arrowcolor": "#2a3f5f",
+ "arrowhead": 0,
+ "arrowwidth": 1
+ },
+ "autotypenumbers": "strict",
+ "coloraxis": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "colorscale": {
+ "diverging": [
+ [
+ 0,
+ "#8e0152"
+ ],
+ [
+ 0.1,
+ "#c51b7d"
+ ],
+ [
+ 0.2,
+ "#de77ae"
+ ],
+ [
+ 0.3,
+ "#f1b6da"
+ ],
+ [
+ 0.4,
+ "#fde0ef"
+ ],
+ [
+ 0.5,
+ "#f7f7f7"
+ ],
+ [
+ 0.6,
+ "#e6f5d0"
+ ],
+ [
+ 0.7,
+ "#b8e186"
+ ],
+ [
+ 0.8,
+ "#7fbc41"
+ ],
+ [
+ 0.9,
+ "#4d9221"
+ ],
+ [
+ 1,
+ "#276419"
+ ]
+ ],
+ "sequential": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "sequentialminus": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ]
+ },
+ "colorway": [
+ "#636efa",
+ "#EF553B",
+ "#00cc96",
+ "#ab63fa",
+ "#FFA15A",
+ "#19d3f3",
+ "#FF6692",
+ "#B6E880",
+ "#FF97FF",
+ "#FECB52"
+ ],
+ "font": {
+ "color": "#2a3f5f"
+ },
+ "geo": {
+ "bgcolor": "white",
+ "lakecolor": "white",
+ "landcolor": "#E5ECF6",
+ "showlakes": true,
+ "showland": true,
+ "subunitcolor": "white"
+ },
+ "hoverlabel": {
+ "align": "left"
+ },
+ "hovermode": "closest",
+ "mapbox": {
+ "style": "light"
+ },
+ "paper_bgcolor": "white",
+ "plot_bgcolor": "#E5ECF6",
+ "polar": {
+ "angularaxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ },
+ "bgcolor": "#E5ECF6",
+ "radialaxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ }
+ },
+ "scene": {
+ "xaxis": {
+ "backgroundcolor": "#E5ECF6",
+ "gridcolor": "white",
+ "gridwidth": 2,
+ "linecolor": "white",
+ "showbackground": true,
+ "ticks": "",
+ "zerolinecolor": "white"
+ },
+ "yaxis": {
+ "backgroundcolor": "#E5ECF6",
+ "gridcolor": "white",
+ "gridwidth": 2,
+ "linecolor": "white",
+ "showbackground": true,
+ "ticks": "",
+ "zerolinecolor": "white"
+ },
+ "zaxis": {
+ "backgroundcolor": "#E5ECF6",
+ "gridcolor": "white",
+ "gridwidth": 2,
+ "linecolor": "white",
+ "showbackground": true,
+ "ticks": "",
+ "zerolinecolor": "white"
+ }
+ },
+ "shapedefaults": {
+ "line": {
+ "color": "#2a3f5f"
+ }
+ },
+ "ternary": {
+ "aaxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ },
+ "baxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ },
+ "bgcolor": "#E5ECF6",
+ "caxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ }
+ },
+ "title": {
+ "x": 0.05
+ },
+ "xaxis": {
+ "automargin": true,
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": "",
+ "title": {
+ "standoff": 15
+ },
+ "zerolinecolor": "white",
+ "zerolinewidth": 2
+ },
+ "yaxis": {
+ "automargin": true,
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": "",
+ "title": {
+ "standoff": 15
+ },
+ "zerolinecolor": "white",
+ "zerolinewidth": 2
+ }
+ }
+ },
+ "title": {
+ "text": "Funkcja jądrowa Gaussa"
+ },
+ "xaxis": {
+ "anchor": "y",
+ "domain": [
+ 0,
+ 1
+ ],
+ "title": {
+ "text": "x"
+ }
+ },
+ "yaxis": {
+ "anchor": "x",
+ "domain": [
+ 0,
+ 1
+ ],
+ "title": {
+ "text": "y"
+ }
+ }
+ }
+ },
+ "text/html": [
+ "
"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "import KernelRegression\n",
+ "import plotly.express as px\n",
+ "import numpy as np\n",
+ "kernel_x = np.arange(-4,4,0.1)\n",
+ "col = KernelRegression.kernel_function(1, kernel_x, 0)\n",
+ "px.line(x=kernel_x, y=col, title='Funkcja jądrowa Gaussa')"
]
},
{
@@ -69,8 +1219,993 @@
"* jądro Epanechnikova\n",
"\\begin{equation}\n",
"K(x) = (\\frac34)(1-(\\frac{x - x_i}h)^2) \\text{ dla } {|x|\\leq1}\n",
- "\\end{equation}\n",
- "
"
+ "\\end{equation}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "victorian-equality",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.plotly.v1+json": {
+ "config": {
+ "plotlyServerURL": "https://plot.ly"
+ },
+ "data": [
+ {
+ "hovertemplate": "x=%{x}
y=%{y}",
+ "legendgroup": "",
+ "line": {
+ "color": "#636efa",
+ "dash": "solid"
+ },
+ "mode": "lines",
+ "name": "",
+ "orientation": "v",
+ "showlegend": false,
+ "type": "scatter",
+ "x": [
+ -2,
+ -1.9,
+ -1.7999999999999998,
+ -1.6999999999999997,
+ -1.5999999999999996,
+ -1.4999999999999996,
+ -1.3999999999999995,
+ -1.2999999999999994,
+ -1.1999999999999993,
+ -1.0999999999999992,
+ -0.9999999999999991,
+ -0.899999999999999,
+ -0.7999999999999989,
+ -0.6999999999999988,
+ -0.5999999999999988,
+ -0.49999999999999867,
+ -0.3999999999999986,
+ -0.2999999999999985,
+ -0.1999999999999984,
+ -0.09999999999999831,
+ 1.7763568394002505e-15,
+ 0.10000000000000187,
+ 0.20000000000000195,
+ 0.30000000000000204,
+ 0.40000000000000213,
+ 0.5000000000000022,
+ 0.6000000000000023,
+ 0.7000000000000024,
+ 0.8000000000000025,
+ 0.9000000000000026,
+ 1.0000000000000027,
+ 1.1000000000000028,
+ 1.2000000000000028,
+ 1.300000000000003,
+ 1.400000000000003,
+ 1.500000000000003,
+ 1.6000000000000032,
+ 1.7000000000000033,
+ 1.8000000000000034,
+ 1.9000000000000035
+ ],
+ "xaxis": "x",
+ "y": [
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1.3322676295501878e-15,
+ 0.1425000000000013,
+ 0.27000000000000124,
+ 0.3825000000000012,
+ 0.4800000000000011,
+ 0.562500000000001,
+ 0.6300000000000009,
+ 0.6825000000000007,
+ 0.7200000000000004,
+ 0.7425000000000003,
+ 0.75,
+ 0.7424999999999997,
+ 0.7199999999999994,
+ 0.6824999999999991,
+ 0.6299999999999988,
+ 0.5624999999999983,
+ 0.47999999999999793,
+ 0.3824999999999975,
+ 0.269999999999997,
+ 0.14249999999999655,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+ ],
+ "yaxis": "y"
+ }
+ ],
+ "layout": {
+ "legend": {
+ "tracegroupgap": 0
+ },
+ "template": {
+ "data": {
+ "bar": [
+ {
+ "error_x": {
+ "color": "#2a3f5f"
+ },
+ "error_y": {
+ "color": "#2a3f5f"
+ },
+ "marker": {
+ "line": {
+ "color": "#E5ECF6",
+ "width": 0.5
+ }
+ },
+ "type": "bar"
+ }
+ ],
+ "barpolar": [
+ {
+ "marker": {
+ "line": {
+ "color": "#E5ECF6",
+ "width": 0.5
+ }
+ },
+ "type": "barpolar"
+ }
+ ],
+ "carpet": [
+ {
+ "aaxis": {
+ "endlinecolor": "#2a3f5f",
+ "gridcolor": "white",
+ "linecolor": "white",
+ "minorgridcolor": "white",
+ "startlinecolor": "#2a3f5f"
+ },
+ "baxis": {
+ "endlinecolor": "#2a3f5f",
+ "gridcolor": "white",
+ "linecolor": "white",
+ "minorgridcolor": "white",
+ "startlinecolor": "#2a3f5f"
+ },
+ "type": "carpet"
+ }
+ ],
+ "choropleth": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "type": "choropleth"
+ }
+ ],
+ "contour": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "contour"
+ }
+ ],
+ "contourcarpet": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "type": "contourcarpet"
+ }
+ ],
+ "heatmap": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "heatmap"
+ }
+ ],
+ "heatmapgl": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "heatmapgl"
+ }
+ ],
+ "histogram": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "histogram"
+ }
+ ],
+ "histogram2d": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "histogram2d"
+ }
+ ],
+ "histogram2dcontour": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "histogram2dcontour"
+ }
+ ],
+ "mesh3d": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "type": "mesh3d"
+ }
+ ],
+ "parcoords": [
+ {
+ "line": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "parcoords"
+ }
+ ],
+ "pie": [
+ {
+ "automargin": true,
+ "type": "pie"
+ }
+ ],
+ "scatter": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatter"
+ }
+ ],
+ "scatter3d": [
+ {
+ "line": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatter3d"
+ }
+ ],
+ "scattercarpet": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattercarpet"
+ }
+ ],
+ "scattergeo": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattergeo"
+ }
+ ],
+ "scattergl": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattergl"
+ }
+ ],
+ "scattermapbox": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scattermapbox"
+ }
+ ],
+ "scatterpolar": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatterpolar"
+ }
+ ],
+ "scatterpolargl": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatterpolargl"
+ }
+ ],
+ "scatterternary": [
+ {
+ "marker": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "type": "scatterternary"
+ }
+ ],
+ "surface": [
+ {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ },
+ "colorscale": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "type": "surface"
+ }
+ ],
+ "table": [
+ {
+ "cells": {
+ "fill": {
+ "color": "#EBF0F8"
+ },
+ "line": {
+ "color": "white"
+ }
+ },
+ "header": {
+ "fill": {
+ "color": "#C8D4E3"
+ },
+ "line": {
+ "color": "white"
+ }
+ },
+ "type": "table"
+ }
+ ]
+ },
+ "layout": {
+ "annotationdefaults": {
+ "arrowcolor": "#2a3f5f",
+ "arrowhead": 0,
+ "arrowwidth": 1
+ },
+ "autotypenumbers": "strict",
+ "coloraxis": {
+ "colorbar": {
+ "outlinewidth": 0,
+ "ticks": ""
+ }
+ },
+ "colorscale": {
+ "diverging": [
+ [
+ 0,
+ "#8e0152"
+ ],
+ [
+ 0.1,
+ "#c51b7d"
+ ],
+ [
+ 0.2,
+ "#de77ae"
+ ],
+ [
+ 0.3,
+ "#f1b6da"
+ ],
+ [
+ 0.4,
+ "#fde0ef"
+ ],
+ [
+ 0.5,
+ "#f7f7f7"
+ ],
+ [
+ 0.6,
+ "#e6f5d0"
+ ],
+ [
+ 0.7,
+ "#b8e186"
+ ],
+ [
+ 0.8,
+ "#7fbc41"
+ ],
+ [
+ 0.9,
+ "#4d9221"
+ ],
+ [
+ 1,
+ "#276419"
+ ]
+ ],
+ "sequential": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ],
+ "sequentialminus": [
+ [
+ 0,
+ "#0d0887"
+ ],
+ [
+ 0.1111111111111111,
+ "#46039f"
+ ],
+ [
+ 0.2222222222222222,
+ "#7201a8"
+ ],
+ [
+ 0.3333333333333333,
+ "#9c179e"
+ ],
+ [
+ 0.4444444444444444,
+ "#bd3786"
+ ],
+ [
+ 0.5555555555555556,
+ "#d8576b"
+ ],
+ [
+ 0.6666666666666666,
+ "#ed7953"
+ ],
+ [
+ 0.7777777777777778,
+ "#fb9f3a"
+ ],
+ [
+ 0.8888888888888888,
+ "#fdca26"
+ ],
+ [
+ 1,
+ "#f0f921"
+ ]
+ ]
+ },
+ "colorway": [
+ "#636efa",
+ "#EF553B",
+ "#00cc96",
+ "#ab63fa",
+ "#FFA15A",
+ "#19d3f3",
+ "#FF6692",
+ "#B6E880",
+ "#FF97FF",
+ "#FECB52"
+ ],
+ "font": {
+ "color": "#2a3f5f"
+ },
+ "geo": {
+ "bgcolor": "white",
+ "lakecolor": "white",
+ "landcolor": "#E5ECF6",
+ "showlakes": true,
+ "showland": true,
+ "subunitcolor": "white"
+ },
+ "hoverlabel": {
+ "align": "left"
+ },
+ "hovermode": "closest",
+ "mapbox": {
+ "style": "light"
+ },
+ "paper_bgcolor": "white",
+ "plot_bgcolor": "#E5ECF6",
+ "polar": {
+ "angularaxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ },
+ "bgcolor": "#E5ECF6",
+ "radialaxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ }
+ },
+ "scene": {
+ "xaxis": {
+ "backgroundcolor": "#E5ECF6",
+ "gridcolor": "white",
+ "gridwidth": 2,
+ "linecolor": "white",
+ "showbackground": true,
+ "ticks": "",
+ "zerolinecolor": "white"
+ },
+ "yaxis": {
+ "backgroundcolor": "#E5ECF6",
+ "gridcolor": "white",
+ "gridwidth": 2,
+ "linecolor": "white",
+ "showbackground": true,
+ "ticks": "",
+ "zerolinecolor": "white"
+ },
+ "zaxis": {
+ "backgroundcolor": "#E5ECF6",
+ "gridcolor": "white",
+ "gridwidth": 2,
+ "linecolor": "white",
+ "showbackground": true,
+ "ticks": "",
+ "zerolinecolor": "white"
+ }
+ },
+ "shapedefaults": {
+ "line": {
+ "color": "#2a3f5f"
+ }
+ },
+ "ternary": {
+ "aaxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ },
+ "baxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ },
+ "bgcolor": "#E5ECF6",
+ "caxis": {
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": ""
+ }
+ },
+ "title": {
+ "x": 0.05
+ },
+ "xaxis": {
+ "automargin": true,
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": "",
+ "title": {
+ "standoff": 15
+ },
+ "zerolinecolor": "white",
+ "zerolinewidth": 2
+ },
+ "yaxis": {
+ "automargin": true,
+ "gridcolor": "white",
+ "linecolor": "white",
+ "ticks": "",
+ "title": {
+ "standoff": 15
+ },
+ "zerolinecolor": "white",
+ "zerolinewidth": 2
+ }
+ }
+ },
+ "title": {
+ "text": "Funkcja jądrowa Epanechnikova"
+ },
+ "xaxis": {
+ "anchor": "y",
+ "domain": [
+ 0,
+ 1
+ ],
+ "title": {
+ "text": "x"
+ }
+ },
+ "yaxis": {
+ "anchor": "x",
+ "domain": [
+ 0,
+ 1
+ ],
+ "title": {
+ "text": "y"
+ }
+ }
+ }
+ },
+ "text/html": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "kernel_x = np.arange(-2,2,0.1)\n",
+ "col = KernelRegression.epanechnikov_list(1, kernel_x, 0)\n",
+ "px.line(x=kernel_x, y=col, title='Funkcja jądrowa Epanechnikova')"
]
},
{
@@ -81,22 +2216,24 @@
"Istotne znaczenie ma nie tylko dobór jądra, ale również parametru wygładzania, czyli szerokości okna. W zależności od niego, punkty są grupowane i dla każdej grupy wyliczana jest wartość funkcji. Jeśli okno będzie zbyt szerokie, funkcja będzie bardziej przypominała prostą (under-fitting). Natomiast jeśli będzie zbyt wąskie, funkcja będzie za bardzo \"skakać\" (over-fitting).\n",
"\n",
"Wyliczenie wartości funkcji polega na wzięciu średniej ważonej z $y_{i}$\n",
- " dla takich $x_{i}$, które znajdują się blisko x, dla którego wyznaczamy wartość. Wagi przy $y_{i}$ dla x sumują się do 1 i są wyższe, kiedy $x_{i}$ jest bliżej x oraz niższe w przeciwnym przypadku."
+ " dla takich $x_{i}$, które znajdują się blisko x, dla którego wyznaczamy wartość. Wagi przy $y_{i}$ dla x sumują się do 1 i są wyższe, kiedy $x_{i}$ jest bliżej x oraz niższe w przeciwnym przypadku.\n",
+ "
\n",
+ "\\begin{equation}w_i= \\frac{K_i}{\\sum\\limits_{i=1}^n K_i} \\end{equation}\n",
+ "
\n",
+ "\\begin{equation} Y=w_1*x_1+w_2*x_2+ \\text{...} +w_n*x_n \\end{equation}
\n",
+ "
"
]
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 3,
"id": "4ae1bce9",
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
- "import numpy as np\n",
- "import plotly.express as px\n",
"import plotly.graph_objs as go\n",
"import pandas as pd \n",
- "import KernelRegression\n",
"\n",
"fires_thefts = pd.read_csv('fires_thefts.csv', names=['x','y'])\n",
"XXX = np.sort(np.array(fires_thefts.x))\n",
@@ -105,7 +2242,7 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 4,
"id": "loved-clinton",
"metadata": {},
"outputs": [],
@@ -113,31 +2250,42 @@
"\n",
"dropdown_bw = widgets.Dropdown(options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], value=1, description='Szerokość okna')\n",
"\n",
- "def interactive_kernel(bw_manual):\n",
- " fig = px.scatter(x=XXX,y=YYY)\n",
- " for i in range(0, len(XXX), bw_manual):\n",
- " fig.add_vline(x=i)\n",
- " fig.show()\n",
- " \n",
+ "def interactive_kernel(bw_manual): \n",
" Y_pred_gauss = KernelRegression.ker_reg(XXX, YYY, bw_manual, 'gauss')\n",
" Y_pred_epanechnikov = KernelRegression.ker_reg(XXX, YYY, bw_manual, 'epanechnikov')\n",
"\n",
" fig = px.scatter(x=XXX,y=YYY)\n",
" fig.add_trace(go.Scatter(x=XXX, y=np.array(Y_pred_gauss), name='Gauss', mode='lines'))\n",
" fig.add_trace(go.Scatter(x=XXX, y=np.array(Y_pred_epanechnikov), name='Epanechnikov', mode='lines'))\n",
+ " fig.show()\n",
+ " \n",
+ " # kernel regression\n",
+ " kernel_x = np.arange(min(XXX)-5,max(XXX)+5, 0.1)\n",
+ "\n",
+ " ## Plotting gaussian for all input x points \n",
+ " kernel_fns = {'kernel_x': kernel_x}\n",
+ " for input_x in XXX: \n",
+ " input_string= 'x_value_{}'.format(np.round(input_x,2)) \n",
+ " kernel_fns[input_string] = KernelRegression.kernel_function(bw_manual, kernel_x, input_x)\n",
+ "\n",
+ " kernels_df = pd.DataFrame(data=kernel_fns)\n",
+ " y_all = kernels_df.drop(columns='kernel_x')\n",
+ " fig = px.line(kernels_df, x='kernel_x', y=y_all.columns, title='Gaussian for all input points', range_x=[min(XXX)-5,max(XXX)+5]) \n",
" fig.show()"
]
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 5,
"id": "injured-english",
- "metadata": {},
+ "metadata": {
+ "scrolled": false
+ },
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "a38d1ceed30b42d19a56951cf88e16e6",
+ "model_id": "ad45339f5a46492393ca1158653290e3",
"version_major": 2,
"version_minor": 0
},
@@ -154,7 +2302,7 @@
""
]
},
- "execution_count": 12,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -165,7 +2313,452 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 43,
+ "id": "collect-imperial",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Input_x | \n",
+ " kernel_x | \n",
+ " weigth | \n",
+ " Y | \n",
+ " Y=w0*x0+w1*x1+...+w41*x41 | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " 2.0 | \n",
+ " K(2.0) | \n",
+ " 0.1329807601 | \n",
+ " 29 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " 2.0 | \n",
+ " K(2.2) | \n",
+ " 0.1326855754 | \n",
+ " 44 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " 2.0 | \n",
+ " K(2.2) | \n",
+ " 0.1326855754 | \n",
+ " 36 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " 2.0 | \n",
+ " K(2.5) | \n",
+ " 0.1311465720 | \n",
+ " 37 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " 2.0 | \n",
+ " K(3.4) | \n",
+ " 0.1192611431 | \n",
+ " 53 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " 2.0 | \n",
+ " K(3.6) | \n",
+ " 0.1153512977 | \n",
+ " 68 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " 2.0 | \n",
+ " K(4.0) | \n",
+ " 0.1064826685 | \n",
+ " 75 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " 2.0 | \n",
+ " K(4.8) | \n",
+ " 0.0860259420 | \n",
+ " 18 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ " 2.0 | \n",
+ " K(5.0) | \n",
+ " 0.0806569082 | \n",
+ " 31 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 9 | \n",
+ " 2.0 | \n",
+ " K(5.4) | \n",
+ " 0.0699640987 | \n",
+ " 25 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 10 | \n",
+ " 2.0 | \n",
+ " K(5.6) | \n",
+ " 0.0647286850 | \n",
+ " 34 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 11 | \n",
+ " 2.0 | \n",
+ " K(5.7) | \n",
+ " 0.0621560962 | \n",
+ " 14 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 12 | \n",
+ " 2.0 | \n",
+ " K(6.2) | \n",
+ " 0.0499091552 | \n",
+ " 11 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 13 | \n",
+ " 2.0 | \n",
+ " K(6.9) | \n",
+ " 0.0350338791 | \n",
+ " 11 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 14 | \n",
+ " 2.0 | \n",
+ " K(7.2) | \n",
+ " 0.0296061537 | \n",
+ " 22 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 15 | \n",
+ " 2.0 | \n",
+ " K(7.3) | \n",
+ " 0.0279285343 | \n",
+ " 16 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 16 | \n",
+ " 2.0 | \n",
+ " K(7.7) | \n",
+ " 0.0218719383 | \n",
+ " 27 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 17 | \n",
+ " 2.0 | \n",
+ " K(8.6) | \n",
+ " 0.0118248643 | \n",
+ " 9 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 18 | \n",
+ " 2.0 | \n",
+ " K(9.0) | \n",
+ " 0.0087406297 | \n",
+ " 29 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 19 | \n",
+ " 2.0 | \n",
+ " K(9.5) | \n",
+ " 0.0058427668 | \n",
+ " 30 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 20 | \n",
+ " 2.0 | \n",
+ " K(10.5) | \n",
+ " 0.0024020333 | \n",
+ " 40 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 21 | \n",
+ " 2.0 | \n",
+ " K(10.5) | \n",
+ " 0.0024020333 | \n",
+ " 32 | \n",
+ " 54.121103 | \n",
+ "
\n",
+ " \n",
+ " 22 | \n",
+ " 2.0 | \n",
+ " K(10.7) | \n",
+ " 0.0019841775 | \n",
+ " 41 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 23 | \n",
+ " 2.0 | \n",
+ " K(10.8) | \n",
+ " 0.0018003521 | \n",
+ " 147 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 24 | \n",
+ " 2.0 | \n",
+ " K(11.0) | \n",
+ " 0.0014772828 | \n",
+ " 22 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 25 | \n",
+ " 2.0 | \n",
+ " K(11.3) | \n",
+ " 0.0010889397 | \n",
+ " 29 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 26 | \n",
+ " 2.0 | \n",
+ " K(11.9) | \n",
+ " 0.0005741896 | \n",
+ " 46 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 27 | \n",
+ " 2.0 | \n",
+ " K(12.2) | \n",
+ " 0.0004107397 | \n",
+ " 23 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 28 | \n",
+ " 2.0 | \n",
+ " K(15.1) | \n",
+ " 0.0000096222 | \n",
+ " 4 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 29 | \n",
+ " 2.0 | \n",
+ " K(15.1) | \n",
+ " 0.0000096222 | \n",
+ " 31 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 30 | \n",
+ " 2.0 | \n",
+ " K(16.5) | \n",
+ " 0.0000011246 | \n",
+ " 39 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 31 | \n",
+ " 2.0 | \n",
+ " K(17.4) | \n",
+ " 0.0000002522 | \n",
+ " 15 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 32 | \n",
+ " 2.0 | \n",
+ " K(18.4) | \n",
+ " 0.0000000431 | \n",
+ " 32 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 33 | \n",
+ " 2.0 | \n",
+ " K(18.5) | \n",
+ " 0.0000000359 | \n",
+ " 27 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 34 | \n",
+ " 2.0 | \n",
+ " K(21.6) | \n",
+ " 0.0000000001 | \n",
+ " 32 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 35 | \n",
+ " 2.0 | \n",
+ " K(21.8) | \n",
+ " 0.0000000000 | \n",
+ " 34 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 36 | \n",
+ " 2.0 | \n",
+ " K(23.3) | \n",
+ " 0.0000000000 | \n",
+ " 17 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 37 | \n",
+ " 2.0 | \n",
+ " K(28.6) | \n",
+ " 0.0000000000 | \n",
+ " 46 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 38 | \n",
+ " 2.0 | \n",
+ " K(29.1) | \n",
+ " 0.0000000000 | \n",
+ " 42 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 39 | \n",
+ " 2.0 | \n",
+ " K(34.1) | \n",
+ " 0.0000000000 | \n",
+ " 43 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 40 | \n",
+ " 2.0 | \n",
+ " K(36.2) | \n",
+ " 0.0000000000 | \n",
+ " 34 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " 41 | \n",
+ " 2.0 | \n",
+ " K(39.7) | \n",
+ " 0.0000000000 | \n",
+ " 19 | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Input_x kernel_x weigth Y Y=w0*x0+w1*x1+...+w41*x41\n",
+ "0 2.0 K(2.0) 0.1329807601 29 \n",
+ "1 2.0 K(2.2) 0.1326855754 44 \n",
+ "2 2.0 K(2.2) 0.1326855754 36 \n",
+ "3 2.0 K(2.5) 0.1311465720 37 \n",
+ "4 2.0 K(3.4) 0.1192611431 53 \n",
+ "5 2.0 K(3.6) 0.1153512977 68 \n",
+ "6 2.0 K(4.0) 0.1064826685 75 \n",
+ "7 2.0 K(4.8) 0.0860259420 18 \n",
+ "8 2.0 K(5.0) 0.0806569082 31 \n",
+ "9 2.0 K(5.4) 0.0699640987 25 \n",
+ "10 2.0 K(5.6) 0.0647286850 34 \n",
+ "11 2.0 K(5.7) 0.0621560962 14 \n",
+ "12 2.0 K(6.2) 0.0499091552 11 \n",
+ "13 2.0 K(6.9) 0.0350338791 11 \n",
+ "14 2.0 K(7.2) 0.0296061537 22 \n",
+ "15 2.0 K(7.3) 0.0279285343 16 \n",
+ "16 2.0 K(7.7) 0.0218719383 27 \n",
+ "17 2.0 K(8.6) 0.0118248643 9 \n",
+ "18 2.0 K(9.0) 0.0087406297 29 \n",
+ "19 2.0 K(9.5) 0.0058427668 30 \n",
+ "20 2.0 K(10.5) 0.0024020333 40 \n",
+ "21 2.0 K(10.5) 0.0024020333 32 54.121103\n",
+ "22 2.0 K(10.7) 0.0019841775 41 \n",
+ "23 2.0 K(10.8) 0.0018003521 147 \n",
+ "24 2.0 K(11.0) 0.0014772828 22 \n",
+ "25 2.0 K(11.3) 0.0010889397 29 \n",
+ "26 2.0 K(11.9) 0.0005741896 46 \n",
+ "27 2.0 K(12.2) 0.0004107397 23 \n",
+ "28 2.0 K(15.1) 0.0000096222 4 \n",
+ "29 2.0 K(15.1) 0.0000096222 31 \n",
+ "30 2.0 K(16.5) 0.0000011246 39 \n",
+ "31 2.0 K(17.4) 0.0000002522 15 \n",
+ "32 2.0 K(18.4) 0.0000000431 32 \n",
+ "33 2.0 K(18.5) 0.0000000359 27 \n",
+ "34 2.0 K(21.6) 0.0000000001 32 \n",
+ "35 2.0 K(21.8) 0.0000000000 34 \n",
+ "36 2.0 K(23.3) 0.0000000000 17 \n",
+ "37 2.0 K(28.6) 0.0000000000 46 \n",
+ "38 2.0 K(29.1) 0.0000000000 42 \n",
+ "39 2.0 K(34.1) 0.0000000000 43 \n",
+ "40 2.0 K(36.2) 0.0000000000 34 \n",
+ "41 2.0 K(39.7) 0.0000000000 19 "
+ ]
+ },
+ "execution_count": 43,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "bw_manual = 3\n",
+ "\n",
+ "kernel_x = XXX\n",
+ "col3 = KernelRegression.kernel_function(bw_manual, kernel_x, XXX[0])\n",
+ "# Dataframe for a single observation point x_i. In the code x_i comes from new_x\n",
+ "data = {'Input_x': [XXX[0] for x in kernel_x],\n",
+ " 'kernel_x': kernel_x,\n",
+ " 'weigth': col3,\n",
+ " 'Y': YYY,\n",
+ " 'Y=w0*x0+w1*x1+...+w41*x41': ''\n",
+ " }\n",
+ "single_pt_KE = pd.DataFrame(data=data)\n",
+ "single_pt_KE.at[len(YYY)//2, 'Y=w0*x0+w1*x1+...+w41*x41'] = sum([col3[index]*YYY[index] for index, x in enumerate(kernel_x)])\n",
+ "single_pt_KE['weigth'] = single_pt_KE['weigth'].map('{:,.10f}'.format)\n",
+ "single_pt_KE['kernel_x'] = single_pt_KE['kernel_x'].map('K({})'.format)\n",
+ "single_pt_KE"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
"id": "0406c2c4",
"metadata": {},
"outputs": [
@@ -530,14 +3123,14 @@
34.3922802405316,
34.354702225608875,
34.342176220634634,
- 34.29207220073767,
+ 34.29207220073768,
34.17933815596951,
34.12923413607255,
34.06660411120134,
33.941344061458935,
33.941344061458935,
33.91629205151045,
- 33.90376604653621,
+ 33.90376604653622,
33.87871403658774,
33.841136021665015,
33.76597999181957,
@@ -550,12 +3143,12 @@
32.93926366351969,
32.55095750931823,
32.52590549936975,
- 32.338015424756136,
+ 32.33801542475614,
31.674137161121386,
31.611507136250186,
30.985206887538155,
30.7221607830791,
- 30.28375060898068
+ 30.283750608980682
]
}
],
@@ -1395,9 +3988,9 @@
}
},
"text/html": [
- "