{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"import plotly.express as px\n",
"from statsmodels.nonparametric.kernel_regression import KernelReg\n",
"import plotly.graph_objs as go\n",
"import pandas as pd \n",
"import KernelRegression"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(1)# xwidth controls the range of x values.\n",
"xwidth = 20\n",
"x = np.arange(0,xwidth,1)# we want to add some noise to the x values so that dont sit at regular intervals\n",
"x_residuals = np.random.normal(scale=0.2, size=[x.shape[0]])# new_x is the range of x values we will be using all the way through\n",
"new_x = x + x_residuals# We generate residuals for y values since we want to show some variation in the data\n",
"num_points = x.shape[0]\n",
"residuals = np.random.normal(scale=2.0, size=[num_points])# We will be using fun_y to generate y values all the way through\n",
"fun_y = lambda x: -(x*x) + residuals"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(1)# xwidth controls the range of x values.\n",
"xwidth = 20\n",
"x = np.arange(0,xwidth,1)# we want to add some noise to the x values so that dont sit at regular intervals\n",
"x_residuals = np.random.normal(scale=0.2, size=[x.shape[0]])# new_x is the range of x values we will be using all the way through\n",
"new_x = x + x_residuals# We generate residuals for y values since we want to show some variation in the data\n",
"num_points = x.shape[0]\n",
"residuals = np.random.normal(scale=2.0, size=[num_points])# We will be using fun_y to generate y values all the way through\n",
"fun_y = lambda x: -(x*x) + residuals"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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}