diff --git a/lab_3/lab_3.ipynb b/lab_3/lab_3.ipynb index 3d1e394..cef3df6 100644 --- a/lab_3/lab_3.ipynb +++ b/lab_3/lab_3.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 106, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -15,7 +15,7 @@ " dtype='object')" ] }, - "execution_count": 106, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -99,7 +99,7 @@ "dtype: bool" ] }, - "execution_count": 107, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -131,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -212,7 +212,7 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -247,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -319,7 +319,7 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -366,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -403,7 +403,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -776,7 +776,7 @@ "[2000 rows x 26 columns]" ] }, - "execution_count": 113, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -798,7 +798,7 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -820,14 +820,14 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "d:\\Study\\3 курс 5 семестр\\AIM\\AIM-PIbd-31-Yakovlev-M-G\\kernel\\Lib\\site-packages\\featuretools\\synthesis\\deep_feature_synthesis.py:169: UserWarning: Only one dataframe in entityset, changing max_depth to 1 since deeper features cannot be created\n", + "d:\\Study\\AIM-PIbd-31-Yakovlev-M-G\\kernel\\Lib\\site-packages\\featuretools\\synthesis\\deep_feature_synthesis.py:169: UserWarning: Only one dataframe in entityset, changing max_depth to 1 since deeper features cannot be created\n", " warnings.warn(\n" ] }, @@ -1243,7 +1243,7 @@ "[6362 rows x 28 columns]" ] }, - "execution_count": 115, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -1265,6 +1265,77 @@ "\n", "feature_matrix" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Оценка качества" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Время обучения: 0.27 секунд\n", + "MSE: 2205809457.9675403\n", + "RMSE: 46966.04579872081\n", + "R²: 0.9623494755346685\n", + "MAE: 35440.813340503635 \n", + "\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "d:\\Study\\AIM-PIbd-31-Yakovlev-M-G\\kernel\\Lib\\site-packages\\sklearn\\metrics\\_regression.py:492: FutureWarning: 'squared' is deprecated in version 1.4 and will be removed in 1.6. To calculate the root mean squared error, use the function'root_mean_squared_error'.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "import time\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.linear_model import LinearRegression\n", + "from sklearn.metrics import mean_squared_error\n", + "from sklearn.metrics import r2_score, mean_absolute_error\n", + "from sklearn.model_selection import cross_val_score\n", + "\n", + "X = feature_matrix.drop('price', axis=1)\n", + "y = feature_matrix['price']\n", + "\n", + "#Делим на выборки\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", + "\n", + "#Начнем обучение\n", + "model = LinearRegression()\n", + "start_time = time.time()\n", + "model.fit(X_train, y_train)\n", + "\n", + "train_time = time.time() - start_time\n", + "\n", + "#Вычесляем показательную способность\n", + "y_pred = model.predict(X_test)\n", + "mse = mean_squared_error(y_test, y_pred)\n", + "rmse = mean_squared_error(y_test, y_pred, squared=False)\n", + "r2 = r2_score(y_test, y_pred)\n", + "mae = mean_absolute_error(y_test, y_pred)\n", + "\n", + "print()\n", + "print(f\"Время обучения: {train_time:.2f} секунд\")\n", + "print(\"Метрики:\")\n", + "print(f\"MSE: {mse}\")\n", + "print(f\"RMSE: {rmse}\")\n", + "print(f\"R²: {r2}\")\n", + "print(f\"MAE: {mae} \\n\")" + ] } ], "metadata": {