forked from filipg/aitech-eks-pub
1378 lines
126 KiB
Plaintext
1378 lines
126 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Regresja liniowa"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## import bibliotek"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 1,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"import pandas as pd\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"from pathlib import Path\n",
|
|||
|
"import seaborn as sns\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"from sklearn.linear_model import LinearRegression\n",
|
|||
|
"plt.rcParams['figure.figsize'] = [10, 5]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Zbiór \n",
|
|||
|
"\n",
|
|||
|
"https://git.wmi.amu.edu.pl/kubapok/mieszkania2-below1m-public"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## ładowanie zbioru train"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 2,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"DATA_DIR = Path('/home/kuba/Syncthing/przedmioty/2020-02/ISI/zajecia7_regresja_liniowa/mieszkania2')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 3,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"with open(DATA_DIR / 'names') as f_names:\n",
|
|||
|
" names = f_names.read().rstrip('\\n').split('\\t')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 4,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mieszkania_train = pd.read_csv(DATA_DIR/'train/in.tsv', sep ='\\t', names=names)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 5,
|
|||
|
"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>isNew</th>\n",
|
|||
|
" <th>rooms</th>\n",
|
|||
|
" <th>floor</th>\n",
|
|||
|
" <th>location</th>\n",
|
|||
|
" <th>sqrMetres</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>Centrum</td>\n",
|
|||
|
" <td>78</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>62</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>15</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>4</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>14</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>15</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" isNew rooms floor location sqrMetres\n",
|
|||
|
"0 False 3 1 Centrum 78\n",
|
|||
|
"1 False 3 2 Sołacz 62\n",
|
|||
|
"2 False 3 0 Sołacz 15\n",
|
|||
|
"3 False 4 0 Sołacz 14\n",
|
|||
|
"4 False 3 0 Sołacz 15"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 5,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"mieszkania_train.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 6,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"with open(DATA_DIR/'train'/'expected.tsv','r') as train_exp_f:\n",
|
|||
|
" Y_train = np.array([float(x.rstrip('\\n')) for x in train_exp_f.readlines()])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 7,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"array([476118., 459531., 411557., ..., 320000., 364000., 209000.])"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 7,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"Y_train"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 8,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mieszkania_train['price'] = Y_train"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 9,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"X_train = mieszkania_train['sqrMetres'].to_numpy()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Wizualizacja danych"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 10,
|
|||
|
"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>isNew</th>\n",
|
|||
|
" <th>rooms</th>\n",
|
|||
|
" <th>floor</th>\n",
|
|||
|
" <th>location</th>\n",
|
|||
|
" <th>sqrMetres</th>\n",
|
|||
|
" <th>price</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>Centrum</td>\n",
|
|||
|
" <td>78</td>\n",
|
|||
|
" <td>476118.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>62</td>\n",
|
|||
|
" <td>459531.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>15</td>\n",
|
|||
|
" <td>411557.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>4</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>14</td>\n",
|
|||
|
" <td>496416.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>False</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>Sołacz</td>\n",
|
|||
|
" <td>15</td>\n",
|
|||
|
" <td>406032.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1652</th>\n",
|
|||
|
" <td>True</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" <td>0</td>\n",
|
|||
|
" <td>Grunwald</td>\n",
|
|||
|
" <td>51</td>\n",
|
|||
|
" <td>299000.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1653</th>\n",
|
|||
|
" <td>True</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" <td>2</td>\n",
|
|||
|
" <td>Centrum</td>\n",
|
|||
|
" <td>53</td>\n",
|
|||
|
" <td>339000.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1654</th>\n",
|
|||
|
" <td>True</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>4</td>\n",
|
|||
|
" <td>Stare</td>\n",
|
|||
|
" <td>65</td>\n",
|
|||
|
" <td>320000.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1655</th>\n",
|
|||
|
" <td>True</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>1</td>\n",
|
|||
|
" <td>Nowe</td>\n",
|
|||
|
" <td>67</td>\n",
|
|||
|
" <td>364000.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1656</th>\n",
|
|||
|
" <td>True</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>3</td>\n",
|
|||
|
" <td>Grunwald</td>\n",
|
|||
|
" <td>50</td>\n",
|
|||
|
" <td>209000.0</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>1657 rows × 6 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" isNew rooms floor location sqrMetres price\n",
|
|||
|
"0 False 3 1 Centrum 78 476118.0\n",
|
|||
|
"1 False 3 2 Sołacz 62 459531.0\n",
|
|||
|
"2 False 3 0 Sołacz 15 411557.0\n",
|
|||
|
"3 False 4 0 Sołacz 14 496416.0\n",
|
|||
|
"4 False 3 0 Sołacz 15 406032.0\n",
|
|||
|
"... ... ... ... ... ... ...\n",
|
|||
|
"1652 True 2 0 Grunwald 51 299000.0\n",
|
|||
|
"1653 True 2 2 Centrum 53 339000.0\n",
|
|||
|
"1654 True 3 4 Stare 65 320000.0\n",
|
|||
|
"1655 True 3 1 Nowe 67 364000.0\n",
|
|||
|
"1656 True 3 3 Grunwald 50 209000.0\n",
|
|||
|
"\n",
|
|||
|
"[1657 rows x 6 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 10,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"mieszkania_train"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 11,
|
|||
|
"metadata": {
|
|||
|
"scrolled": false
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.axes._subplots.AxesSubplot at 0x7f25f864e220>"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 11,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmEAAAFICAYAAAAYvikoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3de3hU1b0//vcnIeEaDBAIQjCE+01FiRekKCgoHviK1fI9th4vWMvP0lpsTz3VAwetR9qer30qnnNKfSjFI73Z0gta0Kq0eEREJSgKBCGRgIRLCJeQAAECWb8/9sywZid7s2dn79l7Zt6v5+HZZGbPnjVrz8z+zFqftZYopUBEREREyZUVdAGIiIiIMhGDMCIiIqIAMAgjIiIiCgCDMCIiIqIAMAgjIiIiCgCDMCIiIqIApGQQJiJLReSgiGxxuP//FZFyEdkqIr/xu3xEREREFyKpOE+YiFwP4DiAZUqpURfYdzCA3wO4USl1VER6KaUOJqOcRERERFZSsiVMKfU2gCP6bSIyUET+KiIbRWStiAyL3PU1AD9VSh2NPJYBGBEREQUuJYMwC4sBPKyUGgPguwAWRW4fAmCIiKwTkfdEZEpgJSQiIiKKaBd0AbwgIl0AXAdguYhEb24f2bYDMBjABABFANaKyCilVF2yy0lEREQUlRZBGIwWvTql1OhW7qsG8J5SqglAlYhshxGUbUhmAYmIiIh0adEdqZSqhxFgzQAAMVweuXsFgImR2wtgdE/uDKSgRERERBEpGYSJyG8BrAcwVESqReSrAO4G8FUR+RjAVgDTI7u/DuCwiJQDWAPgUaXU4SDKTURERBSVklNUEBEREaW6lGwJIyIiIkp1DMKIiIiIApByoyMLCgpU//79gy4GERER0QVt3LjxkFKqZ2v3pVwQ1r9/f5SVlQVdDCIiIqILEpHdVvexO5KIiIgoAAzCiIiIiALAIIyIiIgoAAzCiIiIiALAIIyIiIgoAAz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8+P8lBR0xlPTR6X8MH/+qAkG651aw9GRFHrRi1+YRL9QAYSubMTzY4ej5YLBeqfWMAgjcoFfqOHG82MtjD9qMgHrnVrDKSqIiIiIfMIpKoiIiIhChkFYgJjcTURElLkYhAWIo2WIiIgyFxPzA8TkYaLUUXXoBF5YV4WZ40pSfpoKIgoHtoQFKF3mHSLKBG1tuWb6ARGZMQgjorTjR8DT1kmD/U4/WFtRi1uefRtrK2p9OT4ReY9BGBGlHT8CHr3l2k2Q5/fKD0+v3IbtNQ14euU2X45PRN5jEEZpgy0BFOV3wOMmyPM7/WDetOEYWpiHedOG+3J8IvIeJ2ultHHLs29je00Dhhbm4fVvXx90cSiNMUmfiJziZK2UEVK5JSDIpG0mjCeurV2TREQAgzBKI+MH98Tr374e4wf3DLooCQtyzjir52Zw4Qzn+yMitxiEBciLixwvlOnBnMOUzPNqlT/F4MIZv/PPkonfJ0TJxclaAxS9yAHAU9NHBXYMCl60eysqmefV/NxRnEzYGav6S0X8PiFKLgZhAfLiIscLZXoKw3lNp+CCnAnD+44ok3B0JBEREZFPODqSiIiIKGQYhBEREREFgEEYEaUMjt4jonTCIIyIUganzSCidMLRkUSUMjh6j4jSCVvCiChl+L0Idrpgt21q4fnKXAzCiEJobUUtbnn2baytqA26KJSC2G2bWni+MheDMCKNOfgJ6hfq0yu3YXtNA55euS2pz0vnhbF1wmmZ0mkppUzA85W5GIQRaczBT1C/UOdNG46hhXmYN214Up83jIIKhsLYOuG0TF5324YxIE0n7GbPXEzMJ9LMmzYcT6/cFgt+gkoEL+rWCdcM6I6ibp2S+rxhFNR6hmE
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 720x360 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sns.scatterplot(x='sqrMetres',y='price', data = mieszkania_train, linewidth = 0, s = 5)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Pytanie- Jaki jest baseline naszego systemu?"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Czym jest regresja liniowa?- przypadek jednowymiarowy"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/1.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/2.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/3.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/4.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## wzór na regresję w przypadku jednowymiarowym?\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"$Y = a*X_1 + b$\n",
|
|||
|
"\n",
|
|||
|
"$Y = w_1 * X_1 + w_0$"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Zadanie - napisać funkcję predict_score(sqr_metres) która zwraca cenę mieszkania zgodnie z modelem regresji liniowej ( 5 minut) \n",
|
|||
|
"\n",
|
|||
|
"Należy samemu wymyślić współczynniki modelu"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 12,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"def predict_price(sqr_metres):\n",
|
|||
|
" return 2000* sqr_metres + 200000"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 13,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"240000"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 13,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"predict_price(20)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 14,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"280000"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 14,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"predict_price(40)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 15,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"310000"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 15,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"predict_price(55)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 16,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"200000"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 16,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"predict_price(0)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 17,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"Y_train_predicted = predict_price(X_train)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Mierzenie błędu"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/6.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/5.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Zadanie - napisać funkcję, która liczy błąd średniowadratowy na całym zbiorze (7 minut)\n",
|
|||
|
"\n",
|
|||
|
"rmse(Y_true, Y_predicted)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 18,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"def rmse(Y_true, Y_predicted):\n",
|
|||
|
" return np.sqrt(np.sum((Y_true - Y_predicted)**2)/ len(Y_true)) "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 19,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"0.0"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 19,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(np.array([300_000, 250_000]), np.array([300_000, 250_000]))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 20,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"70799.01129253148"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 20,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(np.array([305_000, 250_000]) ,np.array([300_000, 350_000]) )"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 21,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"80622.57748298549"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 21,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(np.array([300_000, 250_000]), np.array([330_000, 360_000]))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Zadanie - za pomocą rmse policzyć błąd dla baseline (3 minuty)\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 22,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"array([357461.18628244, 357461.18628244, 357461.18628244, ...,\n",
|
|||
|
" 357461.18628244, 357461.18628244, 357461.18628244])"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 22,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"np.ones_like(Y_train) * Y_train.mean()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 23,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"125698.71268014389"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 23,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_train, np.ones_like(Y_train) * Y_train.mean())"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Zadanie - za pomocą rmse policzyc błąd dla predykcji (2 minuty)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 24,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"123420.02227684396"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 24,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_train, Y_train_predicted)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Na jakim zbiorze najlepiej sprawdzać wyniki?\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/7.png)\n",
|
|||
|
"\n",
|
|||
|
"![a](obrazki/8.png)\n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 25,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mieszkania_dev = pd.read_csv(DATA_DIR/'dev-0'/'in.tsv', sep = '\\t', names = names)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 26,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"with open(DATA_DIR/'dev-0'/'expected.tsv','r') as dev_exp_f:\n",
|
|||
|
" Y_dev = np.array([float(x.rstrip('\\n')) for x in dev_exp_f.readlines()])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 27,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mieszkania_dev['price'] = Y_dev"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 28,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"X_dev = mieszkania_dev['sqrMetres'].to_numpy()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 29,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.axes._subplots.AxesSubplot at 0x7f25f7e3efd0>"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 29,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA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LLVSnp8r5buBY5vqrQCeLeUrZiifUici5gNHAhMt2poiM2/KzOHMHF66dOmsT1CSJKlXzEVw9y95bUkWYAswmb26Abi7qXx9yYAdopE48XBZut0XEaeW6+kumFZnsq3zgPvLdXn3AWdHxKKSSHF2KZMkSaq1Su8tGxGHAWcB/0tT8SeBzRGxEXgaOB8gM5+IiM3Ak8B+4JLMfLXUuRi4FVgA3FseADcDt0fELhozdutLWxMRcTXwSDnuqsycqOQkJUmSekg0Jro0PDyco6Oj3e6GJEnSQUXEo5k5PNNn3qFCkiSpRgzuJEmSasTgTpIkqUYM7iRJkmrE4E6SJKlGDO4kSZJqxOBOkiSpRgzupBbGnn+Jj9/9OGPPv9TtrkiS1BaDO6mFWx4c47aHnuKWB8e63RVJktpS6e3HpH534WlDU54lSep1BndSC0NLFnLVupO63Q1JktrmsqwkSVKNGNxJkiTViMGdJElSjRjcSZIk1YjBnSRJUo0Y3EmSJNWIwZ0kSVKNGNxJkiTViMGdJElSjRjcSZIk1YjBnSRJUo1UGtxFxNsi4q6I+KuI2B4RH4iIxRExEhE7y/OipuMvj4hdEbEjItY0lZ8cEY+Vz66PiCjlh0bEnaV8W0SsbKqzoXzHzojYUOV5SpIk9YqqZ+4+BfxpZv448B5gO3AZsDUzVwFby3si4gRgPXAisBa4ISLmlXZuBC4CVpXH2lK+EXghM98FXAdcW9paDFwJnAKsBq5sDiIlSZLqqrLgLiKOAM4AbgbIzH/MzO8A64BN5bBNwLnl9Trgjsx8OTPHgF3A6og4BjgiMx/KzARum1Znsq27gDPLrN4aYCQzJzL
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 720x360 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sns.scatterplot(x='sqrMetres',y='price', data = mieszkania_dev, linewidth = 0, s = 5)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Zadanie - policzyć rmse dla predykcji ze zbioru deweloperskiego modelu baseline i naszego modelu regresji liniowej"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 30,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"Y_dev_predicted = predict_price(X_dev)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 34,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"117309.3154367544"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 34,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_dev, np.ones_like(Y_dev) * Y_dev.mean())"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 35,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"104227.56492755697"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 35,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_dev, Y_dev_predicted)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Przypadek wielowymiarowy"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 36,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.axes._subplots.AxesSubplot at 0x7f25f7d67e20>"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 36,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmEAAAFICAYAAAAYvikoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3dfXzV5Z3n//cnIcEI4UaFqEQBBSIIiiW9oY53LXizMKWO9few0ymubddVpuNNZ/prZ2Fsh4Wddme36vxa9eHP1epvZrVlbKUFrUJHK4u0NRSsQBpAkBKREOUuQCAhuX5/nJPZfOlBcNZzfQ5cr+fj4eOTnHPMdX3PCTmfc918LgshCAAAAHGVeXcAAAAgRSRhAAAADkjCAAAAHJCEAQAAOCAJAwAAcEASBgAA4OCETMLM7FEz22Fma47z8f+Xma0zs7Vm9j+L3T8AAIBjsROxTpiZXS5pn6QnQgjjj/HY0ZJ+KOkTIYRdZjY0hLAjRj8BAACO5oQcCQshvCxpZ+/bzOx8M/uZma00s2VmdkH+rv8g6XshhF35/5cEDAAAuDshk7CjeFjSX4QQJkn6K0kP5G8fI2mMmS03s1+a2bVuPQQAAMjr492BD4KZ9Zf0cUkLzKzn5r752EfSaElXSqqVtMzMxocQdsfuJwAAQI+TIglTbkRvdwhhYoH7miX9MoTQKWmzmTUpl5S9GrODAAAAvZ0U05EhhL3KJVg3SpLlXJy/+xlJV+VvP0O56clNLh0FAADIOyGTMDN7UtIKSXVm1mxmX5T0OUlfNLPXJK2VNCP/8OclvWtm6yS9KOmrIYR3PfoNAADQ44QsUQEAAHCiOyFHwgAAAE50JGEAAAAOTrjdkWeccUYYMWKEdzcAA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ByIsLuRAAA4mBNWAHzF6/T0sYd2ra7XY/c/GHv7kTFmjQAAOJgJKyAN3bsz8SUjDyjn+bOGO9SHgPpWrahVdfc+7KWbWj17goAREMSVsDcT1+ouppqzf30hd5dAZIwb1GjmlraNG9Ro3dXACAakrACLhs9RM/ffTkFO4FI5kwfq7qaasqDAEgKa8IAuMt98OFDD4C0MBIGAADggCSsgJRLVAAAgDhIwgqgVhYAACg21oQVQK0sIK7N7+zXY8s365ZLR1IeBUAyGAkrwLNWFlOhSBGjzwBSRBJWYrzfjLyLZpKEpumWS0dq5uThjD4DSApJWInxfjPyLprpnYQCABALSViJ8T42aMbEs1VZXqYZE892ad87CYUPkm8AKWJhPjIWrt6mjq5uLVy9TbOuGhW9/Z4kFGlhMwyAFDESVmK810R96bKRGlRVoS9dlt6bofdznzLvEWAA8EASVmLuX7peT6zYovuXrndp//W39mh3e6def2uPS/uemBIDAMREElaA54jIvkOHMzG2lNdkeV+7985UAEBcJGEFeI6I9O/bJxNjS3layPvavXemAgDiYmF+AZ6LhO+cMkYDqiqSHIlK3ZzpYzVvUaPmTB/r3RUAQAQWQvDuw/tSX18fGhoavLsBAABwTGa2MoRQX+g+piMBAAAckIQBAAA4IAlDSaFWFwAgFSRhKCnU6gIApILdkSgpHF8DAEgFI2EFMCUGAACKjSSsAKbE/Hg+91SsBwDERBJWgPfxNSmbOq5GdTXVmjquJnrbf/3062pqadNfP/169LYlRmA98dwD8EAShpKyZF2LmlratGRdS/S2D3d3Z2JsjMD64bkH4IGF+QXcv3S9nlm9TXvbO3XfTZd4dycpngvzxw8bqO17d2j8sIHR25bYlOCJ5x6AB5IwZGx+Z78eW75Zt1w6MrlDvGdPG6ezB1W5vRH3HCCO+HjuAXggCSsg5UO0e6ZlJLm8Kc1fvE5LG3do2+52PXLzh6O2zRuxn5S
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 720x360 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sns.scatterplot(x='floor',y='price', data = mieszkania_train, linewidth = 0, s = 5)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"$Y = w_1 * X_1 + w_2 * X_1 + w_3 * X_3 + w_0$"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Zadanie. Napisać analogiczną funkcję predict_price(sqr_metres, floor), policzyć rmse dla takiego modelu ( 7 minut)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 37,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"def predict_price(sqr_metres, floor):\n",
|
|||
|
" return 4000* sqr_metres + (-1000)* floor + 100000"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 38,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"298000"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 38,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"predict_price(50, 2)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 39,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"295000"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 39,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"predict_price(50, 5)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 40,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"Y_dev_predicted = predict_price(mieszkania_dev['sqrMetres'], mieszkania_dev['floor'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 1,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"ename": "NameError",
|
|||
|
"evalue": "name 'rmse' is not defined",
|
|||
|
"output_type": "error",
|
|||
|
"traceback": [
|
|||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|||
|
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
|||
|
"\u001b[0;32m<ipython-input-1-090db4c912bf>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mrmse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mY_dev\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mY_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
|||
|
"\u001b[0;31mNameError\u001b[0m: name 'rmse' is not defined"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_dev, np.mean(Y_train))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 42,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"100227.89896326358"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 42,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_dev, Y_dev_predicted)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## jak dobrać najlepsze parametry?"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 43,
|
|||
|
"metadata": {
|
|||
|
"scrolled": true
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<seaborn.axisgrid.FacetGrid at 0x7f25f7cdd8e0>"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 43,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWAAAAFgCAYAAACFYaNMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9eZQk1X3n+72x5FaZWXt19Qpd9FIIBFILSbSmjYsWGiF5Bj2/w5PBfvaTLAZ07HFj2dITnsPIftieESMdIdqWRfN4HrzMgOUeWzAjhOxWUzRtdUugRiAaqheqt+qt9qzcY7vvjxsRFRkZmRmZlVmVmXU/R5xW5RIZERn5i9/9Ld8foZSCw+FwOMuPsNI7wOFwOKsVboA5HA5nheAGmMPhcFYIboA5HA5nheAGmMPhcFYIboA5HA5nhWhJA0wI+UtCyCQh5C2fr/80IeRtQshxQsh/b/T+cTgcjh9IK9YBE0JuA5AC8NeU0hsrvHYrgO8A2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Y2owVr4JYNnhWubnYe+AkbvqjH+C6//ACbvqjH2DvgZMrvUsFtNP10k7Hshppi1ZkLh/YPOw9cBKPHzwNgQCSwJJLjx88DQDYc8e2Fd47RjtdL+10LJVox1BLW3jAPKvcPDx1+IxpfAUIRDD/ZY83C+10vbTTsZSjXWUt28IA86xy85BWdAiu6JdA2OPNQjtdL+10LOVo11BLWxhgLh/YPHQERBiuvK5B2ePNQjtdL+10LOVo1+aVtogBA+0lH9jKsa77dm3G4wdPQzMMCIQZX4Oyx5uJUtdLK577drr2S9GuspZ
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 360x360 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"sns.lmplot(x='sqrMetres',y='price', data = mieszkania_train)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 56,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"lm_model = LinearRegression()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 57,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"LinearRegression()"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 57,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"lm_model.fit(mieszkania_train[['isNew','rooms', 'floor', 'sqrMetres']], Y_train)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 58,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"Y_train_predicted = lm_model.predict(mieszkania_train[['isNew','rooms', 'floor', 'sqrMetres']])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 59,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"103308.92502763818"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 59,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_train, Y_train_predicted)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 60,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"Y_dev_predicted = lm_model.predict(mieszkania_dev[['isNew','rooms', 'floor', 'sqrMetres']])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 61,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"84157.8788905739"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 61,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"rmse(Y_dev, Y_dev_predicted)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 62,
|
|||
|
"metadata": {
|
|||
|
"scrolled": true
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"array([469449.27836213])"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 62,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"lm_model.predict(np.array(([[0, 4, 3, 70]])))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 63,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"array([455982.54297977])"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 63,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"lm_model.predict(np.array(([[0, 4, 3, 60]])))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 64,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"array([ 4522.65059749, 73763.4125433 , -78.83243119, 1346.67353824])"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 64,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"lm_model.coef_"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 65,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"80364.97780599032"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 65,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"lm_model.intercept_"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 66,
|
|||
|
"metadata": {
|
|||
|
"scrolled": true
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"455982.5429800203"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 66,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"0 * 4522.65059749 + 4* 73763.4125433 + 3 * (-78.83243119) + 60 * 1346.67353824 + 80364.97780599032"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 67,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"with open(DATA_DIR/'dev-0'/'out.tsv','w') as f_out_file:\n",
|
|||
|
" for line in Y_dev_predicted:\n",
|
|||
|
" f_out_file.write(str(line))\n",
|
|||
|
" f_out_file.write('\\n')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Uwaga - regresja linowa działa dobrze tylko dla danych, gdzie występuje korelacja liniowa"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"![a](obrazki/9.png)\n",
|
|||
|
"\n",
|
|||
|
"![a](obrazki/10.png)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Zadanie domowe\n",
|
|||
|
"Zadanie domowe, proszę wybrać jedno z dwóch:\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"- sforkować repozytorium <https://git.wmi.amu.edu.pl/kubapok/auta-public>\n",
|
|||
|
"- Opis zadadania znajduje się w README.md\n",
|
|||
|
"- stworzyć model regresji liniowej dla tego zbioru (można użyć gotowych bibliotek)\n",
|
|||
|
"- dodać skrypty z rozwiązaniem oraz predykcje dla dev-0 i test-A i sprawdzić czy ewaluacja jest poprawna za pomocą geval\n",
|
|||
|
"- wynik zaliczający to max 50_000 RMSE dla dev-0\n",
|
|||
|
"- termin 18.05, 50 punktów,Zadanie proszę oddać w MS TEAMS umieszczając link do repo (repo powinno mieć uprawnienia do odczytu dla użytkownika kubapok lub być publiczne).\n",
|
|||
|
"- punkty: 40, dla 3 najlepszych wyników na test-A: 70\n",
|
|||
|
"\n",
|
|||
|
"LUB:\n",
|
|||
|
"\n",
|
|||
|
"analogicznie dla <https://git.wmi.amu.edu.pl/kubapok/retroc2>\n",
|
|||
|
"- należy użyć wektoryzacji (np tf-dif)\n",
|
|||
|
"- wynik zaliczający to max 50 RMSE dla dev-0 \n",
|
|||
|
"- punkty: 60, dla 3 najlepszych wyników na test-A: 80,"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"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",
|
|||
|
"version": "3.8.5"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 4
|
|||
|
}
|