mirea-projects/Third term/Artificial intelligence systems and big data/4.ipynb

1360 lines
323 KiB
Plaintext
Raw Permalink Normal View History

2024-09-23 23:22:33 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Рабочая тетрадь No 4"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 403,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn import metrics\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.1.3 Задание\n",
"\n",
"Представьте собственные данные и постройте эктраполяцию полиномами \n",
"первой, второй и третьей степени. "
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 404,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"[-0.07808256 1.34935162 1.7342857 2.54080198 3.89339092 4.61161853\n",
" 6.12398157 6.8045353 8.26939507 9.02620843 9.50583159]\n",
"[8.71060552e-01 2.77270588e+00 6.94877588e+00 2.01183390e+01\n",
" 5.48419138e+01 1.48152200e+02 4.03507781e+02 1.09625683e+03\n",
" 2.98133624e+03 8.10312483e+03 2.20261474e+04]\n"
2024-09-23 23:22:33 +00:00
]
}
],
"source": [
2024-09-27 05:31:03 +00:00
"import math\n",
"\n",
2024-09-23 23:22:33 +00:00
"delta = 1.0\n",
2024-09-27 05:31:03 +00:00
"x = np.linspace(0, 10, 11)\n",
"y = math.e ** x + delta * (np.random.rand(11) - 0.5)\n",
2024-09-23 23:22:33 +00:00
"x += delta * (np.random.rand(11) - 0.5)\n",
"\n",
"print(x)\n",
"print(y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Эктраполяция полиномом первой степени"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 405,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjkAAAGdCAYAAADwjmIIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAtLklEQVR4nO3de3hU9b3v8U8SciFIuCkJKQEjcr+JICGgFiUkQLbdCKWi1E2RastJCkn2RsUqgrZNxS0IEqHUKu5zjCJ7b7EiBaZBQUq4BaKACGjpBsUkFiEDQZIhWeePnJlDSi4TyJpJfvN+PU8enLV+s9Z3fRNnPrNmXYIsy7IEAABgmGB/FwAAAGAHQg4AADASIQcAABiJkAMAAIxEyAEAAEYi5AAAACMRcgAAgJEIOQAAwEit/F2AP1VVVenUqVNq27atgoKC/F0OAADwgmVZOnfunGJjYxUcXPf+moAOOadOnVJcXJy/ywAAAFfh5MmT6tq1a53zAzrktG3bVlJ1k6Kiomxbj8vl0ubNm5WcnKzQ0FDb1hPI6LFv0Gf70WPfoM/2s7PHTqdTcXFxnvfxugR0yHF/RRUVFWV7yImMjFRUVBT/M9mEHvsGfbYfPfYN+mw/X/S4oUNNOPAYAAAYiZADAACMRMgBAABGIuQAAAAjEXIAAICRCDkAAMBIhBwAAGAkQg4AAAFsWd4xxT/+vpblHfN3KU0uoC8GCABAIFuWd0yLHUclyfPv7DE9/VlSk2JPDgAAAejygOO22HHUqD06hBwAAAJMbQHHzaSgQ8gBACCA1Bdw3EwJOoQcAAAChDcBx82EoEPIAQAgQCzxMuBc7fjmhpADAECAyBzby9bxzQ0hBwCAADF7TE9leRlcssb2avGnkxNyAAAIIN4EHRMCjkTIAQAg4NQXdEwJOBIhBwCAgFRb0DEp4Ejc1gEAgIDlDjRLHEeVaVjAkQg5AAAEtNljehoXbtz4ugoAABiJkAMAA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IQcAABgJEIOAAAwEiEHAAAYiZADAACMRMgBAABGIuQAAAAjEXIAAICRCDkAAMBIhBwAAGAkQg4AADASIQcAABiJkAMAAIxEyAEAAEYi5AAAACMRcgAAgJEIOQAAwEiEHAAAYCRCDgAAMBIhBwAAGImQAwAAjETIAQAARmp0yNm2bZvuuecexcbGKigoSOvWrasx/yc/+YmCgoJq/IwbN67GmG+//VbTpk1TVFSU2rdvr5kzZ+r8+fM1xnzyySe64447FBERobi4OC1atOiKWtauXas+ffooIiJCAwcO1IYNGxq7OQAAwFCNDjllZWUaPHiwcnJy6hwzbtw4ff31156fN998s8b8adOm6dChQ3I4HFq/fr22bdumRx55xDPf6XQqOTlZ3bt3V0FBgZ5//nktWLBAq1at8ozZsWOH7r//fs2cOVP79+/XxIkTNXHiRB08eLCxmwQAAAzUqrFPGD9+vMaPH1/vmPDwcMXExNQ67/Dhw9q4caP27NmjYcOGSZJeeuklTZgwQf/+7/+u2NhYvfHGG6qoqNCrr76qsLAw9e/fX4WFhVq8eLEnDC1dulTjxo3T3LlzJUnPPvusHA6Hli9frpUrVzZ2swAAgGFsOSbnww8/VOfOndW7d2/NmjVLp0+f9szLz89X+/btPQFHkpKSkhQcHKxdu3Z5xtx5550KCwvzjElJSdGRI0d05swZz5ikpKQa601JSVF+fr4dmwQAAFqYRu/Jaci4ceM0adIkxcfH64svvtATTzyh8ePHKz8/XyEhISoqKlLnzp1rFtGqlTp27KiioiJJUlFRkeLj42uMiY6O9szr0KGDioqKPNMuH+NeRm3Ky8tVXl7
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"m = np.vstack((x, np.ones(11))).T\n",
"s = np.linalg.lstsq(m,y,rcond = None)[0]\n",
"\n",
2024-09-27 05:31:03 +00:00
"x_prec = np.linspace(8, 10, 101)\n",
2024-09-23 23:22:33 +00:00
"\n",
"plt.plot(x, y,'D')\n",
"plt.plot(x_prec, s[0] * x_prec + s[1], '-', lw=1)\n",
"plt.grid()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Эктраполяция полиномом второй степени"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 406,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjkAAAGdCAYAAADwjmIIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABGe0lEQVR4nO3dd3wUdf7H8demAxKqJEQCRIp0RBAMoCIloYgiHDZURCzHjxwlHioWRD1FUVFQFDkL5x0o4J2oiEAMStFQJVJEQEQBIQlKCQRINtn5/TFkQwRCAtmd3dn38/HYh/Od/e7OZ7/E7DtTvuMwDMNARERExGaCrC5ARERExBMUckRERMSWFHJERETElhRyRERExJYUckRERMSWFHJERETElhRyRERExJYUckRERMSWQqwuwEoul4u9e/dSuXJlHA6H1eWIiIhIKRiGwZEjR4iJiSEo6Oz7awI65Ozdu5fY2FiryxAREZHzsHv3burUqXPW5wM65FSuXBkwBykyMtJj23E6nSxevJiEhARCQ0M9tp1ApjH2Do2z52mMvUPj7HmeHOPs7GxiY2Pd3+NnE9Ahp/AQVWRkpMdDTsWKFYmMjNT/TB6iMfYOjbPnaYy9Q+Psed4Y43OdaqITj0VERMSWFHJERETElhRyRERExJYUckRERMSWFHJERETElhRyRERExJYUckRERMSWFHJEREQC2JTU7cQ98jlTUrdbXUq5C+jJAEVERALZlNTtTErZBuD+74hujawsqVxpT46IiEgAOjXgFJqUss1We3QUckRERALMmQJOITsFHYUcERGRAFJSwClkl6CjkCMiIhIgShNwCtkh6CjkiIiIBIhXShlwzre/r1HIERERCRCjezT2aH9fo5AjIiISIEZ0a0RyKYNLco/Gfn85uUKOiIhI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pmLFiqX41BcmJSXF49sIdBpj79A4e57G2Ds0zp7niTE+duxYqfqdd8gZPnw4mzZtYsWKFef7Fl43duxYkpOT3e3s7GxiY2NJSEggMjLSY9t1Op2kpKTQo0cPQkNDPbadQKYx9g6Ns+dpjL1D4+x5nhzjwiMx53JeIScpKYn58+ezbNky6tSp414fHR1NXl4ehw4dKrY3JzMzk+joaHefP18FVXj11al9/nxFVmZmJpGRkVSoUIHg4GCCg4PP2KfwPc4kPDyc8PDw09aHhoZ65YfcW9sJZBpj79A4e57G2Ds0zp7niTEu7fuV6eoqwzBISkri448/ZsmSJcTFxRV7vm3btoSGhpKamupet3XrVnbt2kV8fDwA8fHxbNy4sdhVUCkpKURGRtKsWTN3n1Pfo7BP4XuEhYXRtm3bYn1cLhepqanuPiIiIhLYyrQnZ/jw4cyaNYtPPvmEypUru8+hqVKlChUqVKBKlSoMHTqU5ORkqlevTmRkJH/729+Ij4/nqquuAiAhIYFmzZpx5513MnHiRDIyMnj88ccZPny4ey/LX//6V15//XUeeugh7rnnHpYsWcKcOXP4/PPP3bUkJyczePBg2rVrR/v27Xn11VfJyclhyJAh5TU2IiIi4sfKFHLefPNNALp06VJs/Xvvvcfdd98NwCuvvEJQUBADBgwgNzeXxMRE3njjDXff4OBg5s+fz7Bhw4iPj6dSpUoMHjyYp59+2t0nLi6Ozz//nNGjRzN58mTq1KnD22+/TWJiorvPLbfcwv79+xk3bhwZGRlcfvnlLFy48LSTkUVERCQwlSnkGIZxzj4RERFMnTqVqVOnnrVPvXr1WLBgQYnv06VLF9avX19in6SkJJKSks5Zk4iIiAQe3btKREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREbEkhR0RERGxJIUdERERsSSFHREREyl3Q4seofWgNGIZlNYRYtmURERGxp5+XErzmLdoDrnl74OYZlpShPTkiIiJSfgryYeFYd9N16XWWlaKQIyIiIuXnu39B1mYADlWoj9HqVstKUcgRERGR8nH8ICz5h7u5oc6d4LAuauicHBERESkfX78Axw8A4Go+gINhjSwtR3tyRERE5MJl/Qirp5vLoRUp6PqktfWgkCMiIiIXyjBg0aNgFJjtzqMhMsbamlDIERERkQu1fTHsSDWXq8RCx79ZW89JCjkiIiJy/vJzi10yTo+nIbSCdfWcQiFHREREzt/KN+HADnO5bkdofpO19ZxCIUdERETOT/Y+WPaiuewIgl4vgMNhbU2nUMgRERGR8/Plk5B31FxuOwRqt7K2nj9RyBEREZGy27USNsw2lyOqQtfHLS3nTBRyREREpGxcBfDFQ0Xtro9DxerW1XMWCjkiIiJSNuv/Dfu+N5ejWpiHqnyQQo6IiIiU3vGDkPp0UbvXRAj2zbtEKeSIiIhI6X31HBz7w1xuMQDqd7K2nhIo5IiIiEjp7NsAa942l0MrmhP/+TCFHBERETk3w4AFY8Bwme1rxkCVOtbWdA4KOSIiInJuG+bA7pXmcvUGED/c2npKQSFHRERESnYiG1KeKGr3nggh4dbVU0plDjnLli2jb9++xMTE4HA4mDdvXrHn7777bhwOR7FHz549i/U5cOAAgwYNIjIykqpVqzJ06FCOHj1arM+GDRu4+uqriYiIIDY2lokTJ55Wy9y5c2nSpAkRERG0bNmSBQsWlPXjiIiIyLksfQGOZprLTa6Hht2trae
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"m = np.vstack((x**2, x, np.ones(11))).T\n",
"s = np.linalg.lstsq(m, y, rcond = None)[0]\n",
"\n",
2024-09-27 05:31:03 +00:00
"x_prec = np.linspace(0, 10, 101)\n",
2024-09-23 23:22:33 +00:00
"\n",
"plt.plot(x, y,'D')\n",
"plt.plot(x_prec, s[0] * x_prec**2 + s[1] * x_prec + s[2], '-', lw=2)\n",
"plt.grid()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Эктраполяция полиномом третьей степени"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 407,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjkAAAGdCAYAAADwjmIIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABI50lEQVR4nO3deXwV1f3/8de9WdnCnoRIgLDviyAQVARZwlJbKj8VtZYq1dYvVCGtVq3FrZaKKyjK17Zq7VdcsIW2QJEYBETCIhBl35HNBGQLBEhukvn9MSYwWW+Se+/c5f18POaBc+7JzOeexNx3Zs7MOAzDMBAREREJMk67CxARERHxBoUcERERCUoKOSIiIhKUFHJEREQkKCnkiIiISFBSyBEREZGgpJAjIiIiQUkhR0RERIJSuN0F2KmoqIhjx47RoEEDHA6H3eWIiIiIGwzD4Ny5cyQkJOB0Vny8JqRDzrFjx0hMTLS7DBEREamBw4cP07JlywpfD+mQ06BBA8AcpJiYGK/tx+VysWzZMkaOHElERITX9hPKNMa+oXH2Po2xb2icvc+bY5yTk0NiYmLJ53hFQjrkFJ+iiomJ8XrIqVu3LjExMfqfyUs0xr6hcfY+jbFvaJy9zxdjXNVUE008FhERkaCkkCMiIiJBSSFHREREgpJCjoiIiAQlhRwREREJSgo5IiIiEpQUckRERCQoKeSIiIhIUFLIERERkaCkkCMiIiJBSSFHREREPKuoyO4KgBB/dpWIiIh4wZJfE35oHd2Nq3DsAtrdAHUa+bwMHckRERERz9q/EsfxbbQ7sYzwj38Km/9uSxkKOSIiIuI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LCwsrtU7yN8jz66KOkpqaWrOfk5JCYmMjIkSOJiYmpxghUj8vlIi0tjREjRhAR4X+Pog8GGmPf0Dh7n8bYNzTO1RP2j/mW9YhOIxgz9geVfo03x7j4TExVqhVyDMPgV7/6FQsWLGDFihUkJSVZXu/bty8RERGkp6czfvx4AHbt2sWhQ4dITk4GIDk5mWeffZbjx48TGxsLmCkvJiaGrl27lvRZsmSJZdtpaWkl24iMjKRv376kp6czbtw4wDx9lp6ezpQpUyqsPyoqiqioqDLtERERPvkh99V+QpnG2Dc0zt6nMfYNjbMbCgvgoPVRDs4Ow3G6OW7eGGN3t1etkDN58mTmzZvHv/71Lxo0aFAyh6Zhw4bUqVOHhg0bMmnSJFJTU2nSpAkxMTH86le/Ijk5mYEDBwIwcuRIunbtyl133cXMmTPJysri8ccfZ/LkySUB5Je//CWvvfYaDz/8MPfccw/Lly/no48+YvHixSW1pKamMnHiRPr160f//v155ZVXyM3N5e67767OWxIREZHKHNsMl85a29r6/6RjqGbIeeONNwAYMmSIpf3tt9/mZz/7GQAvv/wyTqeT8ePHk5eXR0pKCq+//npJ37CwMBYtWsT9999PcnIy9erVY+LEiTz99NMlfZKSkli8eDHTpk1j1qxZtGzZkr/85S+kpKSU9Lnttts4ceIE06dPJysri969e7N06dIyk5FFRESkFkpfVdW8MzS8yp5aqqnap6uqEh0dzZw5c5gzZ06FfVq3bl3mdFRpQ4YMYfPmzZX2mTJlSqWnp0RERKSWAuxRDlfSs6tERESkfJfOwpEN1jaFHBEREQl4Bz4Ho/DyelgktB5kXz3VpJAjIiIi5dv7qXW91UCIrGdPLTWgkCMiIiJlGQbsTbe2tR9efl8/pZAjIiIiZX23G84esrYp5IiIiEjA21PqcQwNEiC2qz211JBCjoiIiJRVej5Oh+HgcNhTSw0p5IiIiIhVfi5884W1LcBOVYFCjoiIiJR2cDUU5l9ed4RB2yG2lVNTCjk
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"m = np.vstack((x**3, x**2, x, np.ones(11))).T\n",
"s = np.linalg.lstsq(m, y, rcond = None)[0]\n",
"\n",
2024-09-27 05:31:03 +00:00
"x_prec = np.linspace(0, 10, 101)\n",
2024-09-23 23:22:33 +00:00
"\n",
2024-09-27 05:31:03 +00:00
"plt.plot(x, y, 'D')\n",
2024-09-23 23:22:33 +00:00
"plt.plot(x_prec, s[0] * x_prec**3 + s[1] * x_prec**2 + s[2] * x_prec + s[3], '-', lw=3)\n",
"plt.grid()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.1.5 Задача\n",
"\n",
"Необходимо проверить гипотезу, что наши точечно заданная функция ложится \n",
"на кривые вида: \n",
"1. $f(x,b) = b_0+b_1x$\n",
"2. $f(x,b) = b_0+b_1x+b_2x^2$\n",
"3. $f(x,b) = b_0+b_1\\ln(x)$\n",
"4. $f(x,b) = b_0x^{b_1}$ "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Функция №1"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 439,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"[1.45930946 1.67619359]\n",
"0.04053187863635288\n",
"35.64010010802867\n"
2024-09-23 23:22:33 +00:00
]
}
],
"source": [
"beta = (1.24, 1.74)\n",
"def f(x, b0, b1):\n",
" return b0 + b1 * x\n",
"\n",
"xdata = np.linspace(0,5,50)\n",
"y = f(xdata, *beta)\n",
2024-09-27 05:31:03 +00:00
"ydata = y + 1 * np.random.randn(len(xdata))\n",
2024-09-23 23:22:33 +00:00
"\n",
"from scipy.optimize import curve_fit\n",
"beta_opt, beta_cov = curve_fit(f, xdata, ydata)\n",
"print(beta_opt)\n",
"\n",
"lin_dev = sum(beta_cov[0])\n",
"print(lin_dev)\n",
"\n",
"residuals = ydata - f(xdata, *beta_opt)\n",
"fres = sum(residuals**2)\n",
"print(fres)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 440,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkUAAAG6CAYAAAAGUjKQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABgKUlEQVR4nO3deVzU1RrH8c+ACppI4oYmFlmpSO5LLi1abplXq1tZmlruS7nkXmamubVom2uLltl+zazULDPT3BEV0Sy1NMUNFNxAnZn7x8+ZAQVhYDaG7/v14nUvZ37z+x2ge+fpnOc8j8lqtVoRERERKeACvD0BEREREV+goEhEREQEBUUiIiIigIIiEREREUBBkYiIiAigoEhEREQEUFAkIiIiAkAhb0/AV1ksFg4fPkxISAgmk8nb0xEREZEcsFqtnD59mgoVKhAQ4Nzaj4KiLBw+fJiIiAhvT0NERERy4eDBg1SsWNGp9ygoykJISAhg/FJLlCjh5dmIiIhITqSkpBAREWH/HHeGgqIs2LbMSpQooaBIREQkn8lN6osSrUVERERQUCQiIiICKCgSERERARQUiYiIiAAKikREREQABUUiIiIigIIiEREREUBBkYiIiAigoEhEREQEUEVrERER8XFmi5WN+5M4djqVsiHBNIgMIzDA9c3aFRSJiIiIz1oWl8C4JfEkJKfax8qHBjO2XRSto8u79FnaPhMRERGftCwugb4LYjIERABHklPpuyCGZXEJLn2egiIRERHxOWaLlXFL4rFm8pptbNySeMyWzK7IHQVFIiIi4nM27k+6aoUoPSuQkJzKxv1JLnumgiIRERHxOcdOZx0Q5ea6nFBQJCIiIj6nbEiwS6/LCQVFIiIi4nMaRIZRPjSYrA7emzBOoTWIDHPZMxUUiYiIiM8JDDAxtl0UwFWBke37se2iXFqvSEGRiIiI+KTW0eWZ2bkO4aEZt8jCQ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17pYQxNm0DSX0XslwVVOElY6x0UKXM6ixt5Jxlcp89EREQKGJfXM0pNheefh3r17AHRLlMU99zwF0+fmErSaSMgCg2FGTOs1OoXQ1AWAZGztZlcSUGRiIhIAePSekZr10KtWjBxIly6RCpBvFhmBjUDd7D6UGX7ZY8/Drt3Q9++Jl5q77raTK6koEhERKSAcUk9o9OnjZ4bd94Jf/wBwE+Brbg97BDjj/fl4iUjxLj5Zli+HBYuhPBw462urM3kSsopEhERKWDyXM9o6VLo3dtekfoYZXiu1HwWJLaByztuhQrB8OHwwgtQtOjVt3BVbSZXUlAkIiJSwOSmnhEAiYkweDB8/DEAFkx8UKQPwwu9wclEx6pPkyYwezZUr579PDx97P5atH0mIiJSADm1hWW1wuefGy06LgdEO4ni7uu30fPCDE6eM+5RsqRRq3H16uwDIl+klSIREZECKkdbWIcOQb9+Rqt64DzBTAiawNRLg7l0yrG20rkzvP46lC3r6Z/CdRQUiYiIFGBZbmFZLPDee0aLjpQUAH6kBX2v+4h9Z8Ptl91yC8ycCffd56kZu4+2z0RERCSjv/6Ce+81kqlTUjhCOZ4I/ppW/GgPiAoXhjFjYMcO/wiIQCtFIiIiYnPpEkybBi++CKmpWDAxl56MLPIGp1Kvs192110wa5aRYuRPFBSJiIiI0aKje3fYsgWAHUTTO2ge69LqwgXjkrAweO016NYNTN47Oe822j4TEREpyFJTjWJC9erBli2cpRgjmEKdgFgjILqsa1ejIvVTT/lnQARaKRIRESm41q6FHj2MaAf4gTb0LzyHvy9WhMuN62+7zdgqa9bMi/P0EAVFIiIiBc3p0zB6NLz7LlitHKY8g0xv8aX1v3DRuKRIEeOSESMg2MmG9WaL1ac
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots()\n",
"ax.scatter(xdata, ydata)\n",
"ax.plot(xdata, y, 'r', lw=2)\n",
"ax.plot(xdata, f(xdata, *beta_opt), 'b', lw=2)\n",
"ax.set_xlim(0,5)\n",
"ax.set_xlabel(r'$x$', fontsize=18)\n",
"ax.set_ylabel(r'$f(x, \\beta)$', fontsize=18)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Функция №2"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 410,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"[0.52433999 2.73790669 1.17001858]\n",
"0.0001973378757534478\n",
"0.1645591178934446\n"
2024-09-23 23:22:33 +00:00
]
}
],
"source": [
"beta = (0.51, 2.74, 1.17)\n",
"def f(x, b0, b1, b2):\n",
" return b0 + b1 * x + b2 * x**2\n",
"\n",
"xdata = np.linspace(0,5,50)\n",
"y = f(xdata, *beta)\n",
"ydata = y + 0.05 * np.random.randn(len(xdata))\n",
"\n",
"from scipy.optimize import curve_fit\n",
"beta_opt, beta_cov = curve_fit(f, xdata, ydata)\n",
"print(beta_opt)\n",
"\n",
"lin_dev = sum(beta_cov[0])\n",
"print(lin_dev)\n",
"\n",
"residuals = ydata - f(xdata, *beta_opt)\n",
"fres = sum(residuals**2)\n",
"print(fres)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 411,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkUAAAG6CAYAAAAGUjKQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABSmUlEQVR4nO3deXhU5d3/8fdksq9kT4AEkB2RHUJkUdkREQR3rWitWos+InXDX6tSbbFqW2tVtFZFq4hbQXFhEYSwBAIJYScgRFmyAYFsZJ05vz9CJpkQIIGQ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ZGAtDTfRulvz5Isb8X4DxdqhtCfYpERETETtbO44wcWsLBinYA9PTcy4qUSPZ7t3G6LtUNoVAkIiIiNsfT8xk94AQ/lXUCoLN7OssT/Ym4PJIIB8/tUlMoEhERcWE19zQLKLby5JhCdpR0ByDWfJgfVroR1a+1g2fZNBSKREREXFTNPc08ii34vt2WbaX9AIgyZbNicTGxwzo7eJZNR6FIRETEBdXc08xcaiXoPxEknw5EwRznpZf302n8lY6dZBNT9ZmIiIiLqbmnmancSsS7QSSfGgxAIHn0Gfcdb5YVY7Ea575RC6NQJCIi4mJse5pZrLR+158NBcMB8OEUg0Ys4kDvEDLzSlrMnmb1pVAkIiLiYnIKSjCsBjHv+bA+7xoAPCll2NDP2TcwzG6cK1EoEhERcTHhfl60f9+DtbmjAPCgjBGDF5A2JMxuXEvZ06y
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots()\n",
"ax.scatter(xdata, ydata)\n",
"ax.plot(xdata, y, 'r', lw=2)\n",
"ax.plot(xdata, f(xdata, *beta_opt), 'b', lw=2)\n",
"ax.set_xlim(0,5)\n",
"ax.set_xlabel(r'$x$', fontsize=18)\n",
"ax.set_ylabel(r'$f(x, \\beta)$', fontsize=18)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Функция №3"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 412,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"[1.37468848 0.47099867]\n",
"5.1105391253661135e-05\n",
"0.15167039301730045\n"
2024-09-23 23:22:33 +00:00
]
}
],
"source": [
"beta = (1.37, 0.48)\n",
"\n",
"def f(x, b0, b1):\n",
" return b0 + b1 * np.log(x)\n",
"\n",
"xdata = np.linspace(0.01,5,50)\n",
"y = f(xdata, *beta)\n",
"ydata = y + 0.05 * np.random.randn(len(xdata))\n",
"\n",
"from scipy.optimize import curve_fit\n",
"beta_opt, beta_cov = curve_fit(f, xdata, ydata)\n",
"print(beta_opt)\n",
"\n",
"lin_dev = sum(beta_cov[0])\n",
"print(lin_dev)\n",
"\n",
"residuals = ydata - f(xdata, *beta_opt)\n",
"fres = sum(residuals**2)\n",
"print(fres)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 413,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlUAAAG6CAYAAAAh/LN4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABUtklEQVR4nO3deXiU5fn28e/MZCcLZCELJBC2QERA9k1QQUGBglrrggXX1q3V4oq1UrT9Uevaqq9rLVWkalVQUHEBFVFkR0F2CCRA9kD2deZ5/xgyIZJlJpnMZDk/xzGHTybPzFyZsZ3T+76f6zYZhmEgIiIiIs1i9nYBIiIiIu2BQpWIiIiIGyhUiYiIiLiBQpWIiIiIGyhUiYiIiLiBQpWIiIiIGyhUiYiIiLiBj7cLaK9sNhvHjx8nJCQEk8nk7XJERETECYZhUFhYSFxcHGaza2NPClUt5Pjx48THx3u7DBEREWmCtLQ0unfv7tJjFKpaSEhICGD/UEJDQ71cjYiIiDijoKCA+Ph4x/e4KxSqWkj1lF9oaKhClYiISBvTlKU7WqguIiIi4gYKVSIiIiJuoFAlIiIi4gYKVSIiIiJuoFAlIiIi4gYKVSIiIiJuoFAlIiIi4gYKVSIiIiJuoFAlIiIi4gbqqC4iIiJtktVmsDElj6zCMrqGBDAyMRyL2fVO6O6iUCUiIiJtzqqd6SxcsYv0/DLHfbFhASyYkczUgbFeqUnTfyIiItKm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jhuG/s2LEMGjRIC9VFRGh8BKq+0ZPqM2qNnpSW2kecdu+G3bux7d5
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots()\n",
"ax.scatter(xdata, ydata)\n",
"ax.plot(xdata, y, 'r', lw=2)\n",
"ax.plot(xdata, f(xdata, *beta_opt), 'b', lw=2)\n",
"ax.set_xlim(0,5)\n",
"ax.set_xlabel(r'$x$', fontsize=18)\n",
"ax.set_ylabel(r'$f(x, \\beta)$', fontsize=18)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Функция №4"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 414,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"[0.88850056 1.91981925]\n",
"9.931739265191307e-05\n",
"0.1375688913692001\n"
2024-09-23 23:22:33 +00:00
]
}
],
"source": [
"beta = (0.89, 1.92)\n",
"def f(x, b0, b1):\n",
" return b0 + np.float_power(x, b1)\n",
"\n",
"xdata = np.linspace(0,5,50)\n",
"y = f(xdata, *beta)\n",
"ydata = y + 0.05 * np.random.randn(len(xdata))\n",
"\n",
"from scipy.optimize import curve_fit\n",
"beta_opt, beta_cov = curve_fit(f, xdata, ydata)\n",
"print(beta_opt)\n",
"\n",
"lin_dev = sum(beta_cov[0])\n",
"print(lin_dev)\n",
"\n",
"residuals = ydata - f(xdata, *beta_opt)\n",
"fres = sum(residuals**2)\n",
"print(fres)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 415,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkUAAAG6CAYAAAAGUjKQAAAAOXRFWHRTb2Z0d2F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IIyxfvpzNmzcTHh5e4/Fhw4bh6urKpk2b7NeOHDnC6dOniY6Obu7pioiItHgWq424E9ms2HWSuwfvJ6G0cstKuNsZvtjTDTePFhkpamiRK0UPP/wwn3zyCV9++SW+vr72fUL+/v54enri7+/P/fffz4IFCwgICMDPz49HH32U6OjoelWeiYiIyAXrDqaxaNUh0swlDHk/ly9z7gbAhwJWrTbSobuPg2fYOFpkKFqyZAkAEydOrHH9vffeY/78+QC88sorGI1Gbr31VkpLS4mJieFf//pXM89URESkZavqZ2YDhq5JY3n6AwAYsDJwwtekdIymv2On2GhaxTlFTUHnFImISFtnsdoY+9Jm0swlRO5J45tNd1OCJwDj+67k9CxTs5w91BBt/pwiERERaXzxyTmkmUsIS85m76aZ9kAU3WEzJ39iahH9zBpCoUhERETqlJlfQrvzBZxbNpzMH3uaDfTcR+q8InulWdW41kChSEREROoUaASf90M5bI0EoKvpJCXzzlzU08yZ+5k1hEKRiIiIXMxm4/Pbv2N76QQA/MnF/459lPlfiA4GoKN/5eGMrYFCkYiIiFzkXzPW8M+j0wBwoZy+UzeR19XN/nhL6WfWEApFIiIiUsP6Z77h12ti7N//ds4uDBPb1RjTUvqZNUSLPKdIREREmsbBjxK546W
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots()\n",
"ax.scatter(xdata, ydata)\n",
"ax.plot(xdata, y, 'r', lw=2)\n",
"ax.plot(xdata, f(xdata, *beta_opt), 'b', lw=2)\n",
"ax.set_xlim(0,5)\n",
"ax.set_xlabel(r'$x$', fontsize=18)\n",
"ax.set_ylabel(r'$f(x, \\beta)$', fontsize=18)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.2.1 Задание\n",
"\n",
"Постройте модель линейной регрессии для произвольных данных из двух \n",
"столбцов. Для примера можно взять точечную зависимость заработной платы от \n",
"опыта работы: \n",
"(https://raw.githubusercontent.com/AnnaShestova/salary-years-simple-linear-regression/master/Salary_Data.csv). \n",
"Найдите коэффициенты линии регрессии. Постройте прогноз. "
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 416,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>YearsExperience</th>\n",
" <th>Salary</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>30.000000</td>\n",
" <td>30.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>5.313333</td>\n",
" <td>76003.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>2.837888</td>\n",
" <td>27414.429785</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>1.100000</td>\n",
" <td>37731.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>3.200000</td>\n",
" <td>56720.750000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>4.700000</td>\n",
" <td>65237.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>7.700000</td>\n",
" <td>100544.750000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>10.500000</td>\n",
" <td>122391.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" YearsExperience Salary\n",
"count 30.000000 30.000000\n",
"mean 5.313333 76003.000000\n",
"std 2.837888 27414.429785\n",
"min 1.100000 37731.000000\n",
"25% 3.200000 56720.750000\n",
"50% 4.700000 65237.000000\n",
"75% 7.700000 100544.750000\n",
"max 10.500000 122391.000000"
]
},
2024-09-27 05:31:03 +00:00
"execution_count": 416,
2024-09-23 23:22:33 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"url = 'https://raw.githubusercontent.com/AnnaShestova/salary-years-simple-linear-regression/master/Salary_Data.csv'\n",
"\n",
"ds = pd.read_csv(url)\n",
"\n",
"ds.describe()"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 417,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlUAAAGwCAYAAACAZ5AeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA+jElEQVR4nO3df3hT5f3/8Vda6A+hDRRt02rBDhEoRQEZtYI6tVgmdnZzU1hxDJnuy2BSUQfOQWETEdRNUCni9hnbwB/oNdGidp8OnAysLbRULCCiVkFsQCkk5UcLNuf7Rz+NhLbQhtMkbZ6P68q15Zw7J+9EJS/Ouc/7thiGYQgAAADnJMTfBQAAAHQGhCoAAAATEKoAAABMQKgCAAAwAaEKAADABIQqAAAAExCqAAAATNDF3wUEE5fLpS+//FJRUVGyWCz+LgcAALSCYRiqqalRQkKCQkJaPh9FqPKhL7/8UomJif4uAwAAeGHv3r266KKLWtxPqPKhqKgoSQ3/UKKjo/1cDQAAaA2n06nExET373hLCFU+1HjJLzo6mlAFAEAHc7apO0xUBwAAMAGhCgAAwASEKgAAABMQqgAAAExAqAIAADABoQoAAMAEhCoAAAATEKoAAABMQKgCAAAwAR3VAQBAwKp3GSqprNaBmlrFRkVoRFKMQkPO3NncXwhVAAAgIBVUVGle/g5VOW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AQKdRUFGlKSvLPAKVJNkdtZqyskwFFVV+qgzBgFAFAOgU6l2G5uX
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.scatter(ds['YearsExperience'], ds['Salary'])\n",
"plt.xlabel('Опыт (годы)')\n",
"plt.ylabel('Зарплата')\n",
"plt.show()"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 418,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [],
"source": [
"X = ds.iloc[:, :-1].values\n",
"y = ds.iloc[:, 1].values\n",
"\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 419,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"26780.09915062818\n",
2024-09-23 23:22:33 +00:00
"[9312.57512673]\n"
]
}
],
"source": [
"regressor = LinearRegression()\n",
"regressor.fit(X_train, y_train)\n",
"\n",
"print(regressor.intercept_)\n",
"print(regressor.coef_)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 420,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [],
"source": [
"y_pred = regressor.predict(X_test)\n",
"df = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 421,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkIAAAGYCAYAAACu6o3UAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA8hklEQVR4nO3dfVhUdf7/8dcMNwOogGhyU6hsd2qapqTRmmuFYLmtmrlZltSyuhlUyKZJX1PSyqTVvE3Wb5r1XS3tt+WausgsrlJJqChlpmatm+62g+56Q0jAyMzvDy9mHfEOPYjjeT6ui+tqznnP53zOmzPyas45Mxa32+0WAACACVmbegIAAABNhSAEAABMiyAEAABMiyAEAABMiyAEAABMiyAEAABMiyAEAABMiyAEAABMy7+pJ3A5c7lc+v7779WiRQtZLJamng4AADgPbrdbP/zwg2JiYmS1nv09H4LQWXz//feKjY1t6mkAAIALsH//fl1zzTVnrSEInUWLFi0knWhkaGhoE8/mzJxOp/Lz85WUlKSAgICmno7Poo/GoZfGoZfGoI/G8YVelpeXKzY21vN3/GwIQmdRdzosNDT0sg9CISEhCg0NvWwPSl9AH41DL41DL41BH43jS708n8tauFgaAACYFkEIAACYFkEIAACYFtcIATgjl8ulmpqaBj/P6XTK399fVVVVqq2tbYSZmcfF9DIgIEB+fn6NNDPgykAQAnBaNTU12rt3r1wuV4Of63a7FRUVpf379/MZXBfpYnsZHh6uqKgofg/AGRCEANTjdrv1r3/9S35+foqNjT3nB5KdyuVyqaKiQs2bN2/wc+HtQnvpdrtVWVmpAwcOSJKio6Mba4qATyMIAajn+PHjqqysVExMjEJCQhr8/LpTakFBQQShi3QxvQwODpYkHThwQG3atOE0GXAa/AsFoJ66a1ECAwObeCa4WHVB1ul0NvFMgMsTQQjAGXFdie/jdwicHUEIAACYFkEIAC4Bi8WiFStWNPU0AJyCi6UBnLf241df0u39/dUBF/S8oqIi9e7dW/3799fq1ec/5/bt2ysjI0MZGRkXtF0Avod3hABccRYuXKinnnpKhYWF+v7775t6OgAuYwQhAFeUiooKLVu2TKNHj9aAAQO0ePFir/UfffSRbr31VgUFBal169YaPHiwJKlv37767rvvNGbMGFksFs9FxtnZ2erWrZvXGDNnzlT79u09jzdv3qx+/fqpdevWCgsL089+9jNt3bq1MXcTgEE4NQacauo1kqvKuPGyjxo3F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HfI3G63fvjhB7Vo0cLzCc24MBfby6qqKgUHB6tPnz4X9Lu8Upj530mj+UIv687onI9GCUJ1Iei7777TunXrvEJEVFSUDhw44FV//PhxHTp0yPMhZlFRUSorK/OqqXt8rpqT19cti46O9qo59ePy69hsNtlstnrLAwICLttf9sl8ZZ5Gqq41/o9sgKvK2CDkg7+T2tpaWSwWWa3WC7rGp+4UTt0YuHAX20ur1SqLxWLKfx9Ohz4Y53LuZUPmZfi/UHUhaM+ePfrLX/6iVq1aea1PSEjQkSNHVFJS4lm2bt06uVwu9erVy1NTWFjodY7PbrfrxhtvVMuWLT01p94Ga7fblZCQIEmKi4tTVFSUV015ebmKi4s9NQAAwNwaHIQqKio8n88hnbgoubS0VPv27ZPT6dQDDzygLVu2aMmSJaqtrZXD4ZDD4fBcZ9CxY0f1799fI0eO1KZNm/Tpp58qPT1dw4YN83wI2sMPP6zAwEClpqZqx44dWrZsmWbNmuV12uqZZ55RXl6epk+frl27dik7O1tbtmxRenq6pBP/95SRkaGXXnpJK1e
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df.plot(kind='bar')\n",
"plt.grid()\n",
"plt.show()"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 422,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkIAAAGdCAYAAAD+JxxnAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA9sklEQVR4nO3de3RU1f3//1cuMAmQC8HmglxM/SCUSxVKjfH6aUkNXYjy09aKQSlS9YNYQVtFq4BoFQx4KSogWhUFUagXBBGbAopAGjCESwQDtRGokKRfQiYBSQ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AgBANCa/fe/viHoiiusewMRgk6LIAQAQGs1bpz1xPi6tm+X1qxxpp5WiKUxAABaG2Ok0Hp6Gaa+WyniVOgIAQDQmnz2mW8IevZZQtAZoiMEAEBrERdn3QuorsOHpXbtnKknANARAgDA35WXWxui64agHj2sLhAh6KwQhAAA8GePPSbFxNjHNmyQdu50pp4Aw9IYAAD+qr57A7EXqEnREQIAwN9s2uQbgiZOJAQ1AzpCAAD4kz59rHsB1cXDUpsNQQgAAH9w5IjvxucOHaSKCmfqCRIsjQEA4LTnn/cNQatWEYJaAB0hAACcVN+GaI+n/nE0OTpCAAA4oaDAN+zcdZe1IZoQ1GLoCAEA0NIGDbKWvuoqKpISEpypJ4gRhAAAaCnV1VLbtr7jXBbvGJbGAABohBqPUfbXB7Rk87fK/vqAajwNDDHz5/uGoA8+IAQ5jI4QAAANtCJ
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.scatter(X_test, y_test)\n",
"plt.plot(X_test, y_pred, c='r')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.3.2 Задание\n",
"\n",
"Постройте модель множественной линейной регрессии для произвольных \n",
"данных из нескольких столбцов. Для примера можно взять потребления \n",
"газа (в миллионах галлонов) в 48 штатах США или набор данных о \n",
"качестве красного вина (1) и (2) соответственно. Найдите коэффициенты \n",
"множественной регрессии. Постройте прогноз. "
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 423,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>fixed acidity</th>\n",
" <th>volatile acidity</th>\n",
" <th>citric acid</th>\n",
" <th>residual sugar</th>\n",
" <th>chlorides</th>\n",
" <th>free sulfur dioxide</th>\n",
" <th>total sulfur dioxide</th>\n",
" <th>density</th>\n",
" <th>pH</th>\n",
" <th>sulphates</th>\n",
" <th>alcohol</th>\n",
" <th>quality</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" <td>1599.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>8.319637</td>\n",
" <td>0.527821</td>\n",
" <td>0.270976</td>\n",
" <td>2.538806</td>\n",
" <td>0.087467</td>\n",
" <td>15.874922</td>\n",
" <td>46.467792</td>\n",
" <td>0.996747</td>\n",
" <td>3.311113</td>\n",
" <td>0.658149</td>\n",
" <td>10.422983</td>\n",
" <td>5.636023</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>1.741096</td>\n",
" <td>0.179060</td>\n",
" <td>0.194801</td>\n",
" <td>1.409928</td>\n",
" <td>0.047065</td>\n",
" <td>10.460157</td>\n",
" <td>32.895324</td>\n",
" <td>0.001887</td>\n",
" <td>0.154386</td>\n",
" <td>0.169507</td>\n",
" <td>1.065668</td>\n",
" <td>0.807569</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>4.600000</td>\n",
" <td>0.120000</td>\n",
" <td>0.000000</td>\n",
" <td>0.900000</td>\n",
" <td>0.012000</td>\n",
" <td>1.000000</td>\n",
" <td>6.000000</td>\n",
" <td>0.990070</td>\n",
" <td>2.740000</td>\n",
" <td>0.330000</td>\n",
" <td>8.400000</td>\n",
" <td>3.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>7.100000</td>\n",
" <td>0.390000</td>\n",
" <td>0.090000</td>\n",
" <td>1.900000</td>\n",
" <td>0.070000</td>\n",
" <td>7.000000</td>\n",
" <td>22.000000</td>\n",
" <td>0.995600</td>\n",
" <td>3.210000</td>\n",
" <td>0.550000</td>\n",
" <td>9.500000</td>\n",
" <td>5.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>7.900000</td>\n",
" <td>0.520000</td>\n",
" <td>0.260000</td>\n",
" <td>2.200000</td>\n",
" <td>0.079000</td>\n",
" <td>14.000000</td>\n",
" <td>38.000000</td>\n",
" <td>0.996750</td>\n",
" <td>3.310000</td>\n",
" <td>0.620000</td>\n",
" <td>10.200000</td>\n",
" <td>6.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>9.200000</td>\n",
" <td>0.640000</td>\n",
" <td>0.420000</td>\n",
" <td>2.600000</td>\n",
" <td>0.090000</td>\n",
" <td>21.000000</td>\n",
" <td>62.000000</td>\n",
" <td>0.997835</td>\n",
" <td>3.400000</td>\n",
" <td>0.730000</td>\n",
" <td>11.100000</td>\n",
" <td>6.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>15.900000</td>\n",
" <td>1.580000</td>\n",
" <td>1.000000</td>\n",
" <td>15.500000</td>\n",
" <td>0.611000</td>\n",
" <td>72.000000</td>\n",
" <td>289.000000</td>\n",
" <td>1.003690</td>\n",
" <td>4.010000</td>\n",
" <td>2.000000</td>\n",
" <td>14.900000</td>\n",
" <td>8.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
2024-09-27 05:31:03 +00:00
" fixed acidity volatile acidity citric acid residual sugar \\\n",
"count 1599.000000 1599.000000 1599.000000 1599.000000 \n",
2024-09-23 23:22:33 +00:00
"mean 8.319637 0.527821 0.270976 2.538806 \n",
"std 1.741096 0.179060 0.194801 1.409928 \n",
"min 4.600000 0.120000 0.000000 0.900000 \n",
"25% 7.100000 0.390000 0.090000 1.900000 \n",
"50% 7.900000 0.520000 0.260000 2.200000 \n",
"75% 9.200000 0.640000 0.420000 2.600000 \n",
"max 15.900000 1.580000 1.000000 15.500000 \n",
"\n",
2024-09-27 05:31:03 +00:00
" chlorides free sulfur dioxide total sulfur dioxide density \\\n",
"count 1599.000000 1599.000000 1599.000000 1599.000000 \n",
2024-09-23 23:22:33 +00:00
"mean 0.087467 15.874922 46.467792 0.996747 \n",
"std 0.047065 10.460157 32.895324 0.001887 \n",
"min 0.012000 1.000000 6.000000 0.990070 \n",
"25% 0.070000 7.000000 22.000000 0.995600 \n",
"50% 0.079000 14.000000 38.000000 0.996750 \n",
"75% 0.090000 21.000000 62.000000 0.997835 \n",
"max 0.611000 72.000000 289.000000 1.003690 \n",
"\n",
" pH sulphates alcohol quality \n",
"count 1599.000000 1599.000000 1599.000000 1599.000000 \n",
"mean 3.311113 0.658149 10.422983 5.636023 \n",
"std 0.154386 0.169507 1.065668 0.807569 \n",
"min 2.740000 0.330000 8.400000 3.000000 \n",
"25% 3.210000 0.550000 9.500000 5.000000 \n",
"50% 3.310000 0.620000 10.200000 6.000000 \n",
"75% 3.400000 0.730000 11.100000 6.000000 \n",
"max 4.010000 2.000000 14.900000 8.000000 "
]
},
2024-09-27 05:31:03 +00:00
"execution_count": 423,
2024-09-23 23:22:33 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"url = 'https://raw.githubusercontent.com/aniruddhachoudhury/Red-Wine-Quality/master/winequality-red.csv'\n",
"\n",
"ds = pd.read_csv(url)\n",
"\n",
"ds.describe()"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 424,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [],
"source": [
"X = ds[['fixed acidity', 'volatile acidity', 'citric acid', 'residual sugar', 'chlorides', 'free sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates', 'alcohol']]\n",
"y = ds['quality']\n",
"\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 425,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"34.99871062872143\n",
2024-09-23 23:22:33 +00:00
"[ 4.12835075e-02 -1.14952802e+00 -1.77927063e-01 2.78700036e-02\n",
" -1.87340739e+00 2.68362616e-03 -2.77748370e-03 -3.15166657e+01\n",
" -2.54486051e-01 9.24040106e-01 2.67797417e-01]\n"
]
}
],
"source": [
"regressor = LinearRegression()\n",
"regressor.fit(X_train, y_train)\n",
"\n",
"print(regressor.intercept_)\n",
"print(regressor.coef_)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 426,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Coefficient</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>fixed acidity</th>\n",
" <td>0.041284</td>\n",
" </tr>\n",
" <tr>\n",
" <th>volatile acidity</th>\n",
" <td>-1.149528</td>\n",
" </tr>\n",
" <tr>\n",
" <th>citric acid</th>\n",
" <td>-0.177927</td>\n",
" </tr>\n",
" <tr>\n",
" <th>residual sugar</th>\n",
" <td>0.027870</td>\n",
" </tr>\n",
" <tr>\n",
" <th>chlorides</th>\n",
" <td>-1.873407</td>\n",
" </tr>\n",
" <tr>\n",
" <th>free sulfur dioxide</th>\n",
" <td>0.002684</td>\n",
" </tr>\n",
" <tr>\n",
" <th>total sulfur dioxide</th>\n",
" <td>-0.002777</td>\n",
" </tr>\n",
" <tr>\n",
" <th>density</th>\n",
" <td>-31.516666</td>\n",
" </tr>\n",
" <tr>\n",
" <th>pH</th>\n",
" <td>-0.254486</td>\n",
" </tr>\n",
" <tr>\n",
" <th>sulphates</th>\n",
" <td>0.924040</td>\n",
" </tr>\n",
" <tr>\n",
" <th>alcohol</th>\n",
" <td>0.267797</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Coefficient\n",
"fixed acidity 0.041284\n",
"volatile acidity -1.149528\n",
"citric acid -0.177927\n",
"residual sugar 0.027870\n",
"chlorides -1.873407\n",
"free sulfur dioxide 0.002684\n",
"total sulfur dioxide -0.002777\n",
"density -31.516666\n",
"pH -0.254486\n",
"sulphates 0.924040\n",
"alcohol 0.267797"
]
},
2024-09-27 05:31:03 +00:00
"execution_count": 426,
2024-09-23 23:22:33 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.DataFrame(regressor.coef_, X.columns, columns=['Coefficient'])"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 427,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Actual</th>\n",
" <th>Predicted</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1109</th>\n",
" <td>6</td>\n",
" <td>5.782930</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1032</th>\n",
" <td>5</td>\n",
" <td>5.036193</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1002</th>\n",
" <td>7</td>\n",
" <td>6.596989</td>\n",
" </tr>\n",
" <tr>\n",
" <th>487</th>\n",
" <td>6</td>\n",
" <td>5.339126</td>\n",
" </tr>\n",
" <tr>\n",
" <th>979</th>\n",
" <td>5</td>\n",
" <td>5.939529</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>794</th>\n",
" <td>6</td>\n",
" <td>6.559757</td>\n",
" </tr>\n",
" <tr>\n",
" <th>813</th>\n",
" <td>4</td>\n",
" <td>6.017576</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1322</th>\n",
" <td>5</td>\n",
" <td>6.251291</td>\n",
" </tr>\n",
" <tr>\n",
" <th>704</th>\n",
" <td>4</td>\n",
" <td>5.163926</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1023</th>\n",
" <td>6</td>\n",
" <td>6.367205</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>320 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" Actual Predicted\n",
"1109 6 5.782930\n",
"1032 5 5.036193\n",
"1002 7 6.596989\n",
"487 6 5.339126\n",
"979 5 5.939529\n",
"... ... ...\n",
"794 6 6.559757\n",
"813 4 6.017576\n",
"1322 5 6.251291\n",
"704 4 5.163926\n",
"1023 6 6.367205\n",
"\n",
"[320 rows x 2 columns]"
]
},
2024-09-27 05:31:03 +00:00
"execution_count": 427,
2024-09-23 23:22:33 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_pred = regressor.predict(X_test)\n",
"df = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})\n",
"\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Средняя квадратичная ошибка"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 428,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2024-09-27 05:31:03 +00:00
"np.float64(0.38447119782012357)"
2024-09-23 23:22:33 +00:00
]
},
2024-09-27 05:31:03 +00:00
"execution_count": 428,
2024-09-23 23:22:33 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"metrics.mean_squared_error(y_test,y_pred)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.3.2 Задание*\n",
"\n",
"Экспериментально получены N значений величины Y при \n",
"различных значениях величины X. Построить полиномы первой и второй \n",
"степени, аппроксимирующие результаты эксперимента, с применением \n",
"метода наименьших квадратов. Результаты выводятся в виде таблиц \n",
"значений и графиков, полученных полиномов. \n",
"\n",
"*Вариант:* 2"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 429,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [],
"source": [
"# Линейная функция\n",
"def linear_func(x, b0, b1):\n",
" return b0 + b1 * x\n",
"\n",
"# Квадратичная функция\n",
"def quadratic_func(x, b0, b1, b2):\n",
" return b0 + b1 * x + b2 * x**2"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 430,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [],
"source": [
"xdata = np.linspace(0, 1, 6)\n",
"ydata = np.asarray([5.0, 5.0, 4.0, 4.0, 6.0, 6.0])"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 431,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4.42857143 1.14285715]\n",
" x y\n",
"0 0.0 4.428571\n",
"1 0.2 4.657143\n",
"2 0.4 4.885714\n",
"3 0.6 5.114286\n",
"4 0.8 5.342857\n",
"5 1.0 5.571429\n"
]
}
],
"source": [
"beta_opt, beta_cov = curve_fit(linear_func, xdata, ydata, method='lm')\n",
"print(beta_opt)\n",
"df = pd.DataFrame({\"x\": xdata, \"y\": linear_func(xdata, *beta_opt)});\n",
"#df.columns=['xdata', 'ydata']\n",
"print(df)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 432,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAAGwCAYAAABB4NqyAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABFIUlEQVR4nO3deVyVZf7/8fcBFFwAdxYlw71SM/UruU2LFJZj2a5ZZFmaYptTtkyltmlO08OvS25ZaulQTo2/pjFKLSoTdx23MhcMN3Ci4IglKNy/P66vZ7wFFRC4gfv1fDzOYzz3dZ3D59yTnjfXdd335bEsyxIAAICL+DldAAAAQEUjAAEAANchAAEAANchAAEAANchAAEAANchAAEAANchAAEAANcJcLqAyqigoECHDh1ScHCwPB6P0+UAAIBisCxLR48eVWRkpPz8zj3GQwAqwqFDhxQVFeV0GQAAoBT279+vZs2anbMPAagIwcHBkswJDAkJcbgaAABQHF6vV1FRUb7v8XMhABXh1LRXSEgIAQgAgCqmOMtXWAQNAABchwAEAABchwAEAABchwAEAABchwAEAABchwAEAABchwAEAABchwAEAABchwAEAABchztBAwBcL7/A0trUX3Tk6HE1CQ5St+gG8vdjM+yyVpnOs+MjQAcPHtQ999yjhg0bqlatWurQoYPWr19/ztckJyerc+fOCgwMVKtWrTRv3rxCfaZPn66LL75YQUFBiomJ0dq1a8vpEwAAqrKkbYfV6/UvNWjOaj2WuFmD5qxWr9e/VNK2w06XVq1UtvPsaAD69dd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00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots()\n",
"ax.scatter(xdata, ydata)\n",
"ax.plot(xdata, linear_func(xdata, *beta_opt), 'b', lw=2)\n",
"plt.xlabel('x')\n",
"plt.ylabel('linear')\n",
"plt.show()"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 433,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-09-27 05:31:03 +00:00
"[ 5.14285713 -4.21428562 5.35714277]\n",
2024-09-23 23:22:33 +00:00
" x y\n",
"0 0.0 5.142857\n",
"1 0.2 4.514286\n",
"2 0.4 4.314286\n",
"3 0.6 4.542857\n",
"4 0.8 5.200000\n",
"5 1.0 6.285714\n"
]
}
],
"source": [
"beta_opt, beta_cov = curve_fit(quadratic_func, xdata, ydata, method='lm')\n",
"print(beta_opt)\n",
"df = pd.DataFrame({\"x\": xdata, \"y\": quadratic_func(xdata, *beta_opt)});\n",
"print(df)"
]
},
{
"cell_type": "code",
2024-09-27 05:31:03 +00:00
"execution_count": 434,
2024-09-23 23:22:33 +00:00
"metadata": {},
"outputs": [
{
"data": {
2024-09-27 05:31:03 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGwCAYAAABVdURTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABBxElEQVR4nO3de5yN5f7/8feaGTODPTPkLJNNOcsWNgnpoIiEKMmxLUr6VpRQbKdCQu2d0jk6qii7EJVCRdu57VDKKcJQYcZxxszcvz+u38xqmJlmxlrrWuter+fjsR5d15p7Zj5zh/s9133d1+VxHMcRAACAS0TYLgAAAMCXCDcAAMBVCDcAAMBVCDcAAMBVCDcAAMBVCDcAAMBVCDcAAMBVomwXEGiZmZnav3+/4uLi5PF4bJcDAAAKwHEcHTt2TJUrV1ZERP5jM2EXbvbv36/ExETbZQAAgCLYu3evqlSpku8xYRdu4uLiJJmTEx8fb7kaAABQECkpKUpMTMy+jucn7MJN1q2o+Ph4wg0AACGmIFNKmFAMAABchXADAABchXADAABchXADAABchXADAABchXADAABchXADAABchXADAABchXADAABchXADAABchXADAABchXADAABchXADAAB8Yt8+6corpRUr7NZBuAEAAD7x6KPSV19JrVtLr7xirw7CDQAAOG/r1kmzZ5t26dJSly72aiHcAACA8+I40pAh3v6YMdIFF9irh3ADAADOy4cfmttRklSjhjRokN16CDcAAKDIUlOlYcO8/alTpehoe/VIhBsAAHAennlG2rnTtK+5RurY0W49EuEGAAAU0a+/ShMmmLbHI02bZv5rG+EGAAAUydixUkqKaf/jH1LDhjar8SLcAACAQtu6VXrhBdMuWVJ67DG79fwR4QYAABTaQw9JGRmmPXKkVLGi3Xr+iHADAAAKZckS6ZNPTPuii6ShQ+3WczbCDQAAKLD09JxhZvJkqXhxe/XkhnADAAAK7OWXzXwbSWrWTLrtNrv15IZwAwAACiQ5WfrnP739p54Kjke/z0a4AQAABTJxolnbRjIjNs2b260nL4QbAADwp3bulJ5+2rRjYsxcm2BFuAEAAH9q+HApLc20hw6Vqla1W09+CDcAACBfX38tzZ1r2uXLm3VtghnhBgAA5CkzUxoyxNt/7DEpLs5ePQVBuAEAAHl66y1p7VrTvvRSs4dUsCPcAACAXJ08mfMW1PTpUmSkvXoKinADAAByNXWqtG+fad94o9Smjd16CopwAwAAzrFvn/TEE6YdFWWCTqgg3AAAgHOMGmVuS0nSoEFSrVp26ykMwg0AAMhh/Xpp9mzTLl1aGjPGbj2FRbgBAADZHMc8+u04pv/Pf0plytitqbAINwAAINv8+dKKFaZdo4Z0zz1WyykSwg0AAJAkpaZKw4Z5+08+KUVH26unqAg3AABAkjRjhrRjh2lffbV000126ykqwg0AANBvv0kTJpi2x2MW7PN47NZUVIQbAACg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WO3nmBEuAEAIERs2CDNmmXaCQnS2LE2qwlehBsAAEKA45hHvx3H9P/5T6lsWbs1BSvCDQAAIeA//5GWLTPtiy+WBg+2Wk5QI9wAABDk0tKkYcO8/SeflGJi7NUT7Ag3AAAEuWeflbZvN+3WraXOna2WE/QINwAABLHff5fGjzdtj8escePx2K0p2BFuAAAIYuPGSUePmnbfvlKjRlbLCQmEGwAAgtQPP0jPPWfaJUpIjz9ut55QQbgBACBIDRsmZWSY9vDhUuXKdusJFYQbAACC0OefSwsWmHaVKtJDD9mtJ5QQbgAACDIZGWbBviyTJpnbUigYwg0AAEHm1VelTZtMu0k
2024-09-23 23:22:33 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots()\n",
"ax.scatter(xdata, ydata)\n",
"ax.plot(xdata, quadratic_func(xdata, *beta_opt), 'b', lw=2)\n",
"plt.xlabel('x')\n",
"plt.ylabel('linear')\n",
"plt.show()"
]
}
],
"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",
2024-09-27 05:31:03 +00:00
"version": "3.12.5"
2024-09-23 23:22:33 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 2
}