You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

495 lines
82 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "eb335a6d",
"metadata": {},
"source": [
"# Linear regression\n",
"\n",
"The linear regression is a training procedure based on a linear model. The model makes a prediction by simply computing a weighted sum of the input features, plus a constant term called the bias term (also called the intercept term, $\\theta_0$):\n",
"\n",
"$$ \\hat{y}=\\theta_0 x_0 + \\theta_1 x_1 + \\theta_2 x_2 + \\cdots + \\theta_n x_n$$\n",
"\n",
"\n",
"This can be written more easy by the using vector notation form:\n",
"\n",
"$$\\hat{y}= h_\\theta(x) = \\theta^T x$$\n",
"\n",
"---\n",
"**Now that we have our model, how do we train it?**\n",
"\n",
"*Please, consider that training the model means adjusting the parameters to reduce the error or minimizing the cost function.* \n",
"\n",
"The most common performance measure of a regression model is the **Mean Square Error (MSE)**. Therefore, to train a Linear Regression model, you need to find the value of $\\theta$ that minimizes the MSE:\n",
"\n",
"\n",
"$$ MSE(X,h_\\theta) = \\frac{1}{m} \\sum_{i=1}^{m} \\left( \\theta^T x^{(i)}-y^{(i)} \\right)^2$$\n",
"\n",
"\n",
"$$ MSE(X,h_\\theta) = \\frac{1}{m} \\sum_{i=1}^{m} \\left(\\hat{y}^{(i)}-y^{(i)} \\right)^2$$\n",
"\n",
"$$ MSE(X,h_\\theta) = \\frac{1}{m} \\left(\\hat{y}-y \\right)^2$$"
]
},
{
"cell_type": "markdown",
"id": "12cf820d",
"metadata": {},
"source": [
"# The normal equation\n",
"\n",
"To find the value of $\\theta$ that minimizes the cost function, there is a closed-form or direct solution that gives the result. This is called the **Normal Equation**; and can be found it by deriving the *MSE* equation as a function of $\\theta$ and making it equals to zero:\n",
"\n",
"\\begin{eqnarray*}\n",
"\t\\frac{\\partial J(\\theta)}{\\partial \\theta} = 0\\\\\n",
"\t\\frac{\\partial J(\\theta)}{\\partial \\theta}=\\frac{1}{m}\\left(\\theta x-y \\right)^2=\\frac{1}{m}\\left(\\theta x-y \\right)^T\\left(\\theta x-y \\right)\\\\\n",
"\t\\frac{1}{m}\\left[(\\theta x)^T-y^T \\right] \\left[\\theta x-y \\right]\n",
"\\end{eqnarray*}"
]
},
{
"cell_type": "markdown",
"id": "9139b1c9",
"metadata": {},
"source": [
"just considers that:\n",
"\\begin{align*}\n",
"\t(A^T)^T = A\\\\\n",
"\t(A+B)^T = A^T + B^T\\\\\n",
"\t(kA)^T = kA^T\\\\\n",
"\t(AB)^T =A^TB^T\n",
"\\end{align*}"
]
},
{
"cell_type": "markdown",
"id": "5b069092",
"metadata": {},
"source": [
"just considers that $(\\theta x)^Ty=y^T(\\theta x)$\n",
"\\begin{align*}\n",
"\t0=\\frac{\\partial\\,}{\\partial \\theta}\\frac{1}{m}\\left[(\\theta x)^T\\theta x - (\\theta x)^Ty-y^T\\theta x+y^Ty \\right]\\\\\n",
"\\end{align*}"
]
},
{
"cell_type": "markdown",
"id": "ae45a858",
"metadata": {},
"source": [
"$$0=\\frac{\\partial\\,}{\\partial \\theta}\\frac{1}{m}\\left[(\\theta x)^T\\theta x - 2(\\theta x)^Ty+y^Ty \\right]$$"
]
},
{
"cell_type": "markdown",
"id": "ec27d3cd",
"metadata": {},
"source": [
"$$0=\\frac{1}{m}\\left[2\\theta x^T x - 2(x)^Ty+0 \\right]$$"
]
},
{
"cell_type": "markdown",
"id": "7c8c8cfe",
"metadata": {},
"source": [
"$$0=\\frac{2}{m}\\left[\\theta x^T x - (x)^Ty+0 \\right]$$"
]
},
{
"cell_type": "markdown",
"id": "c06b74fd",
"metadata": {},
"source": [
"$$\\hat{\\theta} = (X^T X)^{-1} X^{T} y $$"
]
},
{
"cell_type": "markdown",
"id": "1315356e",
"metadata": {},
"source": [
"## A basic example\n",
"\n",
"First try to implement the linear regressor by only using two instances or points, $(x^0, y^0)$ and $(x^1,y^1)$, thus:\n",
"\n",
"$$\\hat{y}^{(i)}=\\theta_0 x_0+ \\theta_1 x_1^{(i)}$$\n",
"\n",
"but, considers that $x_0=1$, then:\n",
"\n",
"$$\\hat{y}^{(i)}=\\theta_0 + \\theta_1 x_1^{(i)}$$\n",
"\n",
"then, to write it in vector form\n",
"\n",
"$$\n",
" \\hat{y}^0=\n",
" \\begin{bmatrix}\n",
" \\theta_0 & \\theta_1\n",
" \\end{bmatrix} \n",
" \\begin{bmatrix}\n",
" 1 \\\\ \n",
" x_0\n",
" \\end{bmatrix}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "54dda83d",
"metadata": {},
"source": [
"Now, we need a matrix form to manage all data:\n",
"\n",
"$$\n",
" \\begin{bmatrix}\n",
" \\hat{y}^0 \\\\ \n",
" \\hat{y}^1\\\\\n",
" \\end{bmatrix}\n",
" =\n",
" \\begin{bmatrix}\n",
" \\theta_0 + \\theta_1 x^0_1 \\\\\n",
" \\theta_0 + \\theta_1 x^0_1 \\\\\n",
" \\end{bmatrix}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "d86618e4",
"metadata": {},
"source": [
"$$\n",
" \\begin{bmatrix}\n",
" \\hat{y}^0 \\\\ \n",
" \\hat{y}^1\\\\\n",
" \\end{bmatrix}\n",
" =\n",
" \\begin{bmatrix}\n",
" 1 & x^0_1 \\\\\n",
" 1 & x^1_1 \\\\\n",
" \\end{bmatrix}\n",
" \\begin{bmatrix}\n",
" \\theta_0 \\\\\n",
" \\theta_1 \\\\\n",
" \\end{bmatrix}\n",
"$$\n",
"\n",
"Now, let's compute $\\theta$ using the normal equation:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d2670f5b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1.000e+00, 1.000e-03],\n",
" [1.000e+00, 2.196e+00]])"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"X = np.array([[1,0.001],[1, 2.196]])\n",
"Xo = np.array([[0.001],[2.196]])\n",
"y = np.array([4.314825, 10.877373])\n",
"X"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d95f739b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4.31183523, 2.9897713 ])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y)\n",
"theta"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b241fb39",
"metadata": {},
"outputs": [],
"source": [
"t0 = theta[0]\n",
"t1 = theta[1]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "152366f0",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAadUlEQVR4nO3de4xU9fn48Wdg3YUSdrzCsnVEtCoWrRdUAtIoFiWUGPUPq4RavMXGYJSaajWpt6BdMUZNvyFqTQoKKtqo2NZW4g2NigoCDVqrooh4AWvVHUA71uX8/jDsz5WbqzOf2dl9vZITOmfOzHk2p5PzdubsbC7LsiwAABLpVe0BAICeRXwAAEmJDwAgKfEBACQlPgCApMQHAJCU+AAAkhIfAEBSddUe4Os2btwY7733XvTv3z9yuVy1xwEAvoEsy2LdunXR3NwcvXpt+72NLhcf7733XhQKhWqPAQB8C6tXr47dd999m9t0ufjo379/RHw5fGNjY5WnAQC+iWKxGIVCof08vi1dLj42fdTS2NgoPgCgxnyTSyZccAoAJCU+AICkxAcAkFSn4+Opp56K448/PpqbmyOXy8W8efM63H///ffHcccdF7vsskvkcrlYtmxZmUYFALqDTsfHhg0b4qCDDooZM2Zs9f7Ro0fH9OnTv/NwAED30+nfdhk/fnyMHz9+q/efdtppERHx1ltvfeuhAIDuq+q/alsqlaJUKrXfLhaLVZwGAKi0ql9w2tLSEvl8vn3x7aYA0L1VPT4uvfTSaG1tbV9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AJISHwBAUuIDAEhKfAAASYkPACAp8QEAJCU+AICkxAcAkJT4AACSEh8AQFLiAwBISnwAAEmJDwAgKfEBACQlPgCApMQHAJCU+AAAkhIfAEBS4gMASEp8AABJiQ8AICnxAQAkJT4AgKTEBwCQlPgAAJISHwBAUuIDAEhKfAAASYkPACAp8QEAJCU+AICkxAcAkJT4AACSEh8AQFLiAwBISnwAAEmJDwAgKfEBACQlPgCApMoeH21tbXHZZZfFkCFDom/fvrH33nvHtGnTIsuycu8KAKhBdeV+wunTp8fNN98ct99+ewwbNiwWL14cZ5xxRuTz+Tj//PPLvTsAoMaUPT6effbZOOGEE2LChAkREbHnnnvG3XffHS+88EK5dwUA1KCyf+wyatSoeOyxx+K1116LiIh//OMf8fTTT8f48eO3uH2pVIpisdhhAQC6r7K/83HJJZdEsViMoUOHRu/evaOtrS2uueaamDRp0ha3b2lpiauuuqrcYwAAXVTZ3/m49957484774y77rorlixZErfffntcf/31cfvtt29x+0svvTRaW1vbl9WrV5d7JACgC8llZf41lEKhEJdccklMmTKlfd3VV18dc+bMiX/961/bfXyxWIx8Ph+tra3R2NhYztEAgArpzPm77O98fPrpp9GrV8en7d27d2zcuLHcuwIAalDZr/k4/vjj45prrok99tgjhg0bFkuXLo0bbrghzjzzzHLvCgCoQWX/2GXdunVx2WWXxQMPPBAffPBBNDc3x8SJE+Pyyy+P+vr67T7exy4AUHs6c/4ue3x8V+IDAGpPVa/5AADYFvEBACQlPgCApMQHAJCU+AAAkhIfAEBS4gMASEp8AABJiQ8AICnxAQAkJT4AgKTEBwCQlPgAAJISHwBAUuIDAEhKfAAASYkPACAp8QEAJCU+AICkxAcAkJT4AACSEh8AQFLiAwBISnwAAEmJDwAgKfEBACQlPgCApMQHAJCU+AAAkhIfAEBS4gMASEp8AABJiQ8AICnxAQAkJT4AgKTEBwCQlPgAAJISHwBAUuIDAEhKfAAASZU9Pvb
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"plt.plot(Xo,y, '*k')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4f15df79",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAzuUlEQVR4nO3dd5iU1d3/8fcCsiDCIlIWdEX0UVFjpNgoKhoECSFiEgsiUsQWLGhsJFE0aFBj7CioEQQUMCrYQQGxUaT6UxMNWBBFsMEOzQV2798fJ25EiizMzL07835d11zxzNy78/WZ7DOfnO+5z8mJoihCkiQpTSrFXYAkScouhg9JkpRWhg9JkpRWhg9JkpRWhg9JkpRWhg9JkpRWhg9JkpRWhg9JkpRWVeIu4MdKSkpYunQpNWvWJCcnJ+5yJEnSdoiiiFWrVtGoUSMqVdr23Ea5Cx9Lly6loKAg7jIkSdIOWLJkCXvttdc2ryl34aNmzZpAKL5WrVoxVyNJkrZHIpGgoKCg9Ht8W8pd+Pi+1VKrVi3DhyRJFcz2LJlwwakkSUorw4ckSUorw4ckSUqrMoeP1157jS5dutCoUSNycnKYMGHCJq8/9dRTdOjQgT322IOcnBwWLFiQpFIlSVImKHP4WLNmDYcddhhDhgzZ6utt27bllltu2eniJElS5inz3S6dOnWiU6dOW329R48eAHzyySc7XJQkScpcsd9qW1RURFFRUek4kUjEWI0kSUq12BecDh48mLy8vNKHu5tKkpTZYg8fAwYMoLCwsPSxZMmSuEuSJEkpFHv4yM3NLd3N1F1NJUlKrTlz5nDCCScwZ86c2GqIPXxIkqT0GTlyJK+88gqjRo2KrYYyLzhdvXo1ixYtKh1//PHHLFiwgDp16rD33nvz7bff8umnn7J06VIAPvjgAwDy8/PJz89PUtmSJGl7LV68mK+//pqcnBzG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zH5Kk8i+KYNiwcBptURHstVfYRKxt27gr0w4wfEiSyrdEAs49Fx5/PIw7dw4LTOvWjbUs7TjbLpKk8mvuXGjRIgSPKlXgb38Lp9EaPCo0Zz4kSeVPFMG998IVV8D69dC4MYwdC0cfHXdlSgLDhySpfFmxAs45B8aPD+OTT4bhw2H33eOtS0lj20WSVH689VZos4wfH469v/PO8M8Gj4xi+JAkxS+K4PbboU0b+OQTaNIE3nwTLr00HBCnjGLbRZIUr2+/hV694Nlnw/h3v4OHHoK8vFjLUuo48yFJis/06dCsWQgeublw333hzhaDR0YzfEiS0q+kBG65BY49FpYsgf33h5kzw7bptlkynm0XSVJ6ffUV9OwZtkUH6NYt7F5as2a8dSltDB+SpPR57bUQNpYuhWrV4O67oW9fZzuyjG0XSVLqFRfDjTfC8ceH4NG0abit9txzDR5ZyJkPSVJqLV8OZ50FkyeH8dlnw5AhsNtu8dal2Bg+JEmpM3UqnHlmCCC77hpCR69ecVelmNl2kSQlX3ExDBwI7duH4HHIITB7tsFDgDMfkqRkW7oUuneHadPC+JxzwsLSXXeNtSyVH4YPSVLyvPRSWN/x1VdQo0a4hbZ797irUjlj20WStPM2boQ//hE6dgzB47DDYN48g4e2yJkPSdLO+eyzsHfHG2+E8QUXhEPiqlePty6VW4YPSdKOe+GFcOvsN9+EHUofeghOOy3uqlTO2XaRJJXdhg1w1VXQuXMIHi1ahDaLwUPbwZkPSVLZLF4MZ5wRDoIDuPhi+Nvfwqm00nYwfEiStt/TT0Pv3rBiRTj2/uGH4Te/ibsqVTC2XSRJP239eujfH7p2DcHjiCNg/nyDh3aI4UOStG0ffQRt2sBdd4Xx5ZeHO1uaNIm3LlVYtl0kSVv3xBNhh9JEAnbfHR55BLp0ibsqVXDOfEiSNvfdd9CvH5x6aggerVv
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Xvec = np.linspace(0,2,2)\n",
"Xnew = np.c_[np.ones((2, 1)), Xvec]\n",
"ypre = Xnew.dot(theta)\n",
"plt.plot(Xo,y, '*k')\n",
"plt.plot(Xvec, ypre, '-r')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "a986cb4d",
"metadata": {},
"source": [
"# My Linear Regressor\n",
"\n",
"**Instructions:** Create your own function train (estimate) the model's parameter for a Linear Regressor implementing the *Normal Equation*. Test your model with the next generated data."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5ca2686a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff82286040>]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAwKUlEQVR4nO3df3RU5Z3H8U8SJLAsiaL8SieOQFKsVBCrslA9xhiILMuBPXtUOOjSdixZDz2WtbYLfyhw0A20nuq65Shxp8L6A5a2gt3WSpUOUBV/8GsXrKUJZYQRkN2uEIga25m7f9CMTDJJ5k7u3J/v1zlzNJM7M88zN8P9zvN8n+9TZBiGIQAAAJsUO90AAAAQLAQfAADAVgQfAADAVgQfAADAVgQfAADAVgQfAADAVgQfAADAVgQfAADAVv2cbkBnqVRKx44d0+DBg1VUVOR0cwAAQA4Mw9CZM2dUUVGh4uKexzZcF3wcO3ZMlZWVTjcDAADk4ejRowqFQj0e47rgY/DgwZLONb6srMzh1gAAgFy0traqsrIyfR3vieuCj46plrKyMoIPAAA8JpeUCRJOAQCArQg+AACArQg+AACArQg+AACArQg+AACArQg+AACArQg+AACArQg+AACArQg+AACArQg+AACArQg+AAD4s0QioVgspkQi4XRTfM108LFjxw7NnDlTFRUVKioq0ubNmzN+//zzz2vatGm6+OKLVVRUpH379lnUVAAACic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kqxcXFampqUiQScbpZtjJz/S5I8LFx40YtWbJEiURCQ4Y
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"np.random.seed(42)\n",
"Xo = 2 * np.random.rand(100, 1)\n",
"X = np.c_[np.ones((100, 1)), Xo] # add x0 = 1 to each instance\n",
"y = 4 + 3 * Xo + np.random.randn(100, 1)\n",
"plt.plot(Xo, y, '.k')"
]
},
{
"cell_type": "markdown",
"id": "43a9426c",
"metadata": {},
"source": [
"Therefore, the model will become:\n",
"\n",
"$$\n",
" \\begin{bmatrix}\n",
" \\hat{y}^0 \\\\ \n",
" \\hat{y}^1\\\\\n",
" \\vdots \\\\\n",
" \\hat{y}^n\n",
" \\end{bmatrix}\n",
" =\n",
" \\begin{bmatrix}\n",
" 1 & x^0_1 \\\\\n",
" 1 & x^1_1 \\\\\n",
" \\vdots & \\vdots \\\\\n",
" 1 & x^n_1\n",
" \\end{bmatrix}\n",
" \\begin{bmatrix}\n",
" \\theta_0 \\\\\n",
" \\theta_1 \\\\\n",
" \\vdots \\\\\n",
" \\theta_n\n",
" \\end{bmatrix}\n",
"$$\n"
]
},
{
"cell_type": "markdown",
"id": "c07852f4",
"metadata": {},
"source": [
"## Using Sklearn to train the model\n",
"Python already includes a linear regression function within Scikit-Learn."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "17481af6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([4.21509616]), array([[0. , 2.77011339]]))"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.linear_model import LinearRegression\n",
"\n",
"lin_reg = LinearRegression()\n",
"lin_reg.fit(X, y)\n",
"lin_reg.intercept_, lin_reg.coef_"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "c5e85264",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[4.21509616],\n",
" [9.75532293]])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X_new = np.array([[0], [2]])\n",
"X_new_b = np.c_[np.ones((2, 1)), X_new] #Se agrega x0=1 para cada instancia\n",
"y_Pred=lin_reg.predict(X_new_b)\n",
"y_Pred"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "20da996b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0xffff72c2bfa0>"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAABRIUlEQVR4nO3df5yM5f4/8Nfssj+wu36EXWat3bVtEkoiyrG2ZXMkOb6KI4ePwSYVJaJCftQSR0VOLBtKKZUfJ3WoNEtU8vugaJed7ORXiV27WMxc3z+udo6xv2Z275n7vmdez8djHplr7pn7uvfe7X7Pdb+v92UQQggQEREReUmA2h0gIiIi/8Lgg4iIiLyKwQcRERF5FYMPIiIi8ioGH0RERORVDD6IiIjIqxh8EBERkVcx+CAiIiKvqqF2B25kt9tx4sQJhIWFwWAwqN0dIiIicoEQAhcuXECTJk0QEFDx2Ibmgo8TJ04gOjpa7W4QERFRFeTl5cFoNFa4jeaCj7CwMACy8+Hh4Sr3hoiIiFxRUFCA6Ohox3W8IpoLPkputYSHhzP4ICIi0hlXUiaYcEpERERexeCDiIiIvIrBBxEREXmV5nI+XCGEwLVr12Cz2dTuClVBYGAgatSowanURER+SnfBx5UrV3Dy5ElcvHhR7a5QNdSqVQtRUVEICgpSuytERORlugo+7HY7cnNzERgYiCZNmiAoKIjfnnVGCIErV67gt99+Q25uLhISEiotRkNERL5FV8HHlStXYLfbER0djVq1aqndHaqi0NBQ1KxZE7/88guuXLmCkJAQtbtERERepMu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ejpiY2MRGhqKtm3b4uOPP1bop0VERL5M/8GHEEBRkToPN9bkq1OnDurUqYN169ahuLi43O0KCwvRq1cv/Pjjj9i+fTsSExMr/Nyvv/4aJ06cwNatWzFv3jxMnToVDzzwAOrVq4cdO3bgsccec5piVVRUhNTUVNSrVw87d+7ERx99hK+++gpPPPGE4zP/+c9/Yvny5Xj77bexbds2/PHHH1i7dq3TftPT0/HOO+9g0aJFOHToEJ5++mk8+uij2LJli8s/EyIi8lMeXmHXbRUtyVvmMuyFhULIMMD7j8JCt47t448/FvXq1RMhISGic+fOYtKkSWL//v2O12NiYkRQUJBo0KCBOHPmTKWfN2TIEBETEyNsNpujLTExUXTp0sXx/Nq1a6J27dpi1apVQgghMjIyRL169UThdX3/7LPPREBAgDh16pQQQoioqCjx6quvOl6/evWqMBqNok+fPkIIIS5fvixq1aolvv32W6f+mEwmMXDgQCGEEGazWQAQ586dK7PvZZ5LIiLSrYqu3zfS/8iHjvTr1w8nTpzAv//9b9x///3IyspCu3btsHz5csc2PXr0QFFREV555RVH2/Hjxx0jJ3Xq1HF6rVWrVk5Tqho3bozWrVs7ngcGBqJBgwY4c+YMAOCnn35C27ZtUbt2bcc299xzD+x2O44cOYL8/HycPHkSHTt2dLxeo0YNtG/f3vE8JycHFy9eRPfu3Z369c477+Do0aPK/LCIiMhn6T/htFYt4Lp8Ba/v200hISHo3r07unfvjsmTJ2P48OGYOnUqhg4dCgC477778OSTT6JPnz6w2+1444030KRJE+zbt8/xGfXr13f8u2bNmk6fbzAYymy7seBMdZTkh3z22Wdo2rSp02vBwcGK7YeIiHyT/oMPgwG47lu83tx6661Yt26dU1uPHj3w6aef4sEHH4QQAvPnz1esOEzLli2xfPlyFBUVOUY/tm/fjoCAACQmJiIiIgJRUVHYsWMH/vKXvwAArl27ht27d6Ndu3aOPgcHB+P48ePo2rWrIv0iIiL/of/gQyfOnj2
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.plot(Xo,y, '.k', label='data')\n",
"plt.plot(X_new, y_Pred, '-r', label='SK-model')\n",
"plt.legend()"
]
},
{
"cell_type": "markdown",
"id": "19ad47f6",
"metadata": {},
"source": [
"# Gradient Descent"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1a8ec08d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}