PolynomialRegression/Polynomial Regression.ipynb

369 lines
149 KiB
Plaintext
Raw Normal View History

2021-06-24 11:07:41 +02:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Algorytm najszybszego spadku dla regresji wielomianowej. "
2021-06-24 11:07:41 +02:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Skład grupy:\n",
"- Nowak Ania,\n",
"- Łaźna Patrycja,\n",
"- Bregier Damian"
2021-06-24 11:07:41 +02:00
]
},
{
"cell_type": "code",
2021-06-25 01:36:15 +02:00
"execution_count": 1,
2021-06-24 13:03:10 +02:00
"metadata": {},
"outputs": [],
"source": [
2021-06-25 01:36:15 +02:00
"import pandas as pd\n",
2021-06-25 09:42:03 +02:00
"import random\n",
2021-06-25 01:36:15 +02:00
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"np.set_printoptions(suppress=True)"
2021-06-24 13:03:10 +02:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 0. Podstawowe informacje o zbiorze danych"
]
},
{
"attachments": {
"image.png": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA2oAAAJACAYAAAD8a5XvAAAgAElEQVR4Aezd8Wsbd4L/f/8Z/nENhsU0HPUeBxbcwUZsOOLSwgrMl48hPwTv8r2c6efomXIEX5Ylp20hiPAhpyuk6Bu+25zdNl2l+cYo3ipf+eJvUqlrfzOum6zVq3blOMHIjXI339g1qhOV15eRNNZIlh2PbFmS8zQISzPvmXnPY2Y0fs37PeMO8YMAAggggAACCCCAAAIIINBSAh0tVRsqgwACCCCAAAIIIIAAAgggIIIaOwECCCCAAAIIIIAAAggg0GICBLUW2yBUBwEEEEAAAQQQQAABBBAgqLEPIIAAAggggAACCCCAAAItJkBQa7ENQnUQQAABBBBAAAEEEEAAAYIa+wACCCCAAAIIIIAAAggg0GICBLUW2yBUBwEEEEAAAQQQQAABBBAgqLEPIIAAAggggAACCCCAAAItJkBQa7ENQnUQQAABBBBAAAEEEEAAgT0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XHOd7NBeS9sXYKzCO8RQAABBA65gGkoeNKrkesZx4qaMi4Ny3fMK+9JvyKLjlHW28WI/Ce98h7zafiSIbNi9F6mrZjRPnzYUPbetCbiS1p3zG3jcVJ3bk5oIjIt4+GqY4ykH1a1dHdaE5EJRW8nld1wjH6W1f3pqKKxhJYck63+OaGZh86Cjml2+ZagtksoilUKtEJIaoU6VKrwCYFGC+QUe7tTo1O5ygWlQvIeDyldObTy06Mx+QbGVDjlZhaUrjyDlssm/Oo4Gy9/drzruPW/tNPLUZS3CCCAAAJtKpC+PqL+
}
},
"cell_type": "markdown",
"metadata": {},
"source": [
"Ze względu na specyfikę wytycznych projektu zakładającego wykorzystanie jedynie dwóch cech: x i y oraz modelowanie zależności y od x za pomocą funkcji wielomianowej dobrany został przez nas odpowiedni dataset. Obejmuje on jedynie trzy kolumny, czyli: płeć, wzrost w calach oraz wagę w funtach, z czego ze względu na specyfikę projektu wykorzystywane są jedynie wzrost oraz waga. Każdy z parametrów zawiera po 10 tysięcy unikalnych wartości.\n",
"\n",
"![image.png](attachment:image.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Wczytywanie i preprocessing danych"
]
},
2021-06-24 13:03:10 +02:00
{
"cell_type": "code",
2021-06-27 11:07:37 +02:00
"execution_count": 2,
2021-06-24 11:07:41 +02:00
"metadata": {},
2021-06-25 01:36:15 +02:00
"outputs": [],
2021-06-24 11:07:41 +02:00
"source": [
2021-06-27 11:07:37 +02:00
"# Stopień wielomianu\n",
"degree = 4\n",
"X_plot = np.linspace(0, 100, 1000)\n",
2021-06-25 01:36:15 +02:00
"initial_theta = np.matrix([0] * (degree + 1)).reshape(degree + 1, 1)"
2021-06-24 11:07:41 +02:00
]
},
{
"cell_type": "code",
2021-06-25 01:36:15 +02:00
"execution_count": 3,
2021-06-24 11:07:41 +02:00
"metadata": {},
2021-06-25 01:36:15 +02:00
"outputs": [],
2021-06-24 11:07:41 +02:00
"source": [
"# Wybór dwóch kolumn - dotyczących wzrostu i wagi\n",
2021-06-25 01:36:15 +02:00
"data = pd.read_csv('weight-height.csv')[[\"Height\", \"Weight\"]]\n",
"# Czyszczenie tabeli i wartości pustych\n",
2021-06-25 01:36:15 +02:00
"data = data.dropna()\n",
"data_matrix = np.matrix(data)\n",
"\n",
"m, n_plus_1 = data_matrix.shape\n",
"n = n_plus_1 - 1\n",
"X = (np.ones((m, 1)))\n",
"\n",
"for i in range(1, degree + 1):\n",
" Xn = np.power(data_matrix[:, 0:n], i)\n",
" Xn /= np.amax(Xn, axis=0)\n",
" X = np.concatenate((X, Xn), axis=1)\n",
"\n",
"X = np.matrix(X).reshape(m, degree * n + 1)\n",
"Y = np.matrix(data_matrix[:, -1])"
2021-06-24 11:07:41 +02:00
]
2021-06-24 13:03:10 +02:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Metody do regresji wielomianowej"
2021-06-24 13:03:10 +02:00
]
},
{
"cell_type": "code",
2021-06-25 01:36:15 +02:00
"execution_count": 4,
2021-06-25 09:42:03 +02:00
"metadata": {
"scrolled": true
},
"outputs": [],
2021-06-24 13:03:10 +02:00
"source": [
"# Implementacja wzrosu na regresję wielomianową\n",
2021-06-24 13:03:10 +02:00
"def polynomial_regression(theta, x):\n",
2021-06-27 11:07:37 +02:00
" x = x/data[\"Height\"].max()\n",
2021-06-25 01:36:15 +02:00
" return sum(theta * np.power(x, i) for i, theta in enumerate(theta.tolist()))\n",
2021-06-24 13:03:10 +02:00
"\n",
"# Implementacja wzoru na RMSE, czyli pierwiastek z błędu średniokwadratowego\n",
2021-06-25 01:36:15 +02:00
"def mean_squared_error(theta, X, Y):\n",
" J = 1.0 / (2.0 * m) * ((X * theta - Y).T * (X * theta - Y))\n",
" return J.item()\n",
2021-06-24 13:03:10 +02:00
"\n",
"# Wzór na gradient prosty\n",
2021-06-27 11:07:37 +02:00
"def gradient(theta, X, Y):\n",
2021-06-25 01:36:15 +02:00
" return 1.0 / len(Y) * (X.T * (X * theta - Y)) \n",
2021-06-24 13:03:10 +02:00
"\n",
2021-06-25 09:42:03 +02:00
"# Batch gradient descent (BGD)\n",
2021-06-27 11:07:37 +02:00
"def BGD(X, Y, theta, cost_function = mean_squared_error, alpha=0.1, eps=10**-5, max_steps = 10000000000):\n",
" cost = cost_function(theta, X, Y)\n",
" logs = [[cost, theta]]\n",
" \n",
" for i in range(max_steps):\n",
" theta = theta - alpha * gradient(theta, X, Y)\n",
" next_cost = cost_function(theta, X, Y)\n",
" logs.append([next_cost, theta])\n",
" if abs(cost - next_cost) <= eps:\n",
" break\n",
" cost = next_cost\n",
" return theta, logs\n",
"\n",
"# Batch gradient descent (BGD)\n",
"def steepest_descent(X, Y, theta, cost_function = mean_squared_error, eps=10**-5, max_steps = 10000000000):\n",
2021-06-25 01:36:15 +02:00
" cost = cost_function(theta, X, Y)\n",
2021-06-24 13:03:10 +02:00
" logs = [[cost, theta]]\n",
" \n",
" for i in range(max_steps):\n",
" theta = theta - alpha * gradient(theta, X, Y)\n",
2021-06-25 01:36:15 +02:00
" next_cost = cost_function(theta, X, Y)\n",
2021-06-24 13:03:10 +02:00
" logs.append([next_cost, theta])\n",
" if abs(cost - next_cost) <= eps:\n",
" break\n",
2021-06-25 01:36:15 +02:00
" cost = next_cost\n",
2021-06-24 13:03:10 +02:00
" return theta, logs\n",
2021-06-25 09:42:03 +02:00
"\n",
"# Mini-batch gradient descent (MBGD)\n",
2021-06-27 11:07:37 +02:00
"def MBGD(X, Y, theta, cost_function = mean_squared_error, alpha=0.1, epochs=5, batch_size=16):\n",
2021-06-25 09:42:03 +02:00
" cost = cost_function(theta, X, Y)\n",
" logs = [[cost, theta]]\n",
" start, end = 0, batch_size\n",
2021-06-24 13:03:10 +02:00
" \n",
2021-06-25 09:42:03 +02:00
" steps = m / batch_size\n",
" for i in range(epochs):\n",
" zipped_XY = list(zip(X, Y))\n",
" random.shuffle(zipped_XY)\n",
" X_shuffled, Y_shuffled = zip(*zipped_XY)\n",
" X_shuffled = np.concatenate(X_shuffled, axis=0) \n",
" Y_shuffled = np.concatenate(Y_shuffled, axis=0) \n",
" for j in range(int(steps)):\n",
" batch = X_shuffled[start:end,:], Y_shuffled[start:end,:]\n",
" theta = theta - alpha * gradient(theta, batch[0], batch[1])\n",
" cost = cost_function(theta, X, Y)\n",
" logs.append([cost, theta])\n",
"\n",
" if start + batch_size < batch_size:\n",
" start += batch_size\n",
" else:\n",
" start = 0\n",
" end = min(start + batch_size, m)\n",
" return theta, logs\n",
"\n",
"# Stochastic gradient descent (SGD)\n",
2021-06-27 11:07:37 +02:00
"def SGD(X, Y, theta, cost_function = mean_squared_error, alpha=0.1, epochs=5, batch_size=16):\n",
2021-06-25 09:42:03 +02:00
" return MBGD(X, Y, theta, gradient, cost_function, alpha, epochs, 1)\n",
"\n",
2021-06-25 01:36:15 +02:00
"#print(mean_squared_error([1,2,1,1],[1,2,43,1]))\n",
"#mean_squared_error(polynomial_regression(initial_theta, X), Y)\n",
2021-06-25 09:42:03 +02:00
"#final_theta, logs_1 = BGD(X, Y, initial_theta)\n",
2021-06-27 11:07:37 +02:00
"final_theta, logs_2 = MBGD(X, Y, initial_theta, epochs = 30, batch_size = 16)\n",
"#final_theta, logs_2 = SGD(X, Y, initial_theta, epochs = 30)"
2021-06-25 01:36:15 +02:00
]
},
{
"attachments": {
"image.png": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA70AAAFDCAYAAAD22mnsAAAgAElEQVR4Aey9i5MV1b33/fwBp97UqefkVl5m9gCHPSC3Y0TfWEblMigMaAheciByDorUaLQgJuflIFFHAoxIEIgKMUclyiUqCnEorAcPRnDAwQHHh0GMAySMWB7HGzMJMpMw7t9bq7tX9+q1e3ev3rt77758qaJm797d6/JZq7vXb/1u/4vwDwRAAARAAARAAARAAARAAARAAAQSSuB/JbRf6BYIgAAIgAAIgAAIgAAIgAAIgAAIEIReTAIQAAEQAAEQAAEQAAEQAAEQAIHEEoDQm9ihRcdAAARAAARAAARAAARAAARAAAQg9GIOgAAIgAAIgA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qNwx+a+5qvocmZLJUag7lnhaWQiZLN64/CoHD7yDE5PzcBzvpZ+MvKD0au5HKrKZuIe0qXnaWqFlWJpmaOlr3nvQzvqaSAITeVA47Og0CIAAC4RCIjdBLRDzFhSUoShrfmkupac9n1PtFb5n+f0Kdbftp/xvs/x/od79+mFauWkp3z5pC9RNG+hbQa27YSKfCGWbPUj9+bqbZ3pueOeF5Pk6oPAEecCwozdj7T00l5ldZqgBdeTJoQR6BM220ZNz5lLlqObUGYT5s+P7XTFpO7UGUR0S5zqdpenW19hxi0Zw/zesEDqSNAITetI04+gsCIAACIRKIk9BLZKW4KCT4BrkIKxn7QD/1/k8nHfz9b+nn8ybT2OH6gq5Q2zM1V9K6IyXX6r8AIXhV
}
},
"cell_type": "markdown",
"metadata": {},
"source": [
"Metoda gradientu prostego\n",
"![image.png](attachment:image.png)"
2021-06-24 13:03:10 +02:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Reprezentacja graficzna regresji wielomianowej"
2021-06-24 13:03:10 +02:00
]
},
{
"cell_type": "code",
2021-06-25 09:42:03 +02:00
"execution_count": 5,
2021-06-25 01:36:15 +02:00
"metadata": {
"scrolled": true
},
2021-06-24 13:03:10 +02:00
"outputs": [
{
"data": {
2021-06-27 11:07:37 +02:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlYAAAEzCAYAAADzdE1rAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAxYElEQVR4nO3de3xU1bn/8c+TkIQEMErAOyRU6c9LES1RsF7baLUoovZ41AZF1MZrBWu12rSibXOqnipQK9p4qVSnUq8IglKNWo/3grd4qQWFIGK5akASIZf1+2NP4gQmySTZe2Yy832/Xrxmz549ay1fW5KHtZ79LHPOISIiIiI9l5HoAYiIiIikCgVWIiIiIj5RYCUiIiLiEwVWIiIiIj5RY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ZqDSOTfDzAYCfwOKgOXAfzvnPg9/5xrgPKAJuMw5tzCQ0YuISCCilVgIaqYK4HsfQ8ky+Lyvf7lV/bP7s+6qdf40JhKjWGasGoErnHP7AmOAS8xsP+BqoMo5NxyoCr8n/NkZwP7A8cBMM8sMYvAiIhKMuCZ6O6io8g5vOgxqfZitAiWrS2J0Glg55z5zzr0RPt4EfADsAYwHZoUvmwWcHD4eD8x2zm1xzi0DlgKH+DxuEREJUDwTvcd9CGM+hdX9vIKgflGyuiRCl3KszKwIOAh4DdjFOfcZeMEXsHP4sj2ATyK+tjJ8btu2ysxskZktWrt2bTeGLiIiQYlWYiEI1gy/fTbc5xFQl+1Pu0pWl0SJObAys/7AI8AU59zGji6Ncm67hXnnXKVzrtg5Vzx48OBYhyEiInHQUmIhiFpVkU5
2021-06-24 13:03:10 +02:00
"text/plain": [
"<Figure size 720x360 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"def plot_polynomial_regression(theta):\n",
" fig = plt.figure(figsize=(10,5))\n",
2021-06-25 01:36:15 +02:00
" Y_plot = polynomial_regression(theta, X_plot).tolist()\n",
2021-06-24 13:03:10 +02:00
" chart = fig.add_subplot()\n",
2021-06-27 11:07:37 +02:00
" chart.plot(data[\"Height\"], Y ,\"go\")\n",
2021-06-24 13:03:10 +02:00
" chart.plot(X_plot, Y_plot, color=\"red\", lw=2, label=f\"degree {len(theta)}\")\n",
2021-06-27 11:07:37 +02:00
" plt.ylim([0,250])\n",
2021-06-24 13:03:10 +02:00
" plt.show()\n",
" \n",
2021-06-25 01:36:15 +02:00
"#plot_polynomial_regression(initial_theta)\n",
"plot_polynomial_regression(final_theta)"
2021-06-24 13:03:10 +02:00
]
},
2021-06-27 11:07:37 +02:00
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-33.70007165990287x^0 + 36.22536357022561x^1 + 77.13438753083798x^2 + 97.31645980974973x^3 + 103.01308458334519x^4 + "
]
}
],
"source": [
"for i,x in enumerate(final_theta.tolist()):\n",
" x = x[0]\n",
" print(f\"{x}x^{i}\", end=\" + \")"
]
},
2021-06-24 13:03:10 +02:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Regresja wielomianowa z wykorzystaniem gotowej biblioteki"
2021-06-24 13:03:10 +02:00
]
},
{
"cell_type": "code",
2021-06-27 11:07:37 +02:00
"execution_count": 7,
2021-06-24 13:03:10 +02:00
"metadata": {},
"outputs": [],
"source": [
"from sklearn.preprocessing import PolynomialFeatures, StandardScaler\n",
"from sklearn.pipeline import make_pipeline\n",
"from sklearn.linear_model import Ridge, LinearRegression"
]
},
{
"cell_type": "code",
2021-06-27 11:07:37 +02:00
"execution_count": 8,
2021-06-24 13:03:10 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2021-06-27 11:07:37 +02:00
"Pipeline(steps=[('polynomialfeatures', PolynomialFeatures(degree=4)),\n",
2021-06-24 13:03:10 +02:00
" ('linearregression', LinearRegression())])"
]
},
2021-06-27 11:07:37 +02:00
"execution_count": 8,
2021-06-24 13:03:10 +02:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = make_pipeline(PolynomialFeatures(degree=degree, include_bias=True), \n",
" LinearRegression())\n",
2021-06-25 01:36:15 +02:00
"model.fit(data[[\"Height\"]],Y)"
2021-06-24 13:03:10 +02:00
]
},
{
"cell_type": "code",
2021-06-27 11:07:37 +02:00
"execution_count": 9,
2021-06-24 13:03:10 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2021-06-27 11:07:37 +02:00
"4"
2021-06-24 13:03:10 +02:00
]
},
2021-06-27 11:07:37 +02:00
"execution_count": 9,
2021-06-24 13:03:10 +02:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
2021-06-27 11:07:37 +02:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmAAAAEzCAYAAACWmb8UAAAAOXRFWHRTb2Z0d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EDV9JrKNUTKIxTOLNy2PLpk7RIKZxa2niQM3CzY9OmuOP/ee93Tkps3hx1VUjI2AaYQ8/PzbVlZWdhhiEhLfPIJ9O3rNhtetCjsaKQViJRHuOrZq3ao7TIY/2fALNz8Ckx42X153clw2wCgkX2zc7JzAOpMEnOyc1g8brGnYYbu5Zdh2DC3kfegQa44PzMz7KgCY4yZa63Nj+camgETkfjsvTdkZLhH1NevDzsaSXKxWaS6CuuDSL7++JJLvqoMjDoTbjuGRpOvrPQsigcW1/sUZKt6OjLmhBPglVfcdmTPPw9nnKFeYc2kBExE4pOe7mbAAD76KNxYJOkVlRZRsaUi+IEtFJfCTa/CVgMFZ8E/Dm78Y6kmlZKhJRTkFdT7FGSrfDoS4JBD4KWX3D6SL7ygJKyZlICJSPwOPti9fvBBmFFIKxDKbJGFP/8HbnzdJV/nnQ3T8hr/WFZ6FlN/MZWCvAIAigcWk5WetcN7Wu3TkeB6AdZMwoYNUxLWRErARCR+SsDEI7HGqkGa8BL8zxuwJQVGDIfp/ep/b6pJBVxdV2zmK6Ygr4CSoSXkZOdgMHW+p1Xq29clYd27w3/+A2eeCZs2hR1VwlMnfBGJ3yGHuNf33w83DklqkfII6zatC3TMq9+Em6PLjuecDU/1rf+9qSaVrTdvbfB6BXkFrT/hqkssCTvhBJgzBy68EB5
2021-06-24 13:03:10 +02:00
"text/plain": [
"<Figure size 720x360 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2021-06-27 11:07:37 +02:00
"Y_plot_2 = model.predict([[x] for x in X_plot])\n",
2021-06-24 13:03:10 +02:00
"\n",
"fig = plt.figure(figsize=(10,5))\n",
"chart = fig.add_subplot()\n",
2021-06-25 01:36:15 +02:00
"chart.plot(data[\"Height\"], Y ,\"go\")\n",
2021-06-27 11:07:37 +02:00
"chart.plot(X_plot, Y_plot_2, color=\"red\", lw=2, label=f\"degree {degree}\")\n",
"plt.ylim([0,250])\n",
2021-06-27 11:07:37 +02:00
"plt.xlim([0,100])\n",
2021-06-24 13:03:10 +02:00
"degree"
]
2021-06-24 11:07:41 +02:00
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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",
2021-06-27 11:07:37 +02:00
"version": "3.8.5"
2021-06-24 11:07:41 +02:00
}
},
"nbformat": 4,
"nbformat_minor": 4
}