AIM-PIbd-31-Ievlewa-M-D/lab3/lab3.ipynb

2297 lines
652 KiB
Plaintext
Raw Normal View History

2024-11-09 10:31:35 +04:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Датасет: Цены на акции\n",
"https://www.kaggle.com/datasets/nancyalaswad90/yamana-gold-inc-stock-Volume\n",
"##### О наборе данных: \n",
"Yamana Gold Inc. — это канадская компания, которая занимается разработкой и управлением золотыми, серебряными и медными рудниками, расположенными в Канаде, Чили, Бразилии и Аргентине. Головной офис компании находится в Торонто.\n",
"\n",
"Yamana Gold была основана в 1994 году и уже через год была зарегистрирована на фондовой бирже Торонто. В 2007 году она стала участником Нью-Йоркской фондовой биржи, а в 2020 году — Лондонской.\n",
"В 2003 году компания претерпела значительные изменения: была проведена реструктуризация, в результате которой Питер Марроне занял пост главного исполнительного директора. Кроме того, Yamana объединилась с бразильской компанией Santa Elina Mines Corporation. Благодаря этому слиянию Yamana получила доступ к капиталу, накопленному Santa Elina, что позволило ей начать разработку и эксплуатацию рудника Чапада. Затем компания объединилась с другими организациями, зарегистрированными на бирже TSX: RNC Gold, Desert Sun Mining, Viceroy Exploration, Northern Orion Resources, Meridian Gold, Osisko Mining и Extorre Gold Mines. Каждая из них внесла свой вклад в разработку месторождения или проект, который в итоге был успешно запущен.\n",
"##### Таким образом:\n",
"* Объект наблюдения - цены и объемы акций компании\n",
"* Атрибуты: 'Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'\n",
"\n",
"##### Бизнес цели:\n",
"* Прогнозирование будущей цены акций.\n",
" Использование данных для создания модели, которая будет предсказывать цену акций компании в будущем.\n",
"* Определение волатильности акций.\n",
" Определение, колебаний цен акций, что поможет инвесторам понять риски.\n",
"\n",
"##### Технические цели:\n",
"* Разработать модель машинного обучения для прогноза цены акций на основе имеющихся данных.\n",
"* Разработать метрику и модель для оценки волатильности акций на основе исторических данных."
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 71,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Количество колонок: 7\n",
"Колонки: Date, Open, High, Low, Close, Adj Close, Volume\n",
"\n",
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 5251 entries, 0 to 5250\n",
"Data columns (total 7 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Date 5251 non-null datetime64[ns]\n",
" 1 Open 5251 non-null float64 \n",
" 2 High 5251 non-null float64 \n",
" 3 Low 5251 non-null float64 \n",
" 4 Close 5251 non-null float64 \n",
" 5 Adj Close 5251 non-null float64 \n",
" 6 Volume 5251 non-null int64 \n",
"dtypes: datetime64[ns](1), float64(5), int64(1)\n",
"memory usage: 287.3 KB\n"
]
},
{
"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>Date</th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Adj Close</th>\n",
" <th>Volume</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2001-06-22</td>\n",
" <td>3.428571</td>\n",
" <td>3.428571</td>\n",
" <td>3.428571</td>\n",
" <td>3.428571</td>\n",
" <td>2.806002</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2001-06-25</td>\n",
" <td>3.428571</td>\n",
" <td>3.428571</td>\n",
" <td>3.428571</td>\n",
" <td>3.428571</td>\n",
" <td>2.806002</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2001-06-26</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.039837</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2001-06-27</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.039837</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2001-06-28</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.714286</td>\n",
" <td>3.039837</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Date Open High Low Close Adj Close Volume\n",
"0 2001-06-22 3.428571 3.428571 3.428571 3.428571 2.806002 0\n",
"1 2001-06-25 3.428571 3.428571 3.428571 3.428571 2.806002 0\n",
"2 2001-06-26 3.714286 3.714286 3.714286 3.714286 3.039837 0\n",
"3 2001-06-27 3.714286 3.714286 3.714286 3.714286 3.039837 0\n",
"4 2001-06-28 3.714286 3.714286 3.714286 3.714286 3.039837 0"
]
},
2024-11-09 11:41:45 +04:00
"execution_count": 71,
2024-11-09 10:31:35 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_csv(\".//static//csv//Stocks.csv\", sep=\",\")\n",
"print('Количество колонок: ' + str(df.columns.size)) \n",
"print('Колонки: ' + ', '.join(df.columns)+'\\n')\n",
"df['Date'] = pd.to_datetime(df['Date'], errors='coerce')\n",
"\n",
"df.info()\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Подготовка данных:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1. Получение сведений о пропущенных данных\n",
"Типы пропущенных данных:\n",
"\n",
"- None - представление пустых данных в Python\n",
"- NaN - представление пустых данных в Pandas\n",
"- '' - пустая строка"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 72,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Date 0\n",
"Open 0\n",
"High 0\n",
"Low 0\n",
"Close 0\n",
"Adj Close 0\n",
"Volume 0\n",
"dtype: int64\n",
"\n",
"Date False\n",
"Open False\n",
"High False\n",
"Low False\n",
"Close False\n",
"Adj Close False\n",
"Volume False\n",
"dtype: bool\n",
"\n",
"Количество бесконечных значений в каждом столбце:\n",
"Date 0\n",
"Open 0\n",
"High 0\n",
"Low 0\n",
"Close 0\n",
"Adj Close 0\n",
"Volume 0\n",
"dtype: int64\n",
"Date процент пустых значений: %0.00\n",
"Open процент пустых значений: %0.00\n",
"High процент пустых значений: %0.00\n",
"Low процент пустых значений: %0.00\n",
"Close процент пустых значений: %0.00\n",
"Adj Close процент пустых значений: %0.00\n",
"Volume процент пустых значений: %0.00\n"
]
}
],
"source": [
"import numpy as np\n",
"# Количество пустых значений признаков\n",
"print(df.isnull().sum())\n",
"print()\n",
"\n",
"# Есть ли пустые значения признаков\n",
"print(df.isnull().any())\n",
"print()\n",
"\n",
"# Проверка на бесконечные значения\n",
"print(\"Количество бесконечных значений в каждом столбце:\")\n",
"print(np.isinf(df).sum())\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in df.columns:\n",
" null_rate = df[i].isnull().sum() / len(df) * 100\n",
" print(f\"{i} процент пустых значений: %{null_rate:.2f}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Таким образом, пропущенных значений не найдено."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2. Проверка выбросов данных и устранение их при наличии:"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 73,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"До устранения выбросов:\n",
"Колонка Open:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.42\n",
" 1-й квартиль (Q1): 2.857143\n",
" 3-й квартиль (Q3): 10.65\n",
"\n",
"После устранения выбросов:\n",
"Колонка Open:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.42\n",
" 1-й квартиль (Q1): 2.857143\n",
" 3-й квартиль (Q3): 10.65\n",
"\n",
"До устранения выбросов:\n",
"Колонка High:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.59\n",
" 1-й квартиль (Q1): 2.88\n",
" 3-й квартиль (Q3): 10.86\n",
"\n",
"После устранения выбросов:\n",
"Колонка High:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.59\n",
" 1-й квартиль (Q1): 2.88\n",
" 3-й квартиль (Q3): 10.86\n",
"\n",
"До устранения выбросов:\n",
"Колонка Low:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.09\n",
" 1-й квартиль (Q1): 2.81\n",
" 3-й квартиль (Q3): 10.425\n",
"\n",
"После устранения выбросов:\n",
"Колонка Low:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.09\n",
" 1-й квартиль (Q1): 2.81\n",
" 3-й квартиль (Q3): 10.425\n",
"\n",
"До устранения выбросов:\n",
"Колонка Close:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.389999\n",
" 1-й квартиль (Q1): 2.857143\n",
" 3-й квартиль (Q3): 10.64\n",
"\n",
"После устранения выбросов:\n",
"Колонка Close:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 1.142857\n",
" Максимальное значение: 20.389999\n",
" 1-й квартиль (Q1): 2.857143\n",
" 3-й квартиль (Q3): 10.64\n",
"\n",
"До устранения выбросов:\n",
"Колонка Adj Close:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 0.935334\n",
" Максимальное значение: 17.543156\n",
" 1-й квартиль (Q1): 2.537094\n",
" 3-й квартиль (Q3): 8.951944999999998\n",
"\n",
"После устранения выбросов:\n",
"Колонка Adj Close:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 0.935334\n",
" Максимальное значение: 17.543156\n",
" 1-й квартиль (Q1): 2.537094\n",
" 3-й квартиль (Q3): 8.951944999999998\n",
"\n",
"До устранения выбросов:\n",
"Колонка Volume:\n",
" Есть выбросы: Да\n",
" Количество выбросов: 95\n",
" Минимальное значение: 0\n",
" Максимальное значение: 76714000\n",
" 1-й квартиль (Q1): 2845900.0\n",
" 3-й квартиль (Q3): 13272450.0\n",
"\n",
"После устранения выбросов:\n",
"Колонка Volume:\n",
" Есть выбросы: Нет\n",
" Количество выбросов: 0\n",
" Минимальное значение: 0.0\n",
" Максимальное значение: 28912275.0\n",
" 1-й квартиль (Q1): 2845900.0\n",
" 3-й квартиль (Q3): 13272450.0\n",
"\n"
]
}
],
"source": [
"numeric_columns = ['Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume']\n",
"\n",
"for column in numeric_columns:\n",
" if pd.api.types.is_numeric_dtype(df[column]): # Проверяем, является ли колонка числовой\n",
" q1 = df[column].quantile(0.25) # Находим 1-й квартиль (Q1)\n",
" q3 = df[column].quantile(0.75) # Находим 3-й квартиль (Q3)\n",
" iqr = q3 - q1 # Вычисляем межквартильный размах (IQR)\n",
"\n",
" # Определяем границы для выбросов\n",
" lower_bound = q1 - 1.5 * iqr # Нижняя граница\n",
" upper_bound = q3 + 1.5 * iqr # Верхняя граница\n",
"\n",
" # Подсчитываем количество выбросов\n",
" outliers = df[(df[column] < lower_bound) | (df[column] > upper_bound)]\n",
" outlier_count = outliers.shape[0]\n",
"\n",
" print(\"До устранения выбросов:\")\n",
" print(f\"Колонка {column}:\")\n",
" print(f\" Есть выбросы: {'Да' if outlier_count > 0 else 'Нет'}\")\n",
" print(f\" Количество выбросов: {outlier_count}\")\n",
" print(f\" Минимальное значение: {df[column].min()}\")\n",
" print(f\" Максимальное значение: {df[column].max()}\")\n",
" print(f\" 1-й квартиль (Q1): {q1}\")\n",
" print(f\" 3-й квартиль (Q3): {q3}\\n\")\n",
"\n",
" # Устраняем выбросы: заменяем значения ниже нижней границы на саму нижнюю границу, а выше верхней — на верхнюю\n",
" if outlier_count != 0:\n",
" df[column] = df[column].apply(lambda x: lower_bound if x < lower_bound else upper_bound if x > upper_bound else x)\n",
" \n",
" # Подсчитываем количество выбросов\n",
" outliers = df[(df[column] < lower_bound) | (df[column] > upper_bound)]\n",
" outlier_count = outliers.shape[0]\n",
"\n",
" print(\"После устранения выбросов:\")\n",
" print(f\"Колонка {column}:\")\n",
" print(f\" Есть выбросы: {'Да' if outlier_count > 0 else 'Нет'}\")\n",
" print(f\" Количество выбросов: {outlier_count}\")\n",
" print(f\" Минимальное значение: {df[column].min()}\")\n",
" print(f\" Максимальное значение: {df[column].max()}\")\n",
" print(f\" 1-й квартиль (Q1): {q1}\")\n",
" print(f\" 3-й квартиль (Q3): {q3}\\n\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Выбросы присутствовали, но мы их устранили."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Разбиение на выборки:\n",
"\n",
"Разобьем наш набор на обучающую, контрольную и тестовую выборки для устранения проблемы просачивания данных."
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 74,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Размер обучающей выборки: 4200\n",
"Размер контрольной выборки: 1051\n",
"Размер тестовой выборки: 1051\n"
]
}
],
"source": [
"from sklearn.model_selection import train_test_split\n",
"\n",
"# Разделение данных на обучающую и тестовую выборки (80% - обучение, 20% - тестовая)\n",
"X_train, X_test = train_test_split(df, test_size=0.2, random_state=42)\n",
"\n",
"# Разделение данных на обучающую и контрольную выборки (80% - обучение, 20% - контроль)\n",
"X_train, X_val = train_test_split(df, test_size=0.2, random_state=42)\n",
"\n",
"print(\"Размер обучающей выборки: \", len(X_train))\n",
"print(\"Размер контрольной выборки: \", len(X_test))\n",
"print(\"Размер тестовой выборки: \", len(X_val))\n"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 75,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA+0AAAIjCAYAAAB20vpjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABeK0lEQVR4nO3dd3gU1eL/8U8CaRASSkgDAqGGXiIlIEVAQlEEohRBQVC8EJSmIipdRUClKIJ4KRYUwYKKgoSqYqgCgpSL3mBQkuDCTQKkQub3B9/sjyUJkJDsTuD9ep59ZGfOnHNmZmfjZ2fmjJNhGIYAAAAAAIDpODu6AwAAAAAAIHeEdgAAAAAATIrQDgAAAACASRHaAQAAAAAwKUI7AAAAAAAmRWgHAAAAAMCkCO0AAAAAAJgUoR0AAAAAAJMq6egOAAAAFHdpaWk6d+6cSpYsKV9fX0d3BwBwG+FMOwAAKHZGjhype++916F92LRpk3r27KmyZcvKw8NDlSpV0ujRox3aJxSuDRs2yNPTU//884+juwLgDkZoB4AisGLFCjk5OVlf7u7uql27tkaNGqWEhARHdw8o1mJiYvTvf/9bL7zwgsP68M477yg8PFxJSUmaP3++oqKiFBUVpenTpzusTyh8Xbt2Vc2aN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V2rVr9dBDDyk4OFgJCQl699131b59ex05ckSBgYGSpMuXL+u+++7T5s2b1b9/f40ePVrnz59XVFSUDh8+rBo1aljbGDBggLp3727T7sSJE3PtzyuvvCInJydNmDBBZ86c0bx589S5c2cdOHBAHh4ekqQtW7aoW7duCg0N1ZQpU+Ts7Kzly5erY8eO+vHHH9WiRYsc9VauXNl6D+iFCxc0YsSIXNueNGmS+vbtq8cff1z//POP3nrrLbVr10779+9X2bJlcywzfPhwtW3bVpL0xRdf6Msvv7SZ/+STT1pvTXj66acVExOjt99+W/v379eOHTvk4uKS63bIj8TExFzvb83KylLPnj31008/afjw4apbt64OHTqkuXPn6j//+Y/Wrl2br3aWL1+ul156SW+88YYefvjhXMvcaHvMnz9fPXv21MCBA5WRkaFVq1bpoYce0rp169SjRw9ruWnTpmnq1Klq3bq1pk+fLldXV+3atUtbtmxRly5dJF0JlEOHDlX9+vU1ceJElS1bVvv379eGDRus/cve9s2bN9fMmTOVkJCg+fPna8eOHTn2qY+Pj+bOnStJ+uuvvzR//nx1795dp06dynXfZ/v555/l5OSkpk2bXnf7LVq0SJ6enpJy//znp6/XOnv2rPbu3auSJUsqMjJSNWrU0Nq1azV8+HCdPXtWzz//fL73wdXmzp0rHx8fSVeOk6vd7HdGfly4cEFt27bV0aNHNXToUDVr1kwWi0Vff/21/vrrL2tfrvXDDz/ou+++y7Pevn37qlq1apo5c6Z27typBQsW6H//+58++OADa5nHH39c77//vh588EGNHz9eu3bt0syZM3X06NEcn+e2bdtq+PDhysrK0uHDhzVv3jydPn06zx97MjMzFRERodjYWO3YsUMBAQF59vX333/P9UeXbKGhofk+hgGg0BgAgEK3fPlyQ5KxadMm459//jFOnTplrFq1yqhQoYLh4eFh/PXXX4ZhGEZaWppx+fJlm2VjYmIMNzc3Y/r06dZpy5YtMyQZb775Zo62srKyrMtJMubMmZOjTP369Y327dtb32/dutWQZFSqVMlITk62Tl+9erUhyZg/f7617lq1ahnh4eHWdgzDMFJSUozg4GDj3nvvzdFW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716dOXNGI0eOtCnTo0cPhYSE6Ntvv7VZLisry7qNDhw
"text/plain": [
"<Figure size 1200x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA+0AAAIjCAYAAAB20vpjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABbsElEQVR4nO3deVyVZf7/8ffBBVEWRWRTEFxx3FJKBsvdUnQ0y3KfNE2d1MqlMm1MsRo0K7dMcya1xTItM6cmy30Lzd0c0VEHoxJUdABFZZH794dfzs/jARSCc27k9Xw8zqPOfV/3dX3OfXMffHNvFsMwDAEAAAAAANNxcXYBAAAAAAAgb4R2AAAAAABMitAOAAAAAIBJEdoBAAAAADApQjsAAAAAACZFaAcAAAAAwKQI7QAAAAAAmBShHQAAAAAAkyrv7AIAAABKu2vXrunixYsqX768fH19nV0OAOAuwpF2AABQ6owaNUoPPvigU2vYsGGDevbsqapVq8rNzU01a9bUc88959SaULzWrVsnd3d3nT9/3tmlACjDCO0AUAKWLVsmi8VifVWqVEkNGjTQmDFjdPbsWWeXB5Rq8fHx+sc//qHJkyc7rYZ3331XXbp0UWpqqubOnav169dr/fr1mj59utNqQvHr2rWr6tWrp5iYGGeXAqAMsxiGYTi7CAC42yxbtkxPPvmkpk+frtDQUF27dk07duzQRx99pNq1a+vIkSOqXLmys8sESqWxY8fq22+/1fHjx50y/okTJ9S0aVM9+eSTevfdd2WxWJxSBxxj4cKFev7555WUlCQPDw9nlwOgDOJIOwCUoKioKA0aNEhPPfWUli1bprFjxyo+Pl5fffWVs0sDSqWsrCwtX75cffr0cVoN8+bNk7+/v+bNm0dgLwN69+6tjIwMrVq1ytmlACijCO0A4EAdO3aUdOP0Xkm6ePGinn/+eTVt2lTu7u7y9PRUVFSUDh06ZLfstWvXNG3aNDVo0ECVKlVSQECAHn30UZ06dUqSdPr0aZtT8m99tW/f3trXli1bZLFY9Nlnn2ny5Mny9/dXlSpV1LNnT/3yyy92Y+/evVtdu3aVl5eXKleurHbt2mnnzp15fsb27dvnOf60adPs2n788ccKDw+Xm5ubvL291a9fvzzHL+iz3SwnJ0dz5sxR48aNValSJfn5+WnkyJH63//+Z9MuJCREf/rTn+zGGTNmjF2fedU+a9Ysu3UqSRkZGZo6darq1asnV1dXBQUF6cUXX1RGRkae6+pm7du3t+vv9ddfl4uLiz755JMirY8333xTrVu3VvXq1eXm5qbw8HB9/vnneY7/8ccfq1WrVqpcubKqVaumtm3b6vvvv7dp8+2336pdu3by8PCQp6en7rvvPrvaVq1aZd2mPj4+GjRokH777TebNkOGDLGpuVq1amrfvr22b99+2/W0Y8cOJScnq3PnznnOnzZt2m1//gtTa1527dql8PBwjRo1Sn5+fnJ1dVWTJk3097//3a5tYbbBrZfV5FX7nX5n5O7jeY3l7u6uIUOG2ExLSUnRuHHjFBISIldXV9WqVUtPPPGEkpOTbfrbsmWLzXLdu3e320dyt8GxY8fUp08feXp6qnr16nruued07do1m+Wzs7P16quvqm7dunJ1dVVISIgmT55st8+EhIRY14eLi4v8/f3Vt29fJSQkWNvk7hfLli2zTrt06ZLCw8MVGhqqxMTEfNtJ0ujRo2WxWOzWja+vr5o1a8YfWwE4DXePBwAHyg3Y1atXlyT997//1Zo1a/T4448rNDRUZ8+e1Xvvvad27drp6NGjCgwMlCRdv35df/rTn7Rx40b169dPzz33nC5duqT169fryJEjqlu3rnWM/v37q1u3bjbjTpo0Kc96Xn/9dVksFk2cOFHnzp3TnDlz1LlzZx08eFBubm6SpE2bNikqKkrh4eGaOnWqXFxctHTpUnXs2FHbt29Xq1at7PqtVauW9RrQy5cv6+mnn85z7ClTpqhPnz566qmndP78ec2fP19t27bVgQMHVLVqVbtlRowYoTZt2kiSVq9erS+//NJm/siRI62XJjz77LOKj4/XO++8owMHDmjnzp2qUKFCnuuhMFJSUvK8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wUbt2bZt+Fi9ebEgyfvzxxzw/c65BgwYZ1atXz3f+5MmTDUlGcnKyddqtP/+FqTUvtWvXNiQZy5Yts07Lzs42OnXqZLi6utqMfSfbINff//53Q5Lx888/W6fd/HNhGHf+nZG7j69atcpunCpVqhiDBw+2vn/llVcMScbq1avt2uZu39z+Nm/ebJ0XERFhREVF2e0juT+LPXv2tOlr1KhRhiTj0KFDhmEYxsGDBw1JxlNPPWXT7vnnnzckGZs2bbJOq127tk3NhmEYAwYMMCpXrmyzHiQZS5cuNXJycoyBAwcalStXNnbv3m23vnLb5erTp4/RpEkTIygoyG4cwzCMv/3tb4Yk4+zZs3bzAKCkcXo8AJSgzp07q0aNGgoKClK/fv3k7u6uL7/8UjVr1pQkubq6ysXlxlfx9evXdeHCBbm7u6thw4bav3+/tZ8vvvhCPj4+euaZZ+zG+D3X1D7xxBM2N1Z67LHHFBAQYD16dvDgQZ04cUIDBgzQhQsXlJycrOTkZKWnp6tTp07atm2bcnJybPq8du2aKlWqVOC4q1evVk5Ojvr06WPtMzk5Wf7+/qpfv742b95s0z4zM1PSjfWVn1WrVsnLy0sPPvigTZ/h4eFyd3e36zMrK8umXXJyst2pu7f67bffNH/+fE2ZMsV6FPfm8Rs1aqSwsDCbPnMvibh1/Pz8+OOP6tOnj3r37q1Zs2bl2eZO1ock69kSkvS///1PqampatOmjc3P1po1a5STk6NXXnnF+rOYK/dna/369bp06ZJeeuklu22b22bv3r06d+6cRo0aZdOme/fuCgsL0zfffGOzXE5OjnUdHTx4UB9
"text/plain": [
"<Figure size 1200x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA+0AAAIjCAYAAAB20vpjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABbsElEQVR4nO3deVy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TrVu3VvXq1eXm5qbw8HB9/vnneY7/8ccfq1WrVqpcubKqVaumtm3b6vvvv7dp8+2336pdu3by8PCQp6en7rvvPrvaVq1aZd2mPj4+GjRokH777TebNkOGDLGpuVq1amrfvr22b99+2/W0Y8cOJScnq3PnznnOnzZt2m1//gtTa1527dql8PBwjRo1Sn5+fnJ1dVWTJk3097//3a5tYbbBrZfV5FX7nX5n5O7jeY3l7u6uIUOG2ExLSUnRuHHjFBISIldXV9WqVUtPPPGEkpOTbfrbsmWLzXLdu3e320dyt8GxY8fUp08feXp6qnr16nruued07do1m+Wzs7P16quvqm7dunJ1dVVISIgmT55st8+EhIRY14eLi4v8/f3Vt29fJSQkWNvk7hfLli2zTrt06ZLCw8MVGhqqxMTEfNtJ0ujRo2WxWOzWja+vr5o1a8YfWwE4DXePBwAHyg3Y1atXlyT997//1Zo1a/T4448rNDRUZ8+e1Xvvvad27drp6NGjCgwMlCRdv35df/rTn7Rx40b169dPzz33nC5duqT169fryJEjqlu3rnWM/v37q1u3bjbjTpo0Kc96Xn/9dVksFk2cOFHnzp3TnDlz1LlzZx08eFBubm6SpE2bNikqKkrh4eGaOnWqXFxctHTpUnXs2FHbt29Xq1at7PqtVauW9RrQy5cv6+mnn85z7ClTpqhPnz566qmndP78ec2fP19t27bVgQMHVLVqVbtlRowYoTZt2kiSVq9erS+//NJm/siRI62XJjz77LOKj4/XO++8owMHDmjnzp2qUKFCnuuhMFJSUvK8vjUnJ0c9e/bUjh07NGLECDVq1Eg//fSTZs+erf/85z9as2ZNocZZunSp/vrXv+qtt97SgAED8mxzu/Uxd+5c9ezZUwMHDlRmZqZWrFihxx9/XF9//bW6d+9ubRcdHa1p06apdevWmj59uipWrKjdu3dr06ZNeuihhyTdCJRDhw5V48aNNWnSJFWtWlUHDhzQunXrrPXlrvv77rtPMTExOnv2rObOnaudO3fabVMfHx/Nnj1bkvTrr79q7ty56tatm3755Zc8t32uH374QRaLRS1atChw/S1cuFDu7u6S8v75L0ytt7pw4YL27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StXNnbv3m23vnLb5erTp4/RpEkTIygoyG4cwzCMv/3tb4Yk4+zZs3bzAKCkcXo8AJSgzp07q0aNGgoKClK/fv3k7u6uL7/8UjVr1pQkubq6ysXlxlfx9evXdeHCBbm7u6thw4bav3+/tZ8vvvhCPj4+euaZZ+zG+D3X1D7xxBM2N1Z67LHHFBAQYD16dvDgQZ04cUIDBgzQhQsXlJycrOTkZKWnp6tTp07atm2bcnJybPq8du2aKlWqVOC4q1evVk5Ojvr06WPtMzk5Wf7+/qpfv742b95s0z4zM1PSjfWVn1WrVsnLy0sPPvigTZ/h4eFyd3e36zMrK8umXXJyst2pu7f67bffNH/+fE2ZMsV6FPfm8Rs1aqSwsDCbPnMvibh1/Pz8+OOP6tOnj3r37q1Zs2bl2eZO1ock69kSkvS///1PqampatOmjc3P1po1a5STk6NXXnnF+rOYK/dna/369bp06ZJeeuklu22b22bv3r06d+6cRo0aZdOme/fuCgsL0zfffGOzXE5OjnUdHTx4UB9
"text/plain": [
"<Figure size 1200x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Гистограмма распределения цены закрытия в обучающей выборке\n",
"plt.figure(figsize=(12, 6))\n",
"sns.histplot(X_train['Close'], bins=30, kde=False)\n",
"plt.title(\"Распределение классов (до балансировки)\")\n",
"plt.xlabel('Целевая переменная: Close')\n",
"plt.ylabel('Частота')\n",
"plt.show()\n",
"\n",
"# Гистограмма распределения цены закрытия в контрольной выборке\n",
"plt.figure(figsize=(12, 6))\n",
"sns.histplot(X_val['Close'], bins=30, kde=False)\n",
"plt.title(\"Распределение классов (до балансировки)\")\n",
"plt.xlabel('Целевая переменная: Close')\n",
"plt.ylabel('Частота')\n",
"plt.show()\n",
"\n",
"# Гистограмма распределения цены закрытия в тестовой выборке\n",
"plt.figure(figsize=(12, 6))\n",
"sns.histplot(X_test['Close'], bins=30, kde=False)\n",
"plt.title(\"Распределение классов (до балансировки)\")\n",
"plt.xlabel('Целевая переменная: Close')\n",
"plt.ylabel('Частота')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Применим овер- и андерсемплинг к обучающей выборке:"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 76,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Date Open High Low Close Adj Close Volume \\\n",
"4789 2020-07-08 5.66 5.73 5.47 5.560000 5.341250 23355100.0 \n",
"3469 2015-04-10 3.86 3.93 3.81 3.880000 3.513961 7605300.0 \n",
"2503 2011-06-07 12.19 12.28 11.95 12.020000 10.138681 7243200.0 \n",
"1580 2007-10-08 11.77 11.84 11.53 11.570000 9.509553 3025900.0 \n",
"2759 2012-06-12 15.77 16.17 15.76 16.120001 13.771020 6113400.0 \n",
"\n",
" closePrice_category \n",
"4789 high \n",
"3469 medium \n",
"2503 very_high \n",
"1580 very_high \n",
"2759 very_high \n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAn4AAAHHCAYAAAAh/VVAAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABc0UlEQVR4nO3dd1QU598F8LuAFKki0gwi9i4RjYIFoygKdiMWoliiRiXWqDGxYW+xK5bErrHGnqDYG3axi2gwEhURFRGU/rx/+O78GHZRJKtg5n7O2XPYmWdmvlN29jJtVUIIASIiIiL6z9PL7wKIiIiI6ONg8CMiIiJSCAY/IiIiIoVg8CMiIiJSCAY/IiIiIoVg8CMiIiJSCAY/IiIiIoVg8CMiIiJSCAY/IiKiPEhPT0dsbCzu37+f36WQjqWmpiImJgYPHz7M71J0jsGP6BOWmJiIuXPnSu/j4+OxaNGi/CuIPrp169bh3r170vtVq1bhwYMH+VfQf1xkZC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VCQoLUffPmzQKAmDdvnjTusmXLCm9vb2k6Qgjx6tUr4eLiIpo0aaIxLQ8PD1GlShXp/ZMnTwQAMW7cOKnbvXv3hL6+vpg8ebJs2KtXrwoDAwON7pGRkQKAWL16tdRt3LhxIusqO378uAAg1q9fLxs2JCREo7uzs7Pw9fXVqH3AgAEi+2aQvfYRI0YIW1tb4ebmJluma9euFXp6euL48eOy4ZcsWSIAiJMnT2pMLytPT09pfHv37hUGBgZi2LBhGu1evXq
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnEAAAHHCAYAAADQ9g7NAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABbuklEQVR4nO3dd1QU198G8GcB6U1EmsGGxl4iNrCAimKvEQuxi0Yl1lhIbNg1xq6oSazR2MWSSMTesIsVEQ0qURFREMRQhPv+4cv8GHZBQBRGn885ew57587Md3Z2Zx+mrUoIIUBEREREiqJV0AUQERERUe4xxBEREREpEEMcERERkQIxxBEREREpEEMcERERkQIxxBEREREpEEMcERERkQIxxBEREREpEEMcERERkQIxxBF9Zl69eoVFixZJz2NjY7F8+fKCK4g+ut9//x3379+Xnq9btw6PHj0quIKICrH79+9DpVJh3bp1UtvUqVOhUqkKrqj/V6Ahbt26dVCpVNJDX18fX375Jby9vfH06dOCLI3ok2VgYICJEydi06ZNiIiIwNSpU7Fv376CLos+opMnT2LcuHG4f/8+/v77bwwbNgxaWvyfnkhpdAq6AACYNm0aypQpg8TERJw6dQp+fn7466+/cOPGDRgaGhZ0eUSfFG1tbfj6+qJ3795IS0uDqakp/vzzz4Iuiz6iUaNGwdXVFWXKlAEAjB49Gra2tgVcFZFyTJw4ERMmTCjoMgpHiGvVqhVq164NABg4cCCKFSuGBQ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x+iIqKEiYmJlL
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnYAAAHHCAYAAAAyKhW0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABbDUlEQVR4nO3dd1QU5/s28GsB6U1AmsFu7CViA7uiqNiNRCV20SjEGjV+Y8OGGqNYUZNYQ2KNJSYSsTfsYhfRYCRGRBSkKEV43j98d34MuyAgAhmvzzl7DvvMszP3zOzOXkxblRBCgIiIiIj+83SKuwAiIiIiKhwMdkREREQKwWBHREREpBAMdkREREQKwWBHREREpBAMdkREREQKwWBHREREpBAMdkREREQKwWBHREREpBAMdkQKlZSUhICAAOl5fHw8Vq1aVXwFUZH76aef8ODBA+n5xo0b8ejRo+IriP7zVCoVZs2aVdxllAiDBw9GhQoVZG0lYfkUSbDbuHEjVCqV9DA0NMTHH38MX19fPHnypChKIPrgGBkZYdq0aQgKCkJUVBRmzZqF3377rbjLoiJ08uRJTJ48GQ8ePMCff/4JHx8f6Ojw/3kiJdMryonNnj0bFStWREpKCk6dOoXAwED88ccfuHHjBoyNjYuyFCLF09XVhZ+fHwYOHIjMzEyYm5vj999/L+6yqAiNHz8erVu3RsWKFQEAEyZMgIODQzFXRaRcr169gp5ekUYrDUU69U6dOqFhw4YAgOHDh8Pa2hpLlizB3r170a9fv6IsheiDMHHiRHz22WeIiopCjRo1YGlpWdwlURGqXr067t+/jxs3bsDGxgaVK1cu7pKIJCkpKdDX11fUXmRDQ8PiLqF4z7Fr27YtACAyMhIA8Pz5c3z11VeoU6cOTE1NYW5ujk6dOuHq1asar01JScGsWbPw8ccfw9DQEA4ODujVqxfu378PAHjw4IHs8G/2R+vWraVxHTt2DCqVCtu2bcP//vc/2Nvbw8TEBN26d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w4cwLBhw5CQkIBx48YV0lJ4w9PTExUrVoS/vz8uX76MH374Aba2tli4cKHUZ/jw4fjpp5/Qv39/uLq64siRI1rf//mtfc6cOdDX18dXX32F1NRU6OvrY9asWfD398fw4cPRuHFjJCQk4OLFi7h8+TLat28PIP/bm88++ww1atTAggUL8Pvvv2Pu3LmwsrLC2rVr0bZtWyxcuBBBQUH46quv0KhRI7Rs2VL2+rzkgcJe5oMHD8b27dsxYMAANG3aFMePH891m5MjUQQ2bNggAIhDhw6Jp0+fiqioKLF161ZhbW0tjIyMxD///COEECIlJUVkZGTIXhsZGSkMDAzE7Nmzpbb169cLAGLJkiUa08rMzJReB0B8++23Gn1q1aolWrVqJT0/evSoACDKli0rEhISpPbt27cLAGLZsmXSuKtWrSrc3d2l6QghxMuXL0XFihVF+/btNabl6uoqateuLT1/+vSpACBmzpwptT148EDo6uqKefPmyV57/fp1oaenp9EeEREhAIhNmzZJbTNnzhRZV+fJkycFABEUFCR7bXBwsEZ7+fLlhYeHh0btPj4+IvtbJHvtkydPFra2tsLZ2Vm2TLds2SJ0dHTEyZMnZa9fs2aNACBOnz6tMb2sWrVqJY3v999/F3p6emLixIka/V6+fKnR5u/vL1Qqlfj777+1jjv7PKglJiYKS0tL4e3tLWuPjo4WFhYWsvZBgwYJExOTHOuPiYkR+vr6okOHDrL39MqVKwUAsX79etm8AhDfffed1Jaamirq168vbG1tRVpamhDi/96nR48elfo1adJEdOrUSWOesr8fYmJihJmZmdQ36zjy4vXr18Lc3Fz4+vpKbdq
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Размер обучающей выборки до oversampling и undersampling: 4200\n",
"Размер обучающей выборки после oversampling и undersampling: 4232\n"
]
},
{
"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>Date</th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Adj Close</th>\n",
" <th>Volume</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2020-07-08</td>\n",
" <td>5.66</td>\n",
" <td>5.73</td>\n",
" <td>5.47</td>\n",
" <td>5.56</td>\n",
" <td>5.341250</td>\n",
" <td>23355100.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>2021-01-19</td>\n",
" <td>5.15</td>\n",
" <td>5.15</td>\n",
" <td>5.02</td>\n",
" <td>5.13</td>\n",
" <td>4.966732</td>\n",
" <td>15906300.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>2010-04-08</td>\n",
" <td>10.60</td>\n",
" <td>10.65</td>\n",
" <td>10.48</td>\n",
" <td>10.52</td>\n",
" <td>8.794909</td>\n",
" <td>10456400.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>2020-12-07</td>\n",
" <td>5.47</td>\n",
" <td>5.80</td>\n",
" <td>5.47</td>\n",
" <td>5.75</td>\n",
" <td>5.541336</td>\n",
" <td>12929600.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>2021-01-05</td>\n",
" <td>6.15</td>\n",
" <td>6.16</td>\n",
" <td>5.98</td>\n",
" <td>6.04</td>\n",
" <td>5.847770</td>\n",
" <td>15080900.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Date Open High Low Close Adj Close Volume\n",
"0 2020-07-08 5.66 5.73 5.47 5.56 5.341250 23355100.0\n",
"20 2021-01-19 5.15 5.15 5.02 5.13 4.966732 15906300.0\n",
"21 2010-04-08 10.60 10.65 10.48 10.52 8.794909 10456400.0\n",
"24 2020-12-07 5.47 5.80 5.47 5.75 5.541336 12929600.0\n",
"28 2021-01-05 6.15 6.16 5.98 6.04 5.847770 15080900.0"
]
},
2024-11-09 11:41:45 +04:00
"execution_count": 76,
2024-11-09 10:31:35 +04:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.model_selection import train_test_split\n",
"from imblearn.over_sampling import RandomOverSampler\n",
"from imblearn.under_sampling import RandomUnderSampler\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Преобразование целевой переменной (цены) в категориальные диапазоны с использованием квантилей\n",
"X_train['closePrice_category'] = pd.qcut(X_train['Close'], q=4, labels=['low', 'medium', 'high', 'very_high'])\n",
"print(X_train.head())\n",
"\n",
"# Визуализация распределения цен после преобразования в категории\n",
"sns.countplot(x=X_train['closePrice_category'])\n",
"plt.title('Распределение категорий закрывающей цены в обучающей выборке')\n",
"plt.xlabel('Категория закрывающей цены')\n",
"plt.ylabel('Частота')\n",
"plt.show()\n",
"\n",
"# Балансировка категорий с помощью RandomOverSampler (увеличение меньшинств)\n",
"ros = RandomOverSampler(random_state=42)\n",
"y_train = X_train['closePrice_category']\n",
"X_train = X_train.drop(columns=['closePrice_category'])\n",
"\n",
"\n",
"# Применяем oversampling. Здесь важно, что мы используем X_train как DataFrame и y_train_categories как целевую переменную\n",
"X_resampled, y_resampled = ros.fit_resample(X_train, y_train)\n",
"\n",
"# Визуализация распределения цен после oversampling\n",
"sns.countplot(x=y_resampled)\n",
"plt.title('Распределение категорий закрывающей цены после oversampling')\n",
"plt.xlabel('Категория закрывающей цены')\n",
"plt.ylabel('Частота')\n",
"plt.show()\n",
"\n",
"# Применение RandomUnderSampler для уменьшения большего класса\n",
"rus = RandomUnderSampler(random_state=42)\n",
"X_resampled, y_resampled = rus.fit_resample(X_resampled, y_resampled)\n",
"\n",
"# Визуализация распределения цен после undersampling\n",
"sns.countplot(x=y_resampled)\n",
"plt.title('Распределение категорий закрывающей цены после undersampling')\n",
"plt.xlabel('Категория закрывающей цены')\n",
"plt.ylabel('Частота')\n",
"plt.show()\n",
"\n",
"\n",
"print(\"Размер обучающей выборки до oversampling и undersampling: \", len(X_train))\n",
"\n",
"\n",
"print(\"Размер обучающей выборки после oversampling и undersampling: \", len(X_resampled))\n",
"X_resampled.head()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"По сути, балансировка так то не требовалась, но все же мы ее провели, добавив в обучающую выборку 5 значений (ーー;)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Конструирование признаков\n",
"1. **Унитарное кодирование категориальных признаков. Преобразование категориальных признаков в бинарные векторы.**\n",
"* В данном датасете категориальные признаки отсутствуют, так что пропустим этот пункт.\n",
"2. **Дискретизация числовых признаков. Преобразование непрерывных числовых значений в дискретные категории или интервалы (бины).**"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 77,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Названия столбцов в датасете:\n",
"Index(['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'], dtype='object')\n",
"Статистические параметры:\n",
" Date Open High Low \\\n",
"count 5251 5251.000000 5251.000000 5251.000000 \n",
"mean 2011-12-01 11:59:51.772995840 6.863639 6.986071 6.720615 \n",
"min 2001-06-22 00:00:00 1.142857 1.142857 1.142857 \n",
"25% 2006-09-13 12:00:00 2.857143 2.880000 2.810000 \n",
"50% 2011-11-29 00:00:00 4.600000 4.710000 4.490000 \n",
"75% 2017-02-16 12:00:00 10.650000 10.860000 10.425000 \n",
"max 2022-05-05 00:00:00 20.420000 20.590000 20.090000 \n",
"std NaN 4.753836 4.832010 4.662891 \n",
"\n",
" Close Adj Close Volume \n",
"count 5251.000000 5251.000000 5.251000e+03 \n",
"mean 6.850606 5.895644 8.976705e+06 \n",
"min 1.142857 0.935334 0.000000e+00 \n",
"25% 2.857143 2.537094 2.845900e+06 \n",
"50% 4.600000 4.337419 8.216200e+06 \n",
"75% 10.640000 8.951945 1.327245e+07 \n",
"max 20.389999 17.543156 2.891228e+07 \n",
"std 4.746055 3.941634 7.251098e+06 \n",
"После дискретизации 'Close':\n",
" Date Open High Low Close Adj Close Volume \\\n",
"0 2001-06-22 3.428571 3.428571 3.428571 3.428571 2.806002 0.0 \n",
"1 2001-06-25 3.428571 3.428571 3.428571 3.428571 2.806002 0.0 \n",
"2 2001-06-26 3.714286 3.714286 3.714286 3.714286 3.039837 0.0 \n",
"3 2001-06-27 3.714286 3.714286 3.714286 3.714286 3.039837 0.0 \n",
"4 2001-06-28 3.714286 3.714286 3.714286 3.714286 3.039837 0.0 \n",
"\n",
" Close_Disc \n",
"0 2-4 \n",
"1 2-4 \n",
"2 2-4 \n",
"3 2-4 \n",
"4 2-4 \n",
" Date Open High Low Close Adj Close Volume \\\n",
"2623 2011-11-25 14.730000 15.050000 14.65 14.650000 12.429751 2433000.0 \n",
"2624 2011-11-28 15.150000 15.370000 15.04 15.200000 12.896397 4348600.0 \n",
"2625 2011-11-29 15.270000 15.710000 15.21 15.600000 13.235776 4576500.0 \n",
"2626 2011-11-30 16.120001 16.850000 16.07 16.830000 14.279361 9537100.0 \n",
"2627 2011-12-01 16.770000 16.940001 16.58 16.809999 14.262395 5111500.0 \n",
"\n",
" Close_Disc \n",
"2623 14-16 \n",
"2624 14-16 \n",
"2625 14-16 \n",
"2626 16+ \n",
"2627 16+ \n",
" Date Open High Low Close Adj Close Volume Close_Disc\n",
"5246 2022-04-29 5.66 5.69 5.50 5.51 5.51 16613300.0 4-6\n",
"5247 2022-05-02 5.33 5.39 5.18 5.30 5.30 27106700.0 4-6\n",
"5248 2022-05-03 5.32 5.53 5.32 5.47 5.47 18914200.0 4-6\n",
"5249 2022-05-04 5.47 5.61 5.37 5.60 5.60 20530700.0 4-6\n",
"5250 2022-05-05 5.63 5.66 5.34 5.44 5.44 19879200.0 4-6\n"
]
}
],
"source": [
"#Пример дискретизации по цене закрытия\n",
"# Проверка на наличие числовых признаков\n",
"print(\"Названия столбцов в датасете:\")\n",
"print(df.columns)\n",
"\n",
"# Выводим основные статистические параметры для количественных признаков\n",
"print(\"Статистические параметры:\")\n",
"print(df.describe())\n",
"\n",
"# Дискретизация столбца 'Close' на группы\n",
"bins = [0, 2, 4, 6, 8, 10, 12, 14, 16, 30] # Определяем границы корзин\n",
"labels = ['0-2', '2-4', '4-6', '6-8', '8-10', '10-12', '12-14', '14-16', '16+'] # Названия категорий\n",
"\n",
"# Создание нового столбца 'Close_Disc' на основе дискретизации\n",
2024-11-09 11:05:06 +04:00
"df['Close_Disc'] = pd.cut(df['Close'], bins=bins, labels=labels, include_lowest=True) #pd.cut выполняет дискретизацию переменной\n",
"#include_lowest=True: Этот параметр гарантирует, что самое нижнее значение (в данном случае 0), будет входить в первую категорию.\n",
"\n",
"\n",
2024-11-09 10:31:35 +04:00
"\n",
"# Проверка результата\n",
"print(\"После дискретизации 'Close':\")\n",
"print(df.head())\n",
"n = len(df)\n",
"middle_index = n // 2\n",
"print(df.iloc[middle_index - 2: middle_index + 3])\n",
"print(df.tail())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Конструирование новых признаков:"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 78,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Исходный датасет: \n",
" Date Open High Low Close Adj Close Volume Close_Disc\n",
"5246 2022-04-29 5.66 5.69 5.50 5.51 5.51 16613300.0 4-6\n",
"5247 2022-05-02 5.33 5.39 5.18 5.30 5.30 27106700.0 4-6\n",
"5248 2022-05-03 5.32 5.53 5.32 5.47 5.47 18914200.0 4-6\n",
"5249 2022-05-04 5.47 5.61 5.37 5.60 5.60 20530700.0 4-6\n",
"5250 2022-05-05 5.63 5.66 5.34 5.44 5.44 19879200.0 4-6\n",
"\n",
"Обучающая выборка: \n",
" Date Open High Low Close Adj Close Volume\n",
"2435 2011-04-14 12.530000 12.84 12.480000 12.750000 10.754427 10527200.0\n",
"1756 2013-05-30 11.510000 11.76 11.480000 11.720000 10.166282 9028100.0\n",
"3296 2009-11-20 13.100000 13.28 12.870000 13.220000 11.031483 17024900.0\n",
"1243 2012-09-17 18.870001 19.00 18.469999 18.870001 16.178450 6652400.0\n",
"343 2006-12-12 12.920000 13.00 12.580000 12.800000 10.487218 3981100.0\n",
"\n",
"Тестовая выборка: \n",
" Date Open High Low Close Adj Close \\\n",
"3095 2013-10-14 9.290000 9.350000 9.070000 9.130000 8.025586 \n",
"859 2004-11-24 3.090000 3.160000 3.040000 3.100000 2.537094 \n",
"3134 2013-12-09 8.550000 8.770000 8.550000 8.770000 7.709136 \n",
"2577 2011-09-21 16.709999 17.070000 16.379999 16.400000 13.869872 \n",
"378 2002-12-27 2.571429 2.571429 2.571429 2.571429 2.104502 \n",
"\n",
" Volume \n",
"3095 5861400.0 \n",
"859 211300.0 \n",
"3134 5335400.0 \n",
"2577 14524400.0 \n",
"378 0.0 \n",
"\n",
"Контрольная выборка: \n",
" Date Open High Low Close Adj Close \\\n",
"3095 2013-10-14 9.290000 9.350000 9.070000 9.130000 8.025586 \n",
"859 2004-11-24 3.090000 3.160000 3.040000 3.100000 2.537094 \n",
"3134 2013-12-09 8.550000 8.770000 8.550000 8.770000 7.709136 \n",
"2577 2011-09-21 16.709999 17.070000 16.379999 16.400000 13.869872 \n",
"378 2002-12-27 2.571429 2.571429 2.571429 2.571429 2.104502 \n",
"\n",
" Volume \n",
"3095 5861400.0 \n",
"859 211300.0 \n",
"3134 5335400.0 \n",
"2577 14524400.0 \n",
"378 0.0 \n",
"\n",
"Новые признаки в обучающей выборке:\n",
" Volume_Change\n",
"2435 0.977868\n",
"1756 -0.142403\n",
"3296 0.885768\n",
"1243 -0.609255\n",
"343 -0.401554\n",
"\n",
"Новые признаки в тестовой выборке:\n",
" Volume_Change\n",
"3095 inf\n",
"859 -0.963951\n",
"3134 24.250355\n",
"2577 1.722270\n",
"378 -1.000000\n",
"\n",
"Новые признаки в контрольной выборке:\n",
" Volume_Change\n",
"3095 inf\n",
"859 -0.963951\n",
"3134 24.250355\n",
"2577 1.722270\n",
"378 -1.000000\n",
"\n",
"Новые признаки в датасете:\n",
" Volume_Change\n",
"5246 -0.218393\n",
"5247 0.631626\n",
"5248 -0.302232\n",
"5249 0.085465\n",
"5250 -0.031733\n"
]
}
],
"source": [
"print('\\nИсходный датасет: ')\n",
"print(df.tail())\n",
"print('\\nОбучающая выборка: ')\n",
"print(X_resampled.tail())\n",
"print('\\nТестовая выборка: ')\n",
"print(X_test.tail())\n",
"print('\\nКонтрольная выборка: ')\n",
"print(X_val.tail())\n",
"\n",
"#Объем изменений\n",
"df['Volume_Change'] = df['Volume'].pct_change()\n",
"X_resampled['Volume_Change'] = X_resampled['Volume'].pct_change()\n",
"X_test['Volume_Change'] = X_test['Volume'].pct_change()\n",
"X_val['Volume_Change'] = X_val['Volume'].pct_change()\n",
2024-11-09 11:05:06 +04:00
"# Результатом работы pct_change() является серия, где каждое значение представляет собой \n",
"# процентное изменение относительно предыдущего значения. Первое значение всегда будет NaN, \n",
"# так как для него нет предшествующего значения для сравнения.\n",
2024-11-09 10:31:35 +04:00
"\n",
"# Проверка создания новых признаков\n",
"print(\"\\nНовые признаки в обучающей выборке:\")\n",
"print(X_resampled[['Volume_Change']].tail())\n",
"\n",
"print(\"\\nНовые признаки в тестовой выборке:\")\n",
"print(X_test[['Volume_Change']].tail())\n",
"\n",
"print(\"\\nНовые признаки в контрольной выборке:\")\n",
"print(X_val[['Volume_Change']].tail())\n",
"\n",
"print(\"\\nНовые признаки в датасете:\")\n",
"print(df[['Volume_Change']].tail())\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Проверим новые признаки:"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 79,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Исходный датасет: \n",
"Volume_Change 501\n",
"dtype: int64\n",
"\n",
"Обучающая выборка: \n",
"Volume_Change 102\n",
"dtype: int64\n",
"\n",
"Тестовая выборка: \n",
"Volume_Change 16\n",
"dtype: int64\n",
"\n",
"Контрольная выборка: \n",
"Volume_Change 16\n",
"dtype: int64\n",
"\n",
"Есть ли пустые значения признаков: \n",
"\n",
"Исходный датасет: \n",
"Volume_Change True\n",
"dtype: bool\n",
"\n",
"Обучающая выорка: \n",
"Volume_Change True\n",
"dtype: bool\n",
"\n",
"Тестовая выборка: \n",
"Volume_Change True\n",
"dtype: bool\n",
"\n",
"Контрольная выборка: \n",
"Volume_Change True\n",
"dtype: bool\n",
"\n",
"Количество бесконечных значений в каждом столбце:\n",
"\n",
"Исходный датасет: \n",
"Volume_Change 32\n",
"dtype: int64\n",
"\n",
"Обучающая выборка: \n",
"Volume_Change 310\n",
"dtype: int64\n",
"\n",
"Тестовая выборка: \n",
"Volume_Change 107\n",
"dtype: int64\n",
"\n",
"Контрольная выборка: \n",
"Volume_Change 107\n",
"dtype: int64\n",
"Volume_Change процент пустых значений в датасете: %9.54\n",
"Volume_Change процент пустых значений в обучающей выборке: %2.41\n",
"Volume_Change процент пустых значений в тестовой выборке: %1.52\n",
"Volume_Change процент пустых значений в контрольной выборке: %1.52\n"
]
}
],
"source": [
"print('\\nИсходный датасет: ')\n",
"print(df[['Volume_Change']].isnull().sum())\n",
"print('\\nОбучающая выборка: ')\n",
"print(X_resampled[['Volume_Change']].isnull().sum())\n",
"print('\\nТестовая выборка: ')\n",
"print(X_test[['Volume_Change']].isnull().sum())\n",
"print('\\nКонтрольная выборка: ')\n",
"print(X_val[['Volume_Change']].isnull().sum())\n",
"print()\n",
"\n",
"# Есть ли пустые значения признаков\n",
"print('Есть ли пустые значения признаков: ')\n",
"print('\\nИсходный датасет: ')\n",
"print(df[['Volume_Change']].isnull().any())\n",
"print('\\nОбучающая выорка: ')\n",
"print(X_resampled[['Volume_Change']].isnull().any())\n",
"print('\\nТестовая выборка: ')\n",
"print(X_test[['Volume_Change']].isnull().any())\n",
"print('\\nКонтрольная выборка: ')\n",
"print(X_val[['Volume_Change']].isnull().any())\n",
"print()\n",
"\n",
"# Проверка на бесконечные значения\n",
"print(\"Количество бесконечных значений в каждом столбце:\")\n",
"print('\\nИсходный датасет: ')\n",
"print(np.isinf(df[['Volume_Change']]).sum())\n",
"print('\\nОбучающая выборка: ')\n",
"print(np.isinf(X_resampled[['Volume_Change']]).sum())\n",
"print('\\nТестовая выборка: ')\n",
"print(np.isinf(X_test[['Volume_Change']]).sum())\n",
"print('\\nКонтрольная выборка: ')\n",
"print(np.isinf(X_val[['Volume_Change']]).sum())\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in df[['Volume_Change']].columns:\n",
" null_rate = df[['Volume_Change']][i].isnull().sum() / len(df[['Volume_Change']]) * 100\n",
" print(f\"{i} процент пустых значений в датасете: %{null_rate:.2f}\")\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in X_resampled[['Volume_Change']].columns:\n",
" null_rate = X_resampled[['Volume_Change']][i].isnull().sum() / len(X_resampled[['Volume_Change']]) * 100\n",
" print(f\"{i} процент пустых значений в обучающей выборке: %{null_rate:.2f}\")\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in X_test[['Volume_Change']].columns:\n",
" null_rate = X_test[['Volume_Change']][i].isnull().sum() / len(X_test[['Volume_Change']]) * 100\n",
" print(f\"{i} процент пустых значений в тестовой выборке: %{null_rate:.2f}\")\n",
"\n",
"# Процент пустых значений признаков\n",
"for i in X_val[['Volume_Change']].columns:\n",
" null_rate = X_val[['Volume_Change']][i].isnull().sum() / len(X_val[['Volume_Change']]) * 100\n",
" print(f\"{i} процент пустых значений в контрольной выборке: %{null_rate:.2f}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Заполним пустые данные"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 80,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(5251, 1)\n",
"(4232, 1)\n",
"(1051, 1)\n",
"(1051, 1)\n",
"Volume_Change False\n",
"dtype: bool\n",
"Volume_Change False\n",
"dtype: bool\n",
"Volume_Change False\n",
"dtype: bool\n",
"Volume_Change False\n",
"dtype: bool\n",
" Volume_Change\n",
"5246 -0.218393\n",
"5247 0.631626\n",
"5248 -0.302232\n",
"5249 0.085465\n",
"5250 -0.031733\n",
" Volume_Change\n",
"2435 0.977868\n",
"1756 -0.142403\n",
"3296 0.885768\n",
"1243 -0.609255\n",
"343 -0.401554\n",
" Volume_Change\n",
"3095 0.000000\n",
"859 -0.963951\n",
"3134 24.250355\n",
"2577 1.722270\n",
"378 -1.000000\n",
" Volume_Change\n",
"3095 0.000000\n",
"859 -0.963951\n",
"3134 24.250355\n",
"2577 1.722270\n",
"378 -1.000000\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_26220\\4038454119.py:39: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
2024-11-09 10:31:35 +04:00
"You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.\n",
"A typical example is when you are setting values in a column of a DataFrame, like:\n",
"\n",
"df[\"col\"][row_indexer] = value\n",
"\n",
"Use `df.loc[row_indexer, \"col\"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
"\n",
" df[['Volume_Change']].loc[df[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_df\n",
2024-11-09 11:41:45 +04:00
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_26220\\4038454119.py:40: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
2024-11-09 10:31:35 +04:00
"You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.\n",
"A typical example is when you are setting values in a column of a DataFrame, like:\n",
"\n",
"df[\"col\"][row_indexer] = value\n",
"\n",
"Use `df.loc[row_indexer, \"col\"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
"\n",
" X_resampled[['Volume_Change']].loc[X_resampled[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_train\n",
2024-11-09 11:41:45 +04:00
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_26220\\4038454119.py:41: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
2024-11-09 10:31:35 +04:00
"You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.\n",
"A typical example is when you are setting values in a column of a DataFrame, like:\n",
"\n",
"df[\"col\"][row_indexer] = value\n",
"\n",
"Use `df.loc[row_indexer, \"col\"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
"\n",
" X_test[['Volume_Change']].loc[X_test[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_test\n",
2024-11-09 11:41:45 +04:00
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_26220\\4038454119.py:42: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
2024-11-09 10:31:35 +04:00
"You are setting values through chained assignment. Currently this works in certain cases, but when using Copy-on-Write (which will become the default behaviour in pandas 3.0) this will never work to update the original DataFrame or Series, because the intermediate object on which we are setting values will behave as a copy.\n",
"A typical example is when you are setting values in a column of a DataFrame, like:\n",
"\n",
"df[\"col\"][row_indexer] = value\n",
"\n",
"Use `df.loc[row_indexer, \"col\"] = values` instead, to perform the assignment in a single step and ensure this keeps updating the original `df`.\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
"\n",
" X_val[['Volume_Change']].loc[X_val[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_val\n"
]
}
],
"source": [
"# Заменяем бесконечные значения на NaN\n",
"df.replace([np.inf, -np.inf], np.nan, inplace=True)\n",
"X_resampled.replace([np.inf, -np.inf], np.nan, inplace=True)\n",
"X_test.replace([np.inf, -np.inf], np.nan, inplace=True)\n",
"X_val.replace([np.inf, -np.inf], np.nan, inplace=True)\n",
"\n",
"fillna_df = df[['Volume_Change']].fillna(0)\n",
"fillna_X_resampled = X_resampled[['Volume_Change']].fillna(0)\n",
"fillna_X_test = X_test[['Volume_Change']].fillna(0)\n",
"fillna_X_val = X_val[['Volume_Change']].fillna(0)\n",
2024-11-09 11:05:06 +04:00
"# используется для заполнения всех значений NaN \n",
"# (Not a Number) в DataFrame или Series указанным значением. \n",
"# В данном случае, fillna(0) заполняет все ячейки, содержащие NaN, значением 0.\n",
2024-11-09 10:31:35 +04:00
"\n",
"\n",
"print(fillna_df.shape)\n",
"print(fillna_X_resampled.shape)\n",
"print(fillna_X_test.shape)\n",
"print(fillna_X_val.shape)\n",
"\n",
"print(fillna_df.isnull().any())\n",
"print(fillna_X_resampled.isnull().any())\n",
"print(fillna_X_test.isnull().any())\n",
"print(fillna_X_val.isnull().any())\n",
"\n",
"# Замена пустых данных на 0\n",
"df[\"Volume_Change\"] = df[\"Volume_Change\"].fillna(0)\n",
"X_resampled[\"Volume_Change\"] = X_resampled[\"Volume_Change\"].fillna(0)\n",
"X_test[\"Volume_Change\"] = X_test[\"Volume_Change\"].fillna(0)\n",
"X_val[\"Volume_Change\"] = X_val[\"Volume_Change\"].fillna(0)\n",
"\n",
"# Вычисляем медиану для колонки \"Volume_Change\"\n",
"median_Volume_Change_df = df[\"Volume_Change\"].median()\n",
"median_Volume_Change_train = X_resampled[\"Volume_Change\"].median()\n",
"median_Volume_Change_test = X_test[\"Volume_Change\"].median()\n",
"median_Volume_Change_val = X_val[\"Volume_Change\"].median()\n",
"\n",
"# Заменяем значения 0 на медиану\n",
"df[['Volume_Change']].loc[df[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_df\n",
"X_resampled[['Volume_Change']].loc[X_resampled[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_train\n",
"X_test[['Volume_Change']].loc[X_test[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_test\n",
"X_val[['Volume_Change']].loc[X_val[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_val\n",
"\n",
"print(df[['Volume_Change']].tail())\n",
"print(X_resampled[['Volume_Change']].tail())\n",
"print(X_test[['Volume_Change']].tail())\n",
"print(X_val[['Volume_Change']].tail())\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Удалим наблюдения с пропусками"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 81,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(5251, 1)\n",
"(4232, 1)\n",
"(1051, 1)\n",
"(1051, 1)\n",
"Volume_Change False\n",
"dtype: bool\n",
" Volume_Change\n",
"5246 -0.218393\n",
"5247 0.631626\n",
"5248 -0.302232\n",
"5249 0.085465\n",
"5250 -0.031733\n",
"Volume_Change False\n",
"dtype: bool\n",
" Volume_Change\n",
"2435 0.977868\n",
"1756 -0.142403\n",
"3296 0.885768\n",
"1243 -0.609255\n",
"343 -0.401554\n",
"Volume_Change False\n",
"dtype: bool\n",
" Volume_Change\n",
"3095 0.000000\n",
"859 -0.963951\n",
"3134 24.250355\n",
"2577 1.722270\n",
"378 -1.000000\n",
"Volume_Change False\n",
"dtype: bool\n",
" Volume_Change\n",
"3095 0.000000\n",
"859 -0.963951\n",
"3134 24.250355\n",
"2577 1.722270\n",
"378 -1.000000\n"
]
}
],
"source": [
"dropna_df = df[['Volume_Change']].dropna()\n",
"dropna_X_resampled = X_resampled[['Volume_Change']].dropna()\n",
"dropna_X_test = X_test[['Volume_Change']].dropna()\n",
"dropna_X_val = X_val[['Volume_Change']].dropna()\n",
"\n",
"print(dropna_df.shape)\n",
"print(dropna_X_resampled.shape)\n",
"print(dropna_X_test.shape)\n",
"print(dropna_X_val.shape)\n",
"\n",
"print(dropna_df.isnull().any())\n",
"print(df[['Volume_Change']].tail())\n",
"print(dropna_X_resampled.isnull().any())\n",
"print(X_resampled[['Volume_Change']].tail())\n",
"print(dropna_X_test.isnull().any())\n",
"print(X_test[['Volume_Change']].tail())\n",
"print(dropna_X_val.isnull().any())\n",
"print(X_val[['Volume_Change']].tail())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Масштабируем новые признаки:\n"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 82,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Результаты после масштабирования:\n",
"\n",
" Датафрейм:\n",
" Volume_Change\n",
"5246 -0.176620\n",
"5247 0.224373\n",
"5248 -0.216171\n",
"5249 -0.033276\n",
"5250 -0.088564\n",
"\n",
" Обучающая:\n",
" Volume_Change\n",
"2435 -0.033736\n",
"1756 -0.033805\n",
"3296 -0.033742\n",
"1243 -0.033834\n",
"343 -0.033821\n",
"\n",
" Тестовая:\n",
" Volume_Change\n",
"3095 -0.033796\n",
"859 -0.033856\n",
"3134 -0.032301\n",
"2577 -0.033690\n",
"378 -0.033858\n",
"\n",
" Контрольная:\n",
" Volume_Change\n",
"3095 -0.033796\n",
"859 -0.033856\n",
"3134 -0.032301\n",
"2577 -0.033690\n",
"378 -0.033858\n"
]
}
],
"source": [
"from sklearn.preprocessing import StandardScaler, MinMaxScaler\n",
"\n",
"# Пример масштабирования числовых признаков\n",
"numerical_features = ['Volume_Change']\n",
"\n",
"scaler = StandardScaler()\n",
"df[numerical_features] = scaler.fit_transform(df[numerical_features])\n",
"X_resampled[numerical_features] = scaler.fit_transform(X_resampled[numerical_features])\n",
"X_val[numerical_features] = scaler.transform(X_val[numerical_features])\n",
"X_test[numerical_features] = scaler.transform(X_test[numerical_features])\n",
2024-11-09 11:05:06 +04:00
"# fit() - вычисляет среднее и стандартное отклонение для каждого признака в наборе данных.\n",
"# transform() - применяет расчеты, чтобы стандартизировать данные по приведенной выше формуле.\n",
2024-11-09 10:31:35 +04:00
"\n",
"# Вывод результатов после масштабирования\n",
"print(\"Результаты после масштабирования:\")\n",
"print(\"\\n Датафрейм:\")\n",
"print(df[numerical_features].tail())\n",
"print(\"\\n Обучающая:\")\n",
"print(X_resampled[numerical_features].tail())\n",
"print(\"\\n Тестовая:\")\n",
"print(X_val[numerical_features].tail())\n",
"print(\"\\n Контрольная:\")\n",
"print(X_test[numerical_features].tail())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Данные признаки предоставляют важную информацию о текущем тренде и возможных изменениях в будущих ценах. Положительные значения Price_Change и Percentage_Change, наряду с высоким Volume_Change, могут поддерживать гипотезу о росте цен на акции.\n",
"\n",
"Также, эти признаки помогают понять уровень рискованности инвестиций. Высокие значения Price_Range и резкие изменения в Volume_Change могут указывать на склонность к большим колебаниям, что требует внимательного управления рисками."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Применим featuretools для конструирования признаков:"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 83,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
" Date Open High Low Close Adj Close Volume \\\n",
"0 2020-07-08 5.66 5.73 5.47 5.56 5.341250 23355100.0 \n",
"20 2021-01-19 5.15 5.15 5.02 5.13 4.966732 15906300.0 \n",
"21 2010-04-08 10.60 10.65 10.48 10.52 8.794909 10456400.0 \n",
"24 2020-12-07 5.47 5.80 5.47 5.75 5.541336 12929600.0 \n",
"28 2021-01-05 6.15 6.16 5.98 6.04 5.847770 15080900.0 \n",
"\n",
" Volume_Change id \n",
"0 -0.033796 0 \n",
"20 -0.033816 20 \n",
"21 -0.033817 21 \n",
"24 -0.033782 24 \n",
"28 -0.033786 28 \n"
2024-11-09 10:31:35 +04:00
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\woodwork\\type_sys\\utils.py:33: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n",
" pd.to_datetime(\n",
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
" Open High Low Close Volume Close_Disc Volume_Change \\\n",
"id \n",
"0 3.428571 3.428571 3.428571 3.428571 0.0 2-4 -0.073594 \n",
"1 3.428571 3.428571 3.428571 3.428571 0.0 2-4 -0.073594 \n",
"2 3.714286 3.714286 3.714286 3.714286 0.0 2-4 -0.073594 \n",
"3 3.714286 3.714286 3.714286 3.714286 0.0 2-4 -0.073594 \n",
"4 3.714286 3.714286 3.714286 3.714286 0.0 2-4 -0.073594 \n",
2024-11-09 10:31:35 +04:00
"\n",
" DAY(Date) MONTH(Date) WEEKDAY(Date) YEAR(Date) \n",
"id \n",
2024-11-09 11:41:45 +04:00
"0 22 6 4 2001 \n",
"1 25 6 0 2001 \n",
"2 26 6 1 2001 \n",
"3 27 6 2 2001 \n",
"4 28 6 3 2001 \n"
2024-11-09 10:31:35 +04:00
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\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",
2024-11-09 10:31:35 +04:00
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:143: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" df = pd.concat([df, default_df], sort=True)\n",
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\featuretools\\computational_backends\\feature_set_calculator.py:143: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
" df = pd.concat([df, default_df], sort=True)\n"
]
2024-11-09 11:41:45 +04:00
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" Open High Low Close Volume Volume_Change DAY(Date) \\\n",
"id \n",
"0 5.66 5.73 5.47 5.56 23355100.0 -0.033796 8 \n",
"20 5.15 5.15 5.02 5.13 15906300.0 -0.033816 19 \n",
"21 10.60 10.65 10.48 10.52 10456400.0 -0.033817 8 \n",
"24 5.47 5.80 5.47 5.75 12929600.0 -0.033782 7 \n",
"28 6.15 6.16 5.98 6.04 15080900.0 -0.033786 5 \n",
"\n",
" MONTH(Date) WEEKDAY(Date) YEAR(Date) \n",
"id \n",
"0 7 2 2020 \n",
"20 1 1 2021 \n",
"21 4 3 2010 \n",
"24 12 0 2020 \n",
"28 1 1 2021 \n",
" Open High Low Close Volume Volume_Change DAY(Date) \\\n",
"id \n",
"1437 18.25 18.68 17.90 18.559999 6853000.0 -0.033812 26 \n",
"2700 3.09 3.11 2.98 3.100000 10015600.0 -0.031587 5 \n",
"3647 12.89 12.98 12.54 12.650000 3031800.0 -0.033849 26 \n",
"2512 2.93 2.93 2.87 2.910000 6872900.0 -0.033823 7 \n",
"2902 15.22 15.63 15.18 15.520000 8104600.0 -0.033743 17 \n",
"\n",
" MONTH(Date) WEEKDAY(Date) YEAR(Date) \n",
"id \n",
"1437 9 2 2012 \n",
"2700 4 1 2016 \n",
"3647 12 1 2006 \n",
"2512 6 3 2018 \n",
"2902 8 2 2011 \n",
" Open High Low Close Volume Volume_Change DAY(Date) \\\n",
"id \n",
"1437 18.25 18.68 17.90 18.559999 6853000.0 -0.033812 26 \n",
"2700 3.09 3.11 2.98 3.100000 10015600.0 -0.031587 5 \n",
"3647 12.89 12.98 12.54 12.650000 3031800.0 -0.033849 26 \n",
"2512 2.93 2.93 2.87 2.910000 6872900.0 -0.033823 7 \n",
"2902 15.22 15.63 15.18 15.520000 8104600.0 -0.033743 17 \n",
"\n",
" MONTH(Date) WEEKDAY(Date) YEAR(Date) \n",
"id \n",
"1437 9 2 2012 \n",
"2700 4 1 2016 \n",
"3647 12 1 2006 \n",
"2512 6 3 2018 \n",
"2902 8 2 2011 \n"
]
2024-11-09 10:31:35 +04:00
}
],
"source": [
"import featuretools as ft\n",
"\n",
2024-11-09 11:41:45 +04:00
"# Добавляем уникальный идентификатор\n",
2024-11-09 10:31:35 +04:00
"df['id'] = df.index \n",
"X_resampled['id'] = X_resampled.index\n",
"X_val['id'] = X_val.index\n",
"X_test['id'] = X_test.index\n",
2024-11-09 11:41:45 +04:00
"\n",
2024-11-09 10:31:35 +04:00
"# Удаление дубликатов по идентификатору\n",
"df = df.drop_duplicates(subset='id')\n",
"\n",
"# Удаление дубликатов из столбца \"id\", сохранив первое вхождение\n",
"df = df.drop_duplicates(subset='id', keep='first')\n",
"\n",
2024-11-09 11:41:45 +04:00
"# Удаляем столбец 'Adj Close' из оригинального датафрейма\n",
"df = df.drop(columns=['Adj Close'], errors='ignore')\n",
2024-11-09 10:31:35 +04:00
"\n",
2024-11-09 11:41:45 +04:00
"print(X_resampled.head()) # Убедитесь, что датафреймы содержат корректные данные перед удалением\n",
2024-11-09 10:31:35 +04:00
"\n",
"# Создание EntitySet\n",
"es = ft.EntitySet(id='stock_data')\n",
"\n",
2024-11-09 11:05:06 +04:00
"# Добавление датафрейма с акциями\n",
2024-11-09 10:31:35 +04:00
"es = es.add_dataframe(dataframe_name='stocks', dataframe=df, index='id')\n",
"\n",
"# Генерация признаков с помощью глубокой синтезы признаков\n",
"feature_matrix, feature_defs = ft.dfs(entityset=es, target_dataframe_name='stocks', max_depth=2)\n",
"\n",
"# Выводим первые 5 строк сгенерированного набора признаков\n",
"print(feature_matrix.head())\n",
"\n",
2024-11-09 11:41:45 +04:00
"# Удаляем 'Adj Close' из X_resampled\n",
"X_resampled = X_resampled.drop(columns=['Adj Close'], errors='ignore')\n",
2024-11-09 10:31:35 +04:00
"X_resampled = X_resampled.drop_duplicates(subset='id')\n",
"X_resampled = X_resampled.drop_duplicates(subset='id', keep='first') # or keep='last'\n",
"\n",
"# Определение сущностей (Создание EntitySet)\n",
"es = ft.EntitySet(id='stock_data')\n",
"\n",
2024-11-09 11:41:45 +04:00
"# Добавление датафрейма X_resampled\n",
2024-11-09 10:31:35 +04:00
"es = es.add_dataframe(dataframe_name='stocks', dataframe=X_resampled, index='id')\n",
"\n",
2024-11-09 11:41:45 +04:00
"# Генерация признаков для X_resampled\n",
2024-11-09 10:31:35 +04:00
"feature_matrix, feature_defs = ft.dfs(entityset=es, target_dataframe_name='stocks', max_depth=2)\n",
"\n",
"# Преобразование признаков для контрольной и тестовой выборок\n",
"val_feature_matrix = ft.calculate_feature_matrix(features=feature_defs, entityset=es, instance_ids=X_val.index)\n",
"test_feature_matrix = ft.calculate_feature_matrix(features=feature_defs, entityset=es, instance_ids=X_test.index)\n",
"\n",
2024-11-09 11:41:45 +04:00
"# Удаляем 'Adj Close' из X_val и X_test (если необходимо)\n",
"X_val = X_val.drop(columns=['Adj Close'], errors='ignore')\n",
"X_test = X_test.drop(columns=['Adj Close'], errors='ignore')\n",
"\n",
"print(feature_matrix.head())\n",
"print(val_feature_matrix.head())\n",
"print(test_feature_matrix.head())"
2024-11-09 10:31:35 +04:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Система сгенерировала следующие признаки:\n",
"1. **Open, High, Low, Close, Adj Close**: Это стандартные финансовые параметры акций, отражающие цены открытия, максимальные, минимальные и закрытия за определенный период.\n",
"**Volume**: Объем торгов акциями, который показывает, сколько акций было куплено/продано за определенный период.\n",
"\n",
"2. Сложные признаки:\n",
"**Close_Disc**: Это диапазон цены закрытия.\n",
"**Price_Change**: Изменение цены, т.е. разница между ценой закрытия и ценой открытия акций.\n",
"**Percentage_Change**: Процентное изменение цен, которое позволяет оценить относительное изменение стоимости акций.\n",
"**Average_Price**: Средняя цена акций за указанный период. Этот показатель может быть использован для оценки общей тенденции рынка.\n",
"\n",
"3. Также произошло разбиение даты на месяц, день недели и год, что может помочь в анализе сезонных и временных закономерностей."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Оценим качество каждого набора признаков:"
]
},
{
"cell_type": "code",
2024-11-09 11:41:45 +04:00
"execution_count": 84,
2024-11-09 10:31:35 +04:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
" Open High Low Volume Volume_Change DAY(Date) MONTH(Date) \\\n",
"id \n",
"0 5.66 5.73 5.47 23355100.0 -0.033796 8 7 \n",
"20 5.15 5.15 5.02 15906300.0 -0.033816 19 1 \n",
"21 10.60 10.65 10.48 10456400.0 -0.033817 8 4 \n",
"24 5.47 5.80 5.47 12929600.0 -0.033782 7 12 \n",
"28 6.15 6.16 5.98 15080900.0 -0.033786 5 1 \n",
"\n",
" WEEKDAY(Date) YEAR(Date) \n",
"id \n",
"0 2 2020 \n",
"20 1 2021 \n",
"21 3 2010 \n",
"24 0 2020 \n",
"28 1 2021 \n",
"\n",
"LinearRegression:\n",
"Коэффициент детерминации R²: 1.00\n",
"Время обучения модели: 0.05 секунд\n",
"Среднеквадратичная ошибка: 0.09\n",
"Средняя абсолютная ошибка: 0.06\n"
2024-11-09 10:31:35 +04:00
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
"Кросс-валидация RMSE: 0.08938664892927554 \n",
2024-11-09 10:31:35 +04:00
"\n"
]
},
{
"data": {
2024-11-09 11:41:45 +04:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADYUElEQVR4nOzdd3hUVfrA8e+9d/pMMklIDwkloUhHUFRAQJCi6KroKhYQsOwqrmVdf7pr11131bXsWrGvZe26dkTFDioqKiIloZOQXqaXe+/vj5iRIQEJhP5+HvM8zLnnnnvmJjPOO+ec9yimaZoIIYQQQgghhNgp6p7ugBBCCCG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zm+uuvp2fPnjgcDvLy8jjppJMoKyvb5nldu3bd5t/O5hRFYfbs2Tz99NP06tULh8PBkCFD+Pjjj1u1++233zJp0iRSU1PxeDyMHTuWhQsXJtVpuQdt/WzYsAHY+tTrF198sc17/cILLzBkyBCcTieZmZmceeaZbNy4ManO9ddfT58+fRKvs8MOO4xXX301qU5b74lfffXVDt+X+fPnoygKr7zySqvn8swzz6AoCgsWLEiUbc/7bMv9s9lsVFdXJx1bsGBBoq+LFi1q9z06++yzE+8bxcXFDBs2jLq6OpxOZ6u/WyH2djItUIi91N///ncMw+DZZ59lyJAhrY5nZmbyn//8h6VLl/Lggw9y3XXXkZ2dDcDdd9/N8ccfzxlnnEE0GuXZZ5/llFNO4Y033uDYY4/d6jXPOeccPvzwQ+bNm0efPn0AePLJJxPHP/nkE+bMmcOdd95JZmYmADk5OVtt7+OPP+att97aoecP8OOPPzJ8+HAKCgq48sorcbvdPP/885xwwgm89NJLnHjiiQD4/X5GjhzJTz/9xMyZMzn44IOpqanhtddeY8OGDYm+bq6xsZFJkyZhtVp56623Eh+ompqaePjhh5k6dSrnnnsuPp+PRx55hAkTJvDll18yaNCgRBvTp0/nvffe46KLLmLgwIFomsacOXP45ptvdvg5t6WyspLDDjss8aEqKyuLt99+m1mzZtHU1MQll1zS7jZXrVrFq6++yimnnEK3bt2orKzkwQcfZNSoUSxdupT8/PxfbePoo49m2rRpSWX//Oc/qa+vTzw2TZPjjz+e+fPnM2vWLAYNGsTcuXP505/+xMaNG7nzzju3eY158+YxefJk8vLyuPjii8nNzeWnn37ijTfe4OKLL07U03WdiRMncthhh3HrrbfyzjvvcN111xGPx7nxxhsT9drz2jjxxBM56aSTiMfjLFiwgDlz5hAKhZJeE9srGAwyatQoNm7cyPnnn09RURGff/45V111FRUVFdx1113tbrMt2/ua++STTzjmmGPo0qUL1113HbFYjPvuu4/hw4fz1Vdf0bNnz62eq+s6kydP5v333+e0007j4osvxufzMW/ePJYsWUJxcfE2rz1o0CD++Mc/JpX95z//Yd68ea3qfvTRRzz33HP84Q9/wG63c9999zFx4kS+/PJL+vXrBzS/T4wcOZLU1FSuuOIKrFYrDz74IKNHj+ajjz5i2LBhSW3eeOONdOvWLaksIyNjm31uy+OPP86MGTM45JBDuOWWW6isrOTuu+/ms88+49tvvyUtLQ1o/nLhxBNPpGvXroRCIR5//HGmTJnCggULOPTQQ7fa/v/93/9t9div3ZfRo0dTWFjI008/nXifbPH0009TXFzM4YcfDmz/+2wLTdN46qmnkr7Ue+yxx3A4HITD4R26R2259tprW7UnxD7BFELslTIyMswuXboklU2fPt10u91JZddcc40JmK+//nqiLBgMJtWJRqNmv379zKOOOiqpHDCvu+460zRN86qrrjI1TTNfffXVrfbpscceMwFz9erVrY7Nnz/fBMz58+cnyoYNG2ZOmjQp6TqmaZpjxowxjzzyyKTzV69ebQLmY489ligbO3as2b9/fzMcDifKDMMwjzjiCLNHjx6JsmuvvdYEzJdffrlVvwzDaNW/cDhsjh492szOzjZLS0uT6sfjcTMSiSSV1dfXmzk5OebMmTMTZaFQyFRV1Tz//POT6rb1O2pLly5dzGOPPbZV+YUXXmhu+dY8a9YsMy8vz6ypqUkqP+2000yv15v4fbc8xxdeeKFVu26325w+fXricTgcNnVdT6qzevVq0263mzfeeOOv9h8wL7zwwlblxx57bNLf7auvvmoC5s0335xU7+STTzYVRWl1/zcXj8fNbt26mV26dDHr6+uTjrX8Xk2z+Z4D5kUXXZR0/NhjjzVtNptZXV2dKN+R10aLI444wuzTp0/icXvu90033WS63W5zxYoVSfWuvPJKU9M0c926daZp/vI6uO2221q12bdvX3PUqFGtrr89r7ktX7tDhgwxvV6vuWnTpkSdFStWmFar1ZwyZUqra2/u0UcfNQHzjjvuaHVs899LW9rzdw+YgLlo0aJE2dq1a02Hw2GeeOKJibITTjjBtNlsZllZWaKsvLzcTElJSXqfabkHX3311Vb7t7XX7wsvvJB0r6PRqJmdnW3269fPDIVCiXpvvPGGCZjXXnvtVq9RVVVlAubtt9+eKBs1alTS7/att94yAXPixIk7fF+uuuoq0263mw0NDUnXtlgsSX8b2/s+23L/pk6davbv3z9RHggEzNTUVPP0009Pur/tuUfTp09Pet9YsmSJqapq4m+5rf/nCLG3kmmBQuylfD5fYiRqW1pGjpqamhJlTqcz8e/6+noaGxsZOXLkVkdU7rnnHm655Rb+9a9/8Zvf/GYne97s5Zdf5quvvuLvf/97q2PZ2dmJaThbU1dXxwcffMBvf/tbfD4fNTU11NTUUFtby4QJE1i5cmViaslLL73EwIEDW33DCrSaUmMYBtOmTWPhwoW89dZbrb5l1zQtsX7NMAzq6uqIx+MMHTo06f4FAgEMw6BTp07bd0N2kGmavPTSSxx
2024-11-09 10:31:35 +04:00
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
2024-11-09 11:41:45 +04:00
"DecisionTreeRegressor:\n",
"Коэффициент детерминации R²: 1.00\n",
"Время обучения модели: 0.05 секунд\n",
"Среднеквадратичная ошибка: 0.00\n",
"Средняя абсолютная ошибка: 0.00\n"
2024-11-09 10:31:35 +04:00
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
"Кросс-валидация RMSE: 0.1802140124251679 \n",
2024-11-09 10:31:35 +04:00
"\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAC+00lEQVR4nOzdd3hUxf7H8ffZlt5JIfTemyBIE5CuYsNeQMAO9nKv99rL9f6uvSs27KKi2EFABEUsoIBITegljfRNsu2c3x8xCzEBCQQS4PN6nvCwc+bMzjnJbvLdmfmOYVmWhYiIiIiIiBwUW113QERERERE5Gig4EpERERERKQWKLgSERERERGpBQquREREREREaoGCKxERERERkVqg4EpERERERKQWKLgSERERERGpBQquREREREREaoGCKxERERERkVqg4EpERERE6tS2bduYNm1a8PGmTZt4++23665DIgdIwZXIEeTSSy8lMjKyrrshIiJSqwzDYPLkycyePZtNmzZx22238d1339V1t0RqzFHXHRCRfdu1axdvv/023333HQsXLqS0tJRRo0bRo0cPzj33XHr06FHXXRQRETkojRo14vLLL2fUqFEANGzYkG+//bZuOyVyAAzLsqy67oSIVO+9997j8ssvp7i4mObNm+Pz+cjIyKBHjx4sX74cn8/H+PHjmTp1Ki6Xq667KyIiclDS09PJycmhc+fORERE1HV3RGpM0wJF6qlFixZx8cUXk5KSwqJFi9i4cSPDhg0jNDSUX375hR07dnDBBRfw+uuvc+ONN1Y695FHHqFfv34kJCQQFhZGz549+fDDD6s8h2EY3HPPPcHHfr+fk08+mfj4eFatWhWss6+vwYMHA/Dtt99iGEaVTxpPOeWUKs8zePDg4HkVNm3ahGEYlebcA6xZs4azzz6b+Ph4QkND6dWrF59++mmVa8nPz+fGG2+kefPmhISE0LhxY8aNG0dOTs5e+7djxw6aN29Or169KC4uBsDr9XLXXXfRs2dPYmJiiIiIYODAgcyfP7/Kc2ZlZTFp0iSaNm2K3W4P3pP9mbrZvHlzTj311CrlU6ZMwTCMKuXbt29n4sSJJCcnExISQqdOnXj11Vcr1am4xuq+15GRkVx66aXBx7m5udxyyy106dKFyMhIoqOjGT16NMuXL//bvsO+fy6aN29eqa7b7ebmm2+mSZMmhISE0K5dOx555BH297O9n376iZNPPpm4uDgiIiLo2rUrTz75ZPB4xXTZDRs2MHLkSCIiIkhNTeW+++6r8hw1eW1UfNntdho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zpVXXknTpk354YcfuP3229m5cydPPPFEjduszv6+5r777jtOPvlkmjVrxt13343P5+O5556jf//+/PLLL7Rt23av5wYCAU499VTmzZvH+eefz/XXX09RURFz5sxh5cqVtGrVap/P3b17d26++eZKZW+88QZz5sypUnfBggVMnz6d6667jpCQEJ577jlGjRrFzz//TOfOnYHy94mBAwcSHR3NbbfdhtPp5MUXX2Tw4MEsWLCAPn36VGrzvvvuo0WLFpXK4uPj99nn6kybNo0JEyZw/PHH89BDD5GZmcmTTz7JokWL+O2334iNjQXKP1w488wzad68OaWlpUybNo2xY8eyePFievfuvdf2//GPf+z12N/dl8GDB9OkSRPefvvt4PtkhbfffptWrVrRt29fYP/fZyvY7XbeeuutSh/qvfbaa4SGhlJWVnZA96g6d911V5X2RI4IlojUS/Hx8VazZs0qlY0fP96KiIioVHbnnXdagPXZZ58Fy0pKSirV8Xq9VufOna2TTjqpUjlg3X333ZZlWdbtt99u2e12a+bMmXvt02uvvWYB1saNG6scmz9/vgVY8+fPD5b16dPHGj16dKXnsSzLGjJkiHXiiSdWOn/jxo0WYL322mvBsqFDh1pdunSxysrKgmWmaVr9+vWz2rRpEyy76667LMD66KOPqvTLNM0q/SsrK7MGDx5sJSUlWWlpaZXq+/1+y+PxVCrLy8uzkpOTrYkTJwbLSktLLZvNZl155ZWV6lb3PapOs2bNrFNOOaVK+eTJk62/vjVPmjTJatiwoZWTk1Op/Pzzz7diYmKC3++Ka/zggw+qtBsREWGNHz8++LisrMwKBAKV6mzcuNEKCQmx7rvvvr/tP2BNnjy5Svkpp5xS6ed25syZFmA98MADleqdffbZlmEYVe7/nvx+v9WiRQurWbNmVl5eXqVjFd9Xyyq/54B17bXXVjp+yimnWC6Xy8rOzg6WH8hro0K/fv2sjh07Bh/X5H7ff//9VkREhLVu3bpK9f75z39adrvd2rJli2VZu18HDz/8cJU2O3XqZA0aNKjK8+/Pa+6vr92ePXtaMTExVkZGRrDOunXrLKfTaY0dO7bKc+/p1VdftQDrscceq3Jsz+9LdWrycw9YgLVkyZJg2ebNm63Q0FDrzDPPDJadccYZlsvlstLT04NlO3bssKKioiq9z1Tcg19++WWv/dvb6/eDDz6odK+9Xq+VlJRkde7c2SotLQ3W+/zzzy3Auuuuu/b6HFlZWRZgPfLII8GyQYMGVfrefvnllxZgjRo16oDvy+23326FhIRY+fn5lZ7b4XBU+tnY3/fZivt3wQUXWF26dAmWu91uKzo62rrwwgsr3d+a3KPx48dXet9YuXKlZbPZgj/L1f3OEamvNC1QpJ4qKioKjkTtS8XIUWFhYbAsLCws+P+8vDwKCgoYOHDgXkdUnnnmGR566CGeeuopTj/99IPsebmPPvqIX375hf/+979VjiUlJQWn4exNbm4u33zzDeeeey5FRUXk5OSQk5PDrl27GDlyJOvXrw9OLZkxYwbdunWr8gkrUGVKjWmajBs3jh9//JEvv/yyyqfsdrs9uH7NNE1yc3Px+/306tWr0v1zu92YpklCQsL+3ZADZFkWM2bMYMyYMViWFbwPOTk5jBw
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"RandomForestRegressor:\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\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"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Коэффициент детерминации R²: 1.00\n",
2024-11-09 11:41:45 +04:00
"Время обучения модели: 3.28 секунд\n",
"Среднеквадратичная ошибка: 0.04\n",
"Средняя абсолютная ошибка: 0.03\n",
"Кросс-валидация RMSE: 0.13929243803791755 \n",
2024-11-09 10:31:35 +04:00
"\n"
]
},
{
"data": {
2024-11-09 11:41:45 +04:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADICUlEQVR4nOzdd3hUVf7H8fednkx6SIXQe2+KKKgIUkRclbWgKyisuiv2tvpb6+quu6trW/ta195W14oCoiii2BCRmgBS09tkkqn3/v7IZiQmIMFAKJ/X8+SBOffcM+feZGbyzTnnewzLsixERERERETkF7G1dQdEREREREQOBAquREREREREWoGCKxERERERkVag4EpERERERKQVKLgSERERERFpBQquREREREREWoGCKxERERERkVag4EpERERERKQVKLgSERERERFpBQquRERERKRNbd68mSeffDL2eMOGDTz77LNt1yGR3aTgSmQ/cvbZZ5OQkNDW3RAREWlVhmEwe/Zs3nvvPTZs2MDVV1/Nxx9/3NbdEmkxR1t3QER2rqysjGeffZaPP/6YhQsXUldXx8SJExkyZAinnnoqQ4YMaesuioiI/CLt27fn3HPPZeLEiQDk5OTw4Ycftm2nRHaDYVmW1dadEJHmvfDCC5x77rnU1NTQuXNnwuEwhYWFDBkyhG+//ZZwOMyMGTN45JFHcLlcbd1dERGRX6SgoIDS0lL69++P1+tt6+6ItJimBYrsoxYtWsRvfvMbsrOzWbRoEevXr2fcuHF4PB6++OILtm7dyrRp03jqqae47LLLGp17xx13cPjhh5Oenk5cXBzDhg3jlVdeafIchmFw0003xR5HIhGOO+440tLSWLFiRazOzr6OPvpoAD788EMMw2jyl8bJkyc3eZ6jjz46dl6DDRs2YBhGozn3AKtWreLXv/41aWlpeDwehg8fzhtvvNHkWiorK7nsssvo3LkzbrebDh06MH36dEpLS3fYv61bt9K5c2eGDx9OTU0NAKFQiBtuuIFhw4aRnJyM1+tl9OjRLFiwoMlzFhcXM2vWLDp27Ijdbo/dk12Zutm5c2eOP/74JuUXXnghhmE0Kd+yZQszZ84kKysLt9tNv379ePzxxxvVabjG5r7XCQkJnH322bHH5eXlXHnllQwYMICEhASSkpKYNGkS33777c/2HXb+c9G5c+dGdf1+P1dccQV5eXm43W569erFHXfcwa7+be/zzz/nuOOOIzU1Fa/Xy8CBA7nnnntixxumy65bt44JEybg9XrJzc3lT3/6U5PnaMlro+HLbrfTvn17zjvvPCorK2N1WnK/of5n9NJLL43dh+7du/O3v/0N0zRjdRpeB3fccUeTNvv379/oddOS19yTTz6JYRhs2LAhVvbee+9x+OGHEx8fT3JyMscffzzLly9v8rzNCQQC3HTTTfTs2ROPx0NOTg4nn3wyBQUFOz2vc+fOO/3Z2Z5hGFx44YU8++yz9OrVC4/Hw7Bhw1i4cGGTdr/55hsmTZpEUlISCQkJjB07ls8++6xRnYZ70NzX5s2bgR1PvX7llVeavdcvv/wyw4YNIy4ujnbt2vGb3/yGLVu2NKpz00030bdv39jr7LDDDuP1119vVKe598Qvvvhit+/LggULMAyD1157rcm1PPfccxiGweLFi2Nlu/I+23D/XC4XJSUljY4tXrw41tcvv/yyxffo7LPPjr1vdOvWjREjRlBeXk5cXFyTn1uRfZ2mBYrso/76179imiYvvPACw4YNa3K8Xbt2/Pvf/2bFihU8/PDD3HjjjWRmZgJwzz33cMIJJ3DmmWcSCoV44YUXOOWUU3jrrbeYPHnyDp/zt7/9LR9++CFz586lb9++ADz99NOx4x9//DGPPPIId911F+3atQMgKytrh+0tXLiQd955Z7euH+D777/niCOOoH379lxzzTV4vV5eeuklTjzxRF599VVOOukkAGpqahg9ejQrV65k5syZDB06lNLSUt544w02b94c6+v2qqqqmDRpEk6nk3feeSf2C1V1dTWPPvoo06ZN49xzz8Xn8/HYY48xYcIElixZwuDBg2NtzJgxg3nz5nHRRRcxaNAg7HY7jzzyCF9//fVuX3NzioqKOOyww2K/VGVkZPDuu+8ya9YsqqurufTSS1vc5rp163j99dc55ZRT6NKlC0VFRTz88MMcddRRrFixgtzc3J9t49hjj2X69OmNyv7xj39QUVERe2xZFieccAILFixg1qxZDB48mPfee4+rrrqKLVu2cNddd+30OebOncvxxx9PTk4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S+73LbfcYnm9XmvNmjWN6l1zzTWW3W63Nm7caFnWj6+D22+/vUmb/fr1s4466qgmz78rr7mfvnaHDRtmJScnW4WFhbE6a9assZxOpzV16tQmz729xx9/3AKsO++8s8mx7b8vzWnJzz1gAdaXX34ZK/vhhx8sj8djnXTSSbGyE0880XK5XFZBQUGsbOvWrVZiYmKj95mGe/DFF1/ssH87ev2+/PLLje51KBSyMjMzrf79+1t1dXWxem+99ZYFWDfccMMOn6O4uNgCrDvuuCNWdtRRRzX63r7zzjsWYE2cOHG378u1115rud1uq7KystFzOxyORj8bu/o+23D/pk2bZg0YMCBW7vf7raSkJOuMM85odH9bco9mzJjR6H1j+fLlls1mi/0sN/eZI7Kv0rRAkX2Uz+eLjUTtTMPIUXV1dawsLi4u9v+KigqqqqoYPXr0DkdU7rvvPm677TbuvfdefvWrX/3Cntf7z3/+wxdffMFf//rXJscyMzNj03B2pLy8nA8++IBTTz0Vn89HaWkppaWllJWVMWHCBNauXRubWvLqq68yaNCgJn9hBZpMqTFNk+nTp/PZZ5/xzjvvNPkru91uj61fM02T8vJyIpEIw4cPb3T//H4/pmmSnp6+azdkN1mWxauvvsq
2024-11-09 10:31:35 +04:00
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
2024-11-09 11:41:45 +04:00
"Lasso:\n",
2024-11-09 10:31:35 +04:00
"Коэффициент детерминации R²: 1.00\n",
2024-11-09 11:41:45 +04:00
"Время обучения модели: 0.02 секунд\n",
2024-11-09 10:31:35 +04:00
"Среднеквадратичная ошибка: 0.15\n",
2024-11-09 11:41:45 +04:00
"Средняя абсолютная ошибка: 0.09\n",
"Кросс-валидация RMSE: 0.14781881296011543 \n",
"\n"
2024-11-09 10:31:35 +04:00
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:697: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 2.283e+01, tolerance: 9.545e+00\n",
2024-11-09 10:31:35 +04:00
" model = cd_fast.enet_coordinate_descent(\n",
2024-11-09 11:41:45 +04:00
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\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",
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:697: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 2.283e+01, tolerance: 9.123e+00\n",
2024-11-09 10:31:35 +04:00
" model = cd_fast.enet_coordinate_descent(\n",
2024-11-09 11:41:45 +04:00
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:697: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 1.777e+01, tolerance: 7.834e+00\n",
" model = cd_fast.enet_coordinate_descent(\n",
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:697: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 1.716e+01, tolerance: 7.848e+00\n",
" model = cd_fast.enet_coordinate_descent(\n",
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:697: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 1.801e+01, tolerance: 7.706e+00\n",
2024-11-09 10:31:35 +04:00
" model = cd_fast.enet_coordinate_descent(\n",
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\sklearn\\linear_model\\_coordinate_descent.py:697: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations, check the scale of the features or consider increasing regularisation. Duality gap: 8.478e+00, tolerance: 4.075e+00\n",
" model = cd_fast.enet_coordinate_descent(\n"
]
},
{
"data": {
2024-11-09 11:41:45 +04:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADl0UlEQVR4nOzdd3xV5f3A8c855+6RvcMOCAoICIqCKAoKqFgVtU4QqNaKdWtrrdtWq23V/tzVqq1aZ+tWBIsb3IqoCASQkZCd3L3OeX5/hFwICSMYCOP7fr3ygnvGc557kntzv3me5/vVlFIKIYQQQgghhBA/id7VHRBCCCGEEEKIPYEEV0IIIYQQQgjRCSS4EkIIIYQQQohOIMGVEEIIIYQQQnQCCa6EEEIIIYQQohNIcCWEEEIIIYQQnUCCKyGEEEIIIYToBBJcCSGEEEIIIUQnkOBKCCGEEEIIITqBBFdCCCGEEKJLrVmzhsceeyz9eOXKlTz55JNd1yEhtpMEV0LsRs455xx8Pl9Xd0MIIYToVJqmMWvWLGbPns3KlSu56qqreP/997u6W0J0mK2rOyCE2LK6ujqefPJJ3n//fd577z2i0SgTJ05k2LBhnHrqqQwbNqyruyiEEEL8JKWlpZx77rlMnDgRgOLiYt55552u7ZQQ20FTSqmu7oQQon1PP/005557LqFQiF69epFMJlm3bh3Dhg3j66+/JplMMm3aNB566CEcDkdXd1cIIYT4ScrLy6mtrWXQoEF4vd6u7o4QHSbTAoXYRX344YecddZZFBUV8eGHH7JixQrGjx+Py+Xi008/paKigtNPP53HH3+cSy+9tNW5f/7znxk1ahS5ubm43W6GDx/O888/3+YamqZxww03pB+nUimOOeYYcnJy+O6779LHbOlr7NixALzzzjtomtbmL43HHntsm+uMHTs2fV6LlStXomlaqzn3AIsXL+bkk08mJycHl8vFiBEjePnll9s8l8bGRi699FJ69eqF0+mkW7duTJ06ldra2s32r6Kigl69ejFixAhCoRAAiUSC6667juHDh5OZmYnX62XMmDHMmzevzTWrq6uZOXMmPXr0wDCM9D3ZlqmbvXr14rjjjmuz/cILL0TTtDbb165dy4wZMygsLMTpdDJw4ED+8Y9/tDqm5Tm29732+Xycc8456cf19fVcccUVDB48GJ/PR0ZGBpMmTeLrr7/eat9hyz8XvXr1anVsOBzm8ssvp3v37jidTvr378+f//xntvVvex9//DHHHHMM2dnZeL1e9t9/f+6+++70/pbpssuXL2fChAl4vV5KSkq46aab2lyjI6+Nli/DMCgtLeW8886jsbExfUxH7jc0/4xecskl6fvQt29f/vSnP2FZVvqYltfBn//85zZtDho0qNXrpiOvucceewxN01i5cmV62+zZsxk1ahQej4fMzEyOO+44Fi1a1Oa67YnFYtxwww3ss88+uFwuiouLOemkkygvL9/ieb169driz87GNE3jwgsv5Mknn6R///64XC6GDx/Oe++916bdL7/8kkmTJpGRkYHP52PcuHEsWLCg1TEt96C9rzVr1gCbn3r9/PPPt3uvn3vuOYYPH47b7SYvL4+zzjqLtWvXtjrmhhtuYL/99ku/zg4++GBefPHFVse095746aefbvd9mTdvHpqm8d///rfNc3nqqafQNI358+ent23L+2zL/XM4HNTU1LTaN3/+/HRfP/vssw7fo3POOSf9vlFWVsbIkSOpr6/H7Xa3+bkVYlcn0wKF2EXddtttWJbF008/zfDhw9vsz8vL45///CffffcdDz74INdffz0FBQUA3H333Rx//PGceeaZJBIJnn76aU455RReffVVjj322M1e8xe/+AXvvPMOc+bMYb/99gPgX//6V3r/+++/z0MPPcSdd95JXl4eAIWFhZtt77333uP111/frucP8O233zJ69GhKS0v57W9/i9fr5dlnn+WEE07ghRde4MQTTwQgFAoxZswYvv/+e2bMmMEBBxxAbW0tL7/8MmvWrEn3dWNNTU1MmjQJu93O66+/nv5AFQgEePjhhzn99NM599xzCQaDPPLII0yYMIFPPvmEoUOHptuYNm0ac+fO5de//jVDhgzBMAweeughvvjii+1+zu2pqqri4IMPTn+oys/P54033mDmzJkEAgEuueSSDre5fPlyXnzxRU455RR69+5NVVUVDz74IIcffjjfffcdJSUlW23jqKOOYurUqa22/eUvf6GhoSH9WCnF8ccfz7x585g5cyZDhw5l9uzZXHnllaxdu5Y777xzi9eYM2cOxx13HMXFxVx88cUUFRXx/fff8+qrr3LxxRenjzNNk4kTJ3LwwQdz++238+abb3L99deTSqW46aab0sd15LVx4oknctJJJ5FKpZg/fz4PPfQQ0Wi01WtiW0UiEQ4//HDWrl3LL3/5S3r06MFHH33E1VdfTWVlJXfddVeH22zPtr7m3n//fY455hh69uzJ9ddfTzKZ5L777mP06NF8+umn7LPPPps91zRNjjvuON5++21OO+00Lr74YoLBIHPmzGHRokWUlZVt8dpDhw7l8ssvb7Xtn//8J3PmzGlz7LvvvsszzzzDRRddhNPp5L777mPixIl88sknDBo0CGh+nxgzZgwZGRlcddVV2O12HnzwQcaOHcu7777LyJEjW7V500030bt371bbcnJyttjn9jz22GNMnz6dAw88kFtvvZWqqiruvvtuPvzwQ7788kuysrKA5j8unHjiifTq1YtoNMpjjz3GlClTmD9/PgcddNBm2//Nb36z2X1buy9jx46le/fuPPnkk+n3yRZPPvkkZWVlHHLIIcC2v8+2MAyDJ554otUf9R599FFcLhexWGy77lF7rrvuujbtCbFbUEKIXVJOTo7q2bNnq23Tpk1TXq+31bZrr71WAeqVV15Jb4tEIq2OSSQSatCgQerII49stR1Q119/vVJKqauvvloZhqFefPHFzfbp0UcfVYBasWJFm33z5s1TgJo3b15628iRI9WkSZNaXUcppY444gh12GGHtTp/xYoVClCPPvpoetu4cePU4MGDVSwWS2+zLEuNGjVK9evXL73tuuuuU4D6z3/+06ZflmW16V8sFlNjx45VBQUFatmyZa2OT6VSKh6Pt9rW0NCgCgsL1YwZM9LbotGo0nVd/fKXv2x1bHvfo/b07NlTHXvssW22z5o1S2361jxz5kxVXFysamtrW20/7bTTVGZmZvr73fIcn3vuuTbter1eNW3atPTjWCymTNNsdcyKFSuU0+lUN91001b7D6hZs2a12X7ssce2+rl98cUXFaBuueWWVsedfPLJStO0Nvd/Y6lUSvXu3Vv17NlTNTQ0tNrX8n1VqvmeA+rXv/51q/3HHnuscjgcqqamJr19e14bLUaNGqX222+/9OOO3O+bb75Zeb1etWTJklbH/fa3v1WGYahVq1YppTa8Du644442bQ4cOFAdfvjhba6/La+5TV+7w4cPV5mZmWrdunXpY5YsWaLsdruaMmVKm2tv7B//+IcC1F//+tc2+zb+vrSnIz/3gALUZ599lt72448/KpfLpU488cT0thNOOEE5HA5VXl6e3lZRUaH8fn+r95mWe/Dpp59utn+be/0+99xzre51IpFQBQUFatCgQSoajaaPe/XVVxWgrrvuus1eo7q6WgHqz3/+c3rb4Ycf3up7+/rrrytATZw4cbvvy9VXX62cTqdqbGxsdW2bzdbqZ2Nb32db7t/pp5+uBg8enN4eDodVRkaGOuOMM1rd347co2nTprV631i0aJHSdT39s9ze7xwhdlUyLVCIXVQwGEyPRG1Jy8hRIBBIb3O73en/NzQ00NTUxJgxYzY7onLPPfdw66238re//Y2f/exnP7Hnzf7zn//w6aefctttt7XZV1BQkJ6Gszn19fX873//49RTTyUYDFJbW0ttbS11dXVMmDCBpUuXpqeWvPDCCwwZMqTNX1iBNlNqLMti6tSpLFiwgNdff73NX9kNw0ivX7Msi/r6elKpFCNGjGh1/8LhMJZlkZubu203ZDs
2024-11-09 10:31:35 +04:00
"text/plain": [
"<Figure size 1000x600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
2024-11-09 11:41:45 +04:00
"Ridge:\n",
"[18.32722123 3.0107936 12.6847593 2.87696207 15.52981848 3.48194544\n",
" 4.53098976 4.58990992 8.55918054 1.71694281 9.10822415 8.40752737\n",
" 2.55937943 17.00035263 8.5683403 15.2286672 16.48759661 2.64328782\n",
" 14.35748458 12.31290367 9.18390836 12.55374573 11.94125633 5.63035597\n",
" 2.42612661 12.21701737 5.89097154 2.70327352 2.71025583 5.88467691\n",
" 6.18495597 10.41194006 11.74058835 5.66495824 8.63860471 2.32680261\n",
" 4.25343744 5.2432205 1.14830738 1.72497365 16.34541382 15.46871272\n",
" 2.85962121 2.30344579 5.65496708 1.92032975 11.16954884 9.45732656\n",
" 3.02702328 8.7593053 16.29196128 9.14135635 11.67985565 2.93153544\n",
" 5.25600956 2.04094627 11.01252369 15.56616586 9.17103507 8.37553299\n",
" 2.00616581 2.1215906 2.9696912 4.12823341 4.16293466 4.06749422\n",
" 13.4970923 1.41292202 2.46751547 6.27820521 2.81149324 3.19217976\n",
" 15.48506179 5.80541842 9.63517226 10.44588766 1.72088075 19.0229673\n",
" 7.97420514 3.54378077 3.84646413 12.44758703 5.96056526 12.07860988\n",
" 1.72342917 5.51538196 2.28724266 3.70750799 6.35093254 11.23979499\n",
" 5.44158532 3.14961345 1.44146004 12.3629413 2.0369365 2.653985\n",
" 4.38821694 2.86791114 4.36303521 7.77605572 1.6223479 2.74020297\n",
" 2.92511993 3.96494258 1.44296481 6.5874516 10.2366303 12.2951812\n",
" 5.76265943 8.84323802 2.61169285 2.8650806 1.71448408 3.84116443\n",
" 10.27423177 2.13438867 9.71588695 5.87075642 6.55998543 4.01717677\n",
" 2.49161305 4.92076646 14.71785247 13.03487059 4.19637943 4.12280758\n",
" 9.53833488 4.36984794 2.30435943 2.35286733 9.83632877 1.71672432\n",
" 3.0790716 10.17767211 8.49247673 12.90571486 11.46719152 15.61927112\n",
" 13.87151069 12.22130308 1.60054527 2.2925814 8.77186654 3.14831016\n",
" 3.43659687 3.69635824 3.98611212 1.43750507 1.72273422 16.09455883\n",
" 5.52081983 12.01068013 2.91301752 14.32208531 3.15080861 8.2657655\n",
" 12.93407876 1.82653829 6.83263136 13.79486528 3.26175027 5.79487874\n",
" 11.94414316 12.98191364 14.47550566 5.32553162 10.28129845 17.37413521\n",
" 2.49622968 4.0074591 18.25192405 9.90052442 1.41478482 10.68641859\n",
" 9.11578983 17.58319025 3.5779263 2.80777855 3.72334889 9.48123556\n",
" 4.00253311 2.50851055 3.14725992 1.88480232 5.66582446 4.70190489\n",
" 2.29057556 3.4425988 16.47818856 2.61829716 3.04047372 3.65158322\n",
" 9.9697805 2.59514454 3.4319669 12.70570616 2.09688785 2.2249029\n",
" 5.64255812 10.51420545 9.81358192 5.25856628 9.47732466 9.10028075\n",
" 3.3194552 14.63525856 2.96062829 2.54155985 11.96331849 10.44282616\n",
" 3.70419454 14.53535116 1.43558882 5.48292316 14.79396409 5.17119502\n",
" 11.8387389 4.7281767 2.74742947 3.89148373 9.15393279 13.16546132\n",
" 9.74668684 3.00362808 17.70317768 11.05084012 9.46590928 4.65493814\n",
" 2.29413516 12.8961292 4.21372965 13.24823607 1.15054761 3.52127164\n",
" 4.00415437 14.2052063 1.88592957 18.87168748 2.35635132 13.21057174\n",
" 3.85142815 9.30387653 6.0170587 2.13101031 18.52228946 3.90643655\n",
" 7.94204889 2.86442427 16.04111643 3.47149236 10.65180971 2.81664073\n",
" 8.87805443 4.95091871 2.39311808 4.00678958 3.0577783 9.68889681\n",
" 2.92780012 9.77211671 2.12647041 8.37581821 2.58051123 5.77277617\n",
" 11.63880937 14.80034104 9.79433136 2.06559445 7.44744145 2.28989505\n",
" 6.71762151 12.68385509 2.98532405 9.78190262 4.03934245 14.97313774\n",
" 5.52721683 11.76555051 2.5411544 4.34622969 3.015949 8.07698343\n",
" 2.9374955 1.43564729 2.6248958 10.17953738 4.4233589 4.28687843\n",
" 6.12715504 3.57780437 14.26214236 10.10197497 7.57548007 4.29275405\n",
" 4.00647401 7.15121533 3.49070553 2.89562089 4.87079254 3.65335177\n",
" 1.98276004 12.21285304 3.80075313 1.60545458 10.9162067 5.88391728\n",
" 12.21920604 10.51094481 3.14849044 2.82357915 3.83022847 2.45718634\n",
" 9.32414072 2.14939107 2.91632385 8.52646224 2.61797119 4.98654586\n",
" 5.63720191 2.33693799 2.80849777 13.2974269 16.94742485 8.87053874\n",
" 2.51840058 15.18609256 4.41520206 8.17249811 3.50445626 15.83736599\n",
" 12.39381531 18.78524005 2.51074177 1.72609665 11.90800331 2.29281582\n",
" 4.37636745 8.77104754 8.85386525 3.71534887 9.0174119 3.83050688\n",
" 2.13860817 9.07451634 7.22838033 8.78669158 12.84500737 3.82724111\n",
" 11.60215407 9.62647822 3.18537771 4.38413336 3.38858381 11.07807859\n",
" 4.57342873 3.62605304 14.13067537 2.97358525 2.80824007 2.60264335\n",
" 2.85543948 10.42505871 11.17897442 4.9551702 1.43771498 4.5699936\n",
" 3.92533082 16.41889465 2.1709318 3.59116878 5.12679239 13.54208216\n",
" 6.4900012 2.70668023 5.41869081 9.4076443 3.35718526 3.88477761\n",
" 12.59921378 12.45690744 1.72196407 5.42504719 1.59211472 18.38656896\n",
" 12.05774811 1.81328658 2.60812509 2.70641661 14.63689067 10.1231312\n",
" 3.19718051 2.64870297 2.5922311 3.6667811 2.86745846 10.74807782\n",
" 7.34653952 3.0257806 1.26915484 3.90973225 1.14757191 15.30102494\n",
" 2.8388904 10.10477021 11.33861902 3.59179238 2.59204053 1.27139508\n",
" 12.75370589 11.83447587 2.2282411 1.14611468 2.44167877 2.58179507\n",
" 4.21622913 4.01778848 15.37576704 2.77757243 4.02608739 3.06976841\n",
" 13.03625384 2.82489613 19.18767186 3.72319075 2.07102046 4.80970213\n",
" 2.29713549 12.29220855 2.11357083 2.64336908 17.1744381 12.47864336\n",
" 11.69760866 2.00646536 2.04917214 16.41397044 9.16973529 12.95993122\n",
" 5.86877613 2.2468947 2.46717077 10.30357811 5.86081991 16.33232632\n",
" 8.25391682 16.93006673 2.04444389 2.76610558 4.33679861 2.98011323\n",
" 10.28818282 3.71219997 3.76573281 4.27291475 11.05404335 11.35363208\n",
" 12.65547427 15.35903285 3.10943919 4.11863028 2.04139352 3.44169724\n",
" 14.15719058 3.71007754 2.60839298 9.40803854 7.965787 5.72961304\n",
" 11.32356401 4.03859843 11.26824897 10.81440803 11.2887788 2.85992\n",
" 4.76882445 10.52593601 9.29548328 1.9204114 3.34590612 1.71958594\n",
" 2.01488465 9.13635507 3.03568843 5.24678712 2.86704456 17.41498095\n",
" 2.81527421 9.10469504 3.59359429 3.09393291 2.14025116 10.12501543\n",
" 2.35302801 10.84937595 13.63837995 11.09919982 5.96236267 15.14528057\n",
" 14.83369739 3.32998139 8.56563887 17.23015189 8.38381052 14.41813023\n",
" 15.36999687 2.74058072 14.3923915 2.71595583 10.22863526 7.36383598\n",
" 2.46400848 16.57392824 2.57781562 3.41926645 3.26749619 3.17635754\n",
" 2.57118678 14.75146822 3.90070952 2.5422388 3.25627717 6.15681406\n",
" 3.01206209 3.72110863 4.81275181 4.17754395 3.37907416 16.67083867\n",
" 2.96639092 8.31861646 19.5928038 2.59001085 11.73172582 2.53080388\n",
" 16.10939211 9.55281074 4.89147294 3.77039723 4.00053916 11.89179237\n",
" 2.56927393 15.1382684 2.57432876 16.86059854 12.26777022 2.21304502\n",
" 3.42883782 9.03406082 9.35980603 2.94004971 3.65403247 2.25539194\n",
" 2.51560397 1.86858304 3.90730135 2.90162905 11.33281109 3.07493559\n",
" 3.15457744 4.18287376 11.24267304 3.14165207 4.17388857 8.72188417\n",
" 1.85582758 2.20106313 4.05432171 8.87105029 8.25713815 7.4982045\n",
" 5.31099181 2.03252885 2.35380106 2.90833172 5.27744197 2.17862018\n",
" 10.59979178 11.67659365 2.86590528 2.09763582 9.82317744 2.90241731\n",
" 16.46282977 5.26638038 3.05806445 6.09927815 10.13120605 9.52575222\n",
" 4.25604601 3.14696785 2.00463723 5.04334856 3.84137804 14.25459319\n",
" 15.19262069 13.81042232 8.69746497 10.20117907 10.44016043 9.20203708\n",
" 8.71833373 12.93418185 9.28551261 17.96015086 2.19455615 3.91631872\n",
" 9.59075942 15.12231599 16.98194811 11.24424247 5.95905356 2.50041082\n",
" 4.47796826 19.95913906 12.81342182 5.63047224 2.69892087 5.43626143\n",
" 12.46475017 14.56422072 1.69619261 9.7081645 10.36442387 2.00400579\n",
" 11.90183282 11.45347863 3.04380204 4.39388834 18.2592019 10.16132727\n",
" 11.81919909 11.7150185 6.10742334 5.70336903 10.81056606 2.67050571\n",
" 14.3015793 5.20797712 4.19400473 2.44345517 12.926497 2.82576306\n",
" 3.52995951 9.08843842 10.79776541 2.1054964 11.8111336 5.53884535\n",
" 8.42241261 2.13193761 17.25708399 5.26646335 12.92020654 3.15086709\n",
" 14.42222551 11.24062861 15.18238417 8.29062296 19.18811532 10.75429813\n",
" 6.09171082 5.51060657 3.38282565 15.16024941 1.72118892 1.8841125\n",
" 15.75713605 10.00156083 1.82383918 15.17370047 2.76597514 12.97800436\n",
" 2.00911775 14.65916569 1.80074335 4.1277356 3.18348842 3.13512011\n",
" 2.86072911 14.03376005 5.90289278 1.41908883 15.16040243 3.21897769\n",
" 2.86368881 2.28948292 2.86396836 3.61071167 15.61242608 11.64838829\n",
" 4.85794237 3.15039497 2.57324047 11.66309006 3.67598898 2.53054004\n",
" 4.72814742 3.22933023 2.18218159 4.0139289 2.57884396 10.38283196\n",
" 3.43718286 3.36874742 4.27099997 2.10418287 2.29338051 20.29371949\n",
" 2.56748636 15.58927323 2.49890628 9.75547704 11.41633048 8.99062199\n",
" 2.91620698 2.00690127 9.84708901 2.20853016 1.6000834 2.36301124\n",
" 14.13997031 13.40623928 14.37827182 1.43777928 2.77851552 2.80842233\n",
" 4.06616654 3.85792485 9.37734454 3.89462333 4.04386877 4.12924573\n",
" 9.80364686 5.27666885 9.49792776 2.04498024 8.39342772 12.43929111\n",
" 3.33066377 10.10553764 11.50080194 14.15645551 3.53308783 7.23569727\n",
" 4.24063666 11.93546104 1.4341425 4.73309817 3.39423613 3.15689465\n",
" 2.48179631 3.90472832 4.1746958 18.57109419 9.08110507 2.97701524\n",
" 2.51687935 5.91769028 2.08750654 1.95767093 2.72859734 2.57603073\n",
" 11.05087488 2.83452257 12.74139073 10.27409885 2.09043978 15.38054965\n",
" 11.11194565 12.44357901 11.21301652 14.62181777 12.86121086 3.03239726\n",
" 1.14981215 10.95406398 8.09016551 11.30190626 8.72749802 11.48987906\n",
" 2.73349591 1.81491824 2.75723715 11.00142742 9.26644724 10.80686206\n",
" 5.47401715 1.5233777 2.68723787 12.21653822 11.67249167 11.73429027\n",
" 12.65422229 3.29490981 10.73473701 1.58175851 3.36260784 10.43117767\n",
" 4.74239496 9.31321539 1.53214498 9.36787631 3.17960608 11.33815015\n",
" 1.4944268 2.55231257 3.4338913 4.88079947 5.54352484 9.44755779\n",
" 5.47553143 2.2867321 3.35788652 3.03689751 13.69364835 2.16172887\n",
" 8.82221604 7.2449377 5.91869505 1.9524711 5.08923505 2.29223848\n",
" 15.42311306 4.14145758 11.86010012 3.02606217 3.87950275 5.41448186\n",
" 8.92537914 3.43315584 8.60694749 15.05033692 2.28146164 18.8219829\n",
" 4.04083324 11.22431607 4.54687533 5.77312967 16.68722862 12.3673102\n",
" 2.77424166 5.0751549 2.60859918]\n",
2024-11-09 10:31:35 +04:00
"id\n",
"1437 18.559999\n",
"2700 3.100000\n",
"3647 12.650000\n",
"2512 2.910000\n",
"2902 15.520000\n",
"Name: Close, dtype: float64\n",
"Коэффициент детерминации R²: 1.00\n",
2024-11-09 11:41:45 +04:00
"Время обучения модели: 0.00 секунд\n",
"Среднеквадратичная ошибка: 0.09\n",
"Средняя абсолютная ошибка: 0.06\n",
"Кросс-валидация RMSE: 0.08939608015848853 \n",
"\n"
2024-11-09 10:31:35 +04:00
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
2024-11-09 11:41:45 +04:00
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\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",
"c:\\Users\\K\\source\\repos\\AIM-PIbd-31-Ievlewa-M-D\\aimenv\\Lib\\site-packages\\sklearn\\linear_model\\_ridge.py:216: LinAlgWarning: Ill-conditioned matrix (rcond=7.51858e-17): result may not be accurate.\n",
2024-11-09 10:31:35 +04:00
" return linalg.solve(A, Xy, assume_a=\"pos\", overwrite_a=True).T\n"
]
},
{
"data": {
2024-11-09 11:41:45 +04:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADYTElEQVR4nOzdd3hUVfrA8e+9d/pMMklIDwktFKULiooICFJEbOhaFwQsu6JrWfWn7trddVdd22LDgr2svYOI2EFFRUWkhU5Ceple7r2/P2IGhgQkGPr7ecjzZM4999wzN5kh75xz3qOYpmkihBBCCCGEEOJ3Ufd0B4QQQgghhBBifyDBlRBCCCGEEEK0AQmuhBBCCCGEEKINSHAlhBBCCCGEEG1AgishhBBCCCGEaAMSXAkhhBBCCCFEG5DgSgghhBBCCCHagARXQgghhBBCCNEGJLgSQgghhBBCiDYgwZUQQgghhNijNmzYwJNPPpl4vGbNGp577rk91yEhdpIEV0LsQ84991w8Hs+e7oYQQgjRphRFYdq0acyePZs1a9Zw9dVX89lnn+3pbgnRapY93QEhxPZVV1fz3HPP8dlnn/Hpp58SCoUYM2YM/fv35w9/+AP9+/ff010UQgghfpeCggLOP/98xowZA0BeXh4ff/zxnu2UEDtBMU3T3NOdEEK07MUXX+T888/H7/fTsWNHYrEYmzZton///vzwww/EYjEmTZrEjBkzsNlse7q7QgghxO9SUlJCVVUVvXr1wu127+nuCNFqMi1QiL3UF198wTnnnENubi5ffPEFq1evZuTIkTgcDr755htKS0s588wzeeqpp7j88suTzr3rrrs48sgjadeuHU6nkwEDBvDKK680u4aiKNx0002Jx/F4nOOOO46MjAyWLFmSqLO9r2HDhgHw8ccfoyhKs08ax40b1+w6w4YNS5zXZM2aNSiKkjTnHmDp0qWceuqpZGRk4HA4GDhwIG+99Vaz51JXV8fll19Ox44dsdvttG/fnokTJ1JVVbXN/pWWltKxY0cGDhyI3+8HIBqNcsMNNzBgwAC8Xi9ut5shQ4Ywb968ZtesqKhg6tSpFBUVoWla4p7syNTNjh07cvzxxzcrv/jii1EUpVn5xo0bmTJlCjk5Odjtdnr27MkTTzyRVKfpObb0s/Z4PJx77rmJxzU1NVx55ZX07t0bj8dDamoqY8eO5YcffvjNvsP2fy86duyYVDcQCPDXv/6VwsJC7HY73bt356677mJHP9v76quvOO6440hPT8ftdtOnTx/uu+++xPGm6bKrVq1i9OjRuN1u8vPzueWWW5pdozWvjaYvTdMoKCjgggsuoK6uLlGnNfcbGn9HL7vsssR9KC4u5t///jeGYSTqNL0O7rrrrmZt9urVK+l105rX3JNPPomiKKxZsyZRNnv2bI488khcLhder5fjjz+exYsXN7tuS8LhMDfddBPdunXD4XCQl5fHKaecQklJyXbP69ix43Z/d7akKAoXX3wxzz33HN27d8fhcDBgwAA+/fTTZu1+//33jB07ltTUVDweDyNGjGDBggVJdZruQUtfGzZsALY99fqVV15p8V6//PLLDBgwAKfTSWZmJueccw4bN25MqnPTTTdx8MEHJ15nhx9+OG+88UZSnZbeE7/55pudvi/z5s1DURRef/31Zs/l+eefR1EU5s+fnyjbkffZpvtns9morKxMOjZ//vxEXxcuXNjqe3Tuuecm3je6dOnCoEGDqKmpwel0Nvu9FWJvJ9MChdhL/etf/8IwDF588UUGDBjQ7HhmZiZPP/00S5Ys4ZFHHuHGG28kOzsbgPvuu48TTjiBs88+m2g0yosvvshpp53GO++8w7hx47Z5zfPOO4+PP/6YOXPmcPDBBwPwzDPPJI5/9tlnzJgxg3vuuYfMzEwAcnJyttnep59+ynvvvbdTzx/g559/ZvDgwRQUFHDNNdfgdrv53//+x0knncSrr77KySefDIDf72fIkCH88ssvTJkyhUMOOYSqqireeustNmzYkOjrlurr6xk7dixWq5X33nsv8QdVQ0MDjz32GGeeeSbnn38+Pp+Pxx9/nNGjR/P111/Tr1+/RBuTJk3iww8/5JJLLqFv375omsaMGTP47rvvdvo5t6S8vJzDDz888UdVVlYW77//PlOnTqWhoYHLLrus1W2uWrWKN954g9NOO41OnTpRXl7OI488wtChQ1myZAn5+fm/2caxxx7LxIkTk8r+85//UFtbm3hsmiYnnHAC8+bNY+rUqfTr14/Zs2dz1VVXsXHjRu65557tXmPOnDkcf/zx5OXlcemll5Kbm8svv/zCO++8w6WXXpqop+s6Y8aM4fDDD+eOO+5g1qxZ3HjjjcTjcW655ZZEvda8Nk4++WROOeUU4vE48+fPZ8aMGYRCoaTXxI4KBoMMHTqUjRs3cuGFF1JUVMSXX37JtddeS1lZGffee2+r22zJjr7mPvvsM4477jg6dOjAjTfeSCwW48EHH2Tw4MF88803dOvWbZvn6rrO8ccfz9y5cznjjDO49NJL8fl8zJkzh8WLF9OlS5ftXrtfv3789a9/TSp7+umnmTNnTrO6n3zyCS+99BJ/+ctfsNvtPPjgg4wZM4avv/6aXr16AY3vE0OGDCE1NZWrr74aq9XKI488wrBhw/jkk08YNGhQUpu33HILnTp1SirLyMjYbp9b8uSTTzJ58mQOPfRQbr/9dsrLy7nvvvv44osv+P7770lLSwMaP1w4+eST6dixI6FQiCeffJIJEyYwf/58DjvssG22/3//93/bPPZb92XYsGEUFhby3HPPJd4nmzz33HN06dKFI444Atjx99kmmqbx7LPPJn2oN3PmTBwOB+FweKfuUUtuuOGGZu0JsU8whRB7pYyMDLNDhw5JZZMmTTLdbndS2fXXX28C5ttvv50oCwaDSXWi0ajZq1cv85hjjkkqB8wbb7zRNE3TvPbaa01N08w33nhjm32aOXOmCZirV69udmzevHkmY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600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import time\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import r2_score, mean_absolute_error\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.tree import DecisionTreeRegressor\n",
"from sklearn.ensemble import RandomForestRegressor\n",
"from sklearn.linear_model import Lasso\n",
"from sklearn.linear_model import Ridge\n",
"from sklearn.metrics import mean_squared_error\n",
"from sklearn.model_selection import cross_val_score\n",
"\n",
"# Разделение данных на обучающую и тестовую выборки. Удаляем целевую переменную\n",
"#y = feature_matrix['Close'] #- целевая переменная\n",
"#X = feature_matrix.drop('Close', axis=1)\n",
"\n",
"# Удаление строк с NaN\n",
"feature_matrix = feature_matrix.dropna()\n",
"val_feature_matrix = val_feature_matrix.dropna()\n",
"test_feature_matrix = test_feature_matrix.dropna()\n",
"\n",
"# Разделение данных на обучающую и тестовую выборки\n",
"y_train = feature_matrix['Close']\n",
"X_train = feature_matrix.drop('Close', axis=1)\n",
"y_test = test_feature_matrix['Close']\n",
"X_test = test_feature_matrix.drop('Close', axis=1)\n",
"\n",
2024-11-09 11:41:45 +04:00
"print(X_train.head())\n",
"\n",
2024-11-09 10:31:35 +04:00
"# Обучение модели\n",
"model1 = LinearRegression()\n",
2024-11-09 11:05:06 +04:00
"#Линейная регрессия — это простая модель, которая пытается установить связь между двумя переменными, рисуя прямую линию на графике. \n",
"# Она прогнозирует значение зависимой переменной (Y) на основе одной или нескольких независимых переменных (X).\n",
2024-11-09 10:31:35 +04:00
"model2 = DecisionTreeRegressor()\n",
2024-11-09 11:05:06 +04:00
"#Это модель, которая принимает решения, дробя данные на «ветви», как дерево. На каждом уровне дерева модель выбирает, \n",
"# какой признак (фактор) использовать для разделения данных.\n",
"model3 = RandomForestRegressor(n_estimators=100) \n",
"#Случайный лес — это ансамблевая модель, которая использует множество деревьев решений. \n",
"# Вместо того чтобы полагаться на одно дерево, она комбинирует результаты нескольких деревьев, чтобы получить более точные предсказания.\n",
2024-11-09 10:31:35 +04:00
"model4 = Lasso(alpha=0.1)\n",
2024-11-09 11:05:06 +04:00
"#Lasso регрессия — это разновидность линейной регрессии с добавлением регуляризации. \n",
"# Она помогает избежать переобучения модели, уменьшая влияние некоторых признаков.\n",
2024-11-09 10:31:35 +04:00
"model5 = Ridge(alpha=0.1)\n",
2024-11-09 11:05:06 +04:00
"#Ridge регрессия похожа на Lasso, но вместо полного исключения некоторых переменных она уменьшает значения всех коэффициентов.\n",
2024-11-09 10:31:35 +04:00
"\n",
"print('\\nLinearRegression:')\n",
"start_time = time.time()\n",
"model1.fit(X_train, y_train)\n",
2024-11-09 11:05:06 +04:00
"#Метод fit обучает модель на обучающем наборе данных, состоящем из X_train (набор данных) и y_train (целевая переменная).\n",
2024-11-09 10:31:35 +04:00
"\n",
"# Время обучения модели\n",
"train_time = time.time() - start_time\n",
"\n",
"y_predict = model1.predict(X_test)\n",
"\n",
"mse = mean_squared_error(y_test, y_predict, squared=False)\n",
2024-11-09 11:05:06 +04:00
"# Этот показатель показывает, насколько в среднем наши предсказания отклоняются от фактических значений. Чем меньше RMSE, тем лучше модель.\n",
2024-11-09 10:31:35 +04:00
"r2 = r2_score(y_test, y_predict)\n",
2024-11-09 11:05:06 +04:00
"# Коффициент детерминации - показывает, насколько модель объясняет разброс значений в наборе данных\n",
2024-11-09 10:31:35 +04:00
"mae = mean_absolute_error(y_test, y_predict)\n",
2024-11-09 11:05:06 +04:00
"# Измеряет среднее расстояние между предсказанными значениями и фактическими значениями, игнорируя направление ошибок.\n",
2024-11-09 10:31:35 +04:00
"print(f'Коэффициент детерминации R²: {r2:.2f}')\n",
"print(f'Время обучения модели: {train_time:.2f} секунд')\n",
"print(f'Среднеквадратичная ошибка: {mse:.2f}')\n",
"print(f'Средняя абсолютная ошибка: {mae:.2f}')\n",
"# Кросс-валидация\n",
"scores = cross_val_score(model1, X_train, y_train, cv=5, scoring='neg_mean_squared_error')\n",
"rmse_cv = (-scores.mean())**0.5\n",
"print(f\"Кросс-валидация RMSE: {rmse_cv} \\n\")\n",
2024-11-09 11:05:06 +04:00
"# Здесь мы используем метод cross_val_score для оценки модели с помощью кросс-валидации. \n",
"# cv=5 означает, что мы будем разбивать наш обучающий набор на 5 частей (фолдов) и \n",
"# использовать каждую часть для тестирования модели, обученной на остальных частях. \n",
"# (по сути разбивка на выборки но несколько раз с использованием разных разбиений, чтобы получить норм оценку)\n",
"\n",
"# Параметр scoring='neg_mean_squared_error' говорит о том, что мы хотим получать отрицательные значения среднеквадратичной ошибки, \n",
"# так как cross_val_score возвращает лучшие результаты как положительные значения. Таким образом, использование отрицательного \n",
"# значения MSE позволяет \"перевернуть\" метрику так, чтобы более низкие значения (более точные предсказания) приводили \n",
"# к более высоким (в терминах абсолютного значения) результатам.\n",
"\n",
"# После этого мы берем среднее значение отрицательной MSE и берем его корень (RMSE) \n",
"# для получения усредненной оценки ошибки модели через кросс-валидацию.\n",
2024-11-09 10:31:35 +04:00
"\n",
"\n",
"# Визуализация результатов\n",
"plt.figure(figsize=(10, 6))\n",
"plt.scatter(y_test, y_predict, alpha=0.5)\n",
"plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2)\n",
"plt.xlabel('Фактическая цена')\n",
"plt.ylabel('Прогнозируемая цена')\n",
"plt.title('Фактическая цена по сравнению с прогнозируемой')\n",
"plt.show()\n",
"\n",
"#//////////////////////////\n",
"\n",
"print('\\nDecisionTreeRegressor:')\n",
"start_time = time.time()\n",
"model2.fit(X_train, y_train)\n",
"\n",
"# Время обучения модели\n",
"train_time = time.time() - start_time\n",
"\n",
"y_predict = model2.predict(X_test)\n",
"\n",
"mse = mean_squared_error(y_test, y_predict, squared=False)\n",
"r2 = r2_score(y_test, y_predict)\n",
"mae = mean_absolute_error(y_test, y_predict)\n",
"print(f'Коэффициент детерминации R²: {r2:.2f}')\n",
"print(f'Время обучения модели: {train_time:.2f} секунд')\n",
"print(f'Среднеквадратичная ошибка: {mse:.2f}')\n",
"print(f'Средняя абсолютная ошибка: {mae:.2f}')\n",
"# Кросс-валидация\n",
"scores = cross_val_score(model2, X_train, y_train, cv=5, scoring='neg_mean_squared_error')\n",
"rmse_cv = (-scores.mean())**0.5\n",
"print(f\"Кросс-валидация RMSE: {rmse_cv} \\n\")\n",
"\n",
"# Анализ важности признаков\n",
"feature_importances = model2.feature_importances_\n",
"feature_names = X_train.columns\n",
"# Визуализация результатов\n",
"plt.figure(figsize=(10, 6))\n",
"plt.scatter(y_test, y_predict, alpha=0.5)\n",
"plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2)\n",
"plt.xlabel('Фактическая цена')\n",
"plt.ylabel('Прогнозируемая цена')\n",
"plt.title('Фактическая цена по сравнению с прогнозируемой')\n",
"plt.show()\n",
"\n",
"#//////////////////////////\n",
"\n",
"print('\\nRandomForestRegressor:')\n",
"start_time = time.time()\n",
"model3.fit(X_train, y_train)\n",
"\n",
"# Время обучения модели\n",
"train_time = time.time() - start_time\n",
"\n",
"y_predict = model3.predict(X_test)\n",
"\n",
"mse = mean_squared_error(y_test, y_predict, squared=False)\n",
"r2 = r2_score(y_test, y_predict)\n",
"mae = mean_absolute_error(y_test, y_predict)\n",
"print(f'Коэффициент детерминации R²: {r2:.2f}')\n",
"print(f'Время обучения модели: {train_time:.2f} секунд')\n",
"print(f'Среднеквадратичная ошибка: {mse:.2f}')\n",
"print(f'Средняя абсолютная ошибка: {mae:.2f}')\n",
"# Кросс-валидация\n",
"scores = cross_val_score(model3, X_train, y_train, cv=5, scoring='neg_mean_squared_error')\n",
"rmse_cv = (-scores.mean())**0.5\n",
"print(f\"Кросс-валидация RMSE: {rmse_cv} \\n\")\n",
"\n",
"# Анализ важности признаков\n",
"feature_importances = model3.feature_importances_\n",
"feature_names = X_train.columns\n",
"# Визуализация результатов\n",
"plt.figure(figsize=(10, 6))\n",
"plt.scatter(y_test, y_predict, alpha=0.5)\n",
"plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2)\n",
"plt.xlabel('Фактическая цена')\n",
"plt.ylabel('Прогнозируемая цена')\n",
"plt.title('Фактическая цена по сравнению с прогнозируемой')\n",
"plt.show()\n",
"\n",
"#//////////////////////////\n",
"\n",
"print('\\nLasso:')\n",
"start_time = time.time()\n",
"model4.fit(X_train, y_train)\n",
"\n",
"# Время обучения модели\n",
"train_time = time.time() - start_time\n",
"\n",
"y_predict = model4.predict(X_test)\n",
"\n",
"mse = mean_squared_error(y_test, y_predict, squared=False)\n",
"r2 = r2_score(y_test, y_predict)\n",
"mae = mean_absolute_error(y_test, y_predict)\n",
"print(f'Коэффициент детерминации R²: {r2:.2f}')\n",
"print(f'Время обучения модели: {train_time:.2f} секунд')\n",
"print(f'Среднеквадратичная ошибка: {mse:.2f}')\n",
"print(f'Средняя абсолютная ошибка: {mae:.2f}')\n",
"# Кросс-валидация\n",
"scores = cross_val_score(model4, X_train, y_train, cv=5, scoring='neg_mean_squared_error')\n",
"rmse_cv = (-scores.mean())**0.5\n",
"print(f\"Кросс-валидация RMSE: {rmse_cv} \\n\")\n",
"\n",
"# Визуализация результатов\n",
"plt.figure(figsize=(10, 6))\n",
"plt.scatter(y_test, y_predict, alpha=0.5)\n",
"plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2)\n",
"plt.xlabel('Фактическая цена')\n",
"plt.ylabel('Прогнозируемая цена')\n",
"plt.title('Фактическая цена по сравнению с прогнозируемой')\n",
"plt.show()\n",
"\n",
"#//////////////////////////\n",
"\n",
"print('\\nRidge:')\n",
"start_time = time.time()\n",
"model5.fit(X_train, y_train)\n",
"\n",
"# Время обучения модели\n",
"train_time = time.time() - start_time\n",
"\n",
"y_predict = model5.predict(X_test)\n",
"print(y_predict)\n",
"print(y_test.head())\n",
"\n",
"mse = mean_squared_error(y_test, y_predict, squared=False)\n",
"r2 = r2_score(y_test, y_predict)\n",
"mae = mean_absolute_error(y_test, y_predict)\n",
"print(f'Коэффициент детерминации R²: {r2:.2f}')\n",
"print(f'Время обучения модели: {train_time:.2f} секунд')\n",
"print(f'Среднеквадратичная ошибка: {mse:.2f}')\n",
"print(f'Средняя абсолютная ошибка: {mae:.2f}')\n",
"# Кросс-валидация\n",
"scores = cross_val_score(model5, X_train, y_train, cv=5, scoring='neg_mean_squared_error')\n",
"rmse_cv = (-scores.mean())**0.5\n",
"print(f\"Кросс-валидация RMSE: {rmse_cv} \\n\")\n",
"\n",
"# Визуализация результатов\n",
"plt.figure(figsize=(10, 6))\n",
"plt.scatter(y_test, y_predict, alpha=0.5)\n",
"plt.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], 'k--', lw=2)\n",
"plt.xlabel('Фактическая цена')\n",
"plt.ylabel('Прогнозируемая цена')\n",
"plt.title('Фактическая цена по сравнению с прогнозируемой')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"На основании представленных данных можно сделать несколько выводов:\n",
"\n",
"1. **Общие выводы по точности**\n",
"В данном случае среднеквадратичные ошибки близки или равны нулю, к тому же коэффициент детерминации 1.00 - это говорит либо о том, что модель обучается идеально, либо о том, что модель запомнила значения. Поэтому я проверила ее на нескольких моделях и отдельно вывела для сравнения список предсказанной целевой переменной и тестовую(с которой сравниваем) целевую переменную - результаты оказались весьма близки к тестовым показателям, но не точь в точь, что, скорее всего, говорит о том, что модель все же обучается идеально...\n",
"**Среднеквадратичная ошибка (RMSE) и Средняя абсолютная ошибка (MAE)**\n",
"* LinearRegression: MAE = 0.04 и RMSE = 0.05 указывает на весьма точные предсказания.\n",
"* DecisionTreeRegressor: MAE и RMSE равны 0.00, что может указывать на чрезмерное подстраивание модели к обучающим данным.\n",
"* RandomForestRegressor: MAE = 0.02 и RMSE = 0.03 показывают высокую точность прогнозов, но не столь идеальные результаты, как у дерева решений.\n",
"* Lasso и Ridge: Обе модели имеют MAE = 0.10 и 0.04 соответственно, что также предполагает приемлемую точность, но с возможностью недопущения переобучения.\n",
"2. **Переобучение модели**\n",
"Высокие значения R² и нулевые ошибки (MAE и RMSE) у DecisionTreeRegressor могут указывать на переобучение модели. Это значит, что модель отлично работает на обучающих данных, но может быть неэффективной на новых, невидимых данных.\n",
"Для линейной регрессии и других регуляризованных моделей (например, Lasso и Ridge) результаты более сбалансированы, что делает их менее подверженными переобучению.\n",
"3. **Производительность модели**\n",
2024-11-09 11:41:45 +04:00
"Время обучения у моделей достаточно быстрое, что свидетельствует об их высокой производительности.\n",
2024-11-09 10:31:35 +04:00
"4. **Соответствие бизнес-целям**\n",
"Учитывая высокую точность модели и ее способность к обучению на исторических данных, можно использовать ее для прогнозирования цен на акции. Однако рекомендуется дополнительно проверять результаты на тестовых данных, чтобы избежать проблем с переобучением."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "aimenv",
"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.12.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}