2268 lines
634 KiB
Plaintext
2268 lines
634 KiB
Plaintext
|
{
|
|||
|
"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",
|
|||
|
"execution_count": null,
|
|||
|
"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"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 1,
|
|||
|
"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",
|
|||
|
"execution_count": null,
|
|||
|
"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",
|
|||
|
"execution_count": 3,
|
|||
|
"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",
|
|||
|
"execution_count": 4,
|
|||
|
"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",
|
|||
|
"execution_count": 5,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA+0AAAIjCAYAAAB20vpjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABeK0lEQVR4nO3dd3gU1eL/8U8CaRASSkgDAqGGXiIlIEVAQlEEohRBQVC8EJSmIipdRUClKIJ4KRYUwYKKgoSqYqgCgpSL3mBQkuDCTQKkQub3B9/sjyUJkJDsTuD9ep59ZGfOnHNmZmfjZ2fmjJNhGIYAAAAAAIDpODu6AwAAAAAAIHeEdgAAAAAATIrQDgAAAACASRHaAQAAAAAwKUI7AAAAAAAmRWgHAAAAAMCkCO0AAAAAAJgUoR0AAAAAAJMq6egOAAAAFHdpaWk6d+6cSpYsKV9fX0d3BwBwG+FMOwAAKHZGjhype++916F92LRpk3r27KmyZcvKw8NDlSpV0ujRox3aJxSuDRs2yNPTU//884+juwLgDkZoB4AisGLFCjk5OVlf7u7uql27tkaNGqWEhARHdw8o1mJiYvTvf/9bL7zwgsP68M477yg8PFxJS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2vr6+atSoET+2AnAYRo8HADvKDtgVKlSQJP33v//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/f7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p8uTJ1s9ituzPVlRUlM6fP6/nn38+x77NLrN3716dOXNGI0eOtCnTo0cPhYSE6Ntvv7VZLisry7qNDhw
|
|||
|
"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+Pl5fffWVs0sDSqWsrCwtX75cffr0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ClTpqhPnz566qmndP78ec2fP19t27bVgQMHVLVqVbtlRowYoTZt2kiSVq9erS+//NJm/siRI62XJjz77LOKj4/XO++8owMHDmjnzp2qUKFCnuuhMFJSUvK8vjUnJ0c9e/bUjh07NGLECDVq1Eg//fSTZs+erf/85z9as2ZNocZZunSp/vrXv+qtt97SgAED8mxzu/Uxd+5c9ezZUwMHDlRmZqZWrFihxx9/XF9//bW6d+9ubRcdHa1p06apdevWmj59uipWrKjdu3dr06ZNeuihhyTdCJRDhw5V48aNNWnSJFWtWlUHDhzQunXrrPXlrvv77rtPMTExOnv2rObOnaudO3fabVMfHx/Nnj1bkvTrr79q7ty56tatm3755Zc8t32uH374QRaLRS1atChw/S1cuFDu7u6S8v75L0ytt7pw4YL27t2r8uXLa/To0apbt67WrFmjESNG6MKFC3rppZcKvQ1uNnv2bPn4+Ei6sZ/c7E6/Mwrj8uXLatOmjeLi4jR06FC1bNlSycnJWrt2rX799VdrLbfatm2b/vWvf+Xbb58+fRQSEqKYmBjt2rVL8+bN0//+9z99+OGH1jZPPfWUPvjgAz322GOaMGGCdu/erZiYGMXFxdn9PLdp00YjRoxQTk6Ojhw5ojlz5ujMmTP5/rEnKytLvXv3VkJCgnbu3KmAgIB8az158mSef3TJFR4eXuh9GACKjQEAKHZLly41JBkbNmwwzp8/b/zyyy/GihUrjOrVqxtubm7Gr7/+ahiGYVy7ds24fv26zbLx8fGGq6urMX36dOu0JUuWGJKMt99+226snJwc63KSjFmzZtm1ady4sdGuXTvr+82bNxuSjJo1axppaWnW6StXrjQkGXPnzrX2Xb9+faNLly7WcQzDMK5cuWKEhoYaDz74oN1YrVu3Npo0aWJ9f/78eUOSMXXqVOu006dPG+XKlTNef/11m2V/+ukno3z58nbTT5w4YUgyPvjgA+u0qVOnGjf/Gtu+fbshyVi+fLnNsuvWrbObXrt2baN79+52tY8ePdq49VfjrbW/+OKLhq+vrxEeHm6zTj/66CPDxcXF2L59u83yixYtMiQZO3futBvvZu3atbP298033xjly5c3JkyYkGfbO1kfhnFjO90sMzPTaNKkidGxY0ebvlxcXIxHHnnE7mcxd5unpKQYHh4eRkREhHH16tU822RmZhq+vr5GkyZNbNp8/fXXhiTjlVdesU4bPHiwUbt2bZt+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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nzp15fsb27dvnOf60adPs2n788ccKDw+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++8owMHDmjnzp2qUKFCnuuhMFJSUvK8vjUnJ0c9e/bUjh07NGLECDVq1Eg//fSTZs+erf/85z9as2ZNocZZunSp/vrXv+qtt97SgAED8mxzu/Uxd+5c9ezZUwMHDlRmZqZWrFihxx9/XF9//bW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x888/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"
|
|||
|
}
|
|||
|
],
|
|||
|
"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",
|
|||
|
"execution_count": 6,
|
|||
|
"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+VfQf1xkZCR69+4NBwcHGBoaws7ODu7u7uCPYOVOQd5ez58/jy5dusDGxgZGRkZwcHBA+/bt87ssnVPp6ifbVq1ahR49ekjvjYyMUKJECTRt2hRjxoyBnZ2dLiZDRFlkZGTA0tISS5cuRYMGDfDzzz/j1q1bCAkJye/S6CPp27cvnj9/jhkzZiAiIgLt2rXDnTt34ODgkN+l/eecPn0azZs3h7W1NQYOHIhKlSpBpVLB0tIStWrVyu/yPgkFdXvduXMnOnbsiAoVKqBfv34oXbo0AMDW1hbVqlXL19p0zUDXI5wwYQJcXFyQnJyMEydOIDg4GH/88QeuXbuGwoUL63pyRIqmr6+PoKAgdOvWDZmZmbCwsMDevXvzuyz6iIYMGYKGDRvCxcUFADB06NB8/xL9L0pNTUWPHj1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0acyfPx/Pnz/HmjVrclX729SvXx99+vRBZmYmrl27hrlz5+Lhw4c4fvy41GbevHlo1aoV/P39kZqaio0bN6JDhw7Ys2cPfH19cxx3+/btERoaim7duuGLL77A4cOHMWrUKNy7d08jxOfVq1ev4OnpiQcPHqBv374oUaIETp06hVGjRuHRo0eym3myu3PnDpYvX66TOrLLy37xY/vxxx9RsWJFvH79Wvon39bWFr169cpxmNevX6Nhw4a4c+cOAgMD4eLigi1btqB79+6Ij4/HoEGDAABPnz7FX3/9hR9//BHt2rXDsGHDcP78ecycORPXrl3D3r17oVKp0LVrV6xZswb79u2T/bMdExODQ4cOYdy4ce89X9xe/0f9nZiSkoJ9+/Zh1qxZMDY2xsSJE/M8D0+fPsWJEydw4sQJ9OzZE25ubjh48KDWZfXNN99g9erV+OqrrzBs2DCcOXMGU6dOxc2bNzW+nyMjI9GxY0d8++23CAgIwMqVK9GhQweEhISgSZMmWmuJjo5Gs2bNUKFCBWzevBkGBm9i2r9ZzhqEjqxcuVIAEAcOHBBPnjwR0dHRYuPGjaJo0aLCxMRE/PPPP0IIIZKTk0VGRoZs2KioKGFkZCQmTJggdVuxYoUAIGbPnq0xrczMTGk4AGLmzJkabSpXriw8PT2l94cPHxYARPHixUVCQoLUffPmzQKAmDdvnjTusmXLCm9vb2k6Qgjx6tUr4eLiIpo0aaIxLQ8PD1GlShXp/ZMnTwQAMW7cOKnbvXv3hL6+vpg8ebJs2KtXrwoDAwON7pGRkQKAWL16tdRt3LhxIusqO378uAAg1q9fLxs2JCREo7uzs7Pw9fXVqH3AgAEi+2aQvfYRI0YIW1tb4ebmJluma9euFXp6euL48eOy4ZcsWSIAiJMnT2pMLytPT09pfHv37hUGBgZi2LBhGu1evXq
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 640x480 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iV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fP0erVq3QvXt3fPPNN7C2tkZUVBRatGiB4sWLY8KECTA3N8f9+/exa9cuWd25+aydPHkSe/fuxbBhwwAAs2fPRtu2bTFu3DisWLECQ4cORUxMDObNm4f+/fvjyJEjsvHzuo3NyqlTp7Br1y4MHToUJiYmWLJkCbp06YKHDx9KmebKlSto2bIlbG1t4evri9TUVEybNk36vskVUYDWrl0rAIhDhw6JZ8+eiYiICLFlyxZRrFgxYWBgIP79918hhBCJiYkiNTVVNm54eLjQ09MT06ZNk9rWrFkjAIgFCxaozSstLU0aD4D46aef1PpUqVJFuLi4SM+PHj0qAIgSJUqIuLg4qX3btm0CgFi8eLE07fLlywt3d3dpPkII8fr1a1GmTBnRvHlztXk5OzuLqlWrSs+fPXsmAIgpU6ZIbffv3xfa2tpi5syZsnGvX78udHR01NrDwsIEALF+/XqpbcqUKSLjaj558qQAIDZt2iQbNyAgQK29VKlSok2bNmq1Dxs2TGR+62Sufdy4ccLKyko4OjrKXtONGzcKLS0tcfLkSdn4K1euFADE6dOn1eaXkYuLizS9P//8U+jo6IgxY8ao9Xv9+rVa2+zZs4VKpRIPHjzQOO3My5AuPj5emJubCy8vL1l7ZGSkMDMzk7X36dNHGBkZZVl/VFSU0NXVFS1atJC9p5ctWyYAiDVr1siWFYD4+eefpbakpCRRs2ZNYWVlJZKTk4UQ/3ufHj16VOpXr1490apVK7Vlyvx+iIqKEiYmJlL
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 640x480 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnYAAAHHCAYAAAAyKhW0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABbDUlEQV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2bNggAIhDhw6Jp0+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"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 6,
|
|||
|
"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",
|
|||
|
"execution_count": 7,
|
|||
|
"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",
|
|||
|
"df['Close_Disc'] = pd.cut(df['Close'], bins=bins, labels=labels, include_lowest=True)\n",
|
|||
|
"\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",
|
|||
|
"execution_count": 8,
|
|||
|
"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",
|
|||
|
"\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",
|
|||
|
"execution_count": 9,
|
|||
|
"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",
|
|||
|
"execution_count": 10,
|
|||
|
"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": [
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:36: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
|
|||
|
"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",
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:36: SettingWithCopyWarning: \n",
|
|||
|
"A value is trying to be set on a copy of a slice from a DataFrame\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",
|
|||
|
" df[['Volume_Change']].loc[df[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_df\n",
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:37: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
|
|||
|
"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",
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:37: SettingWithCopyWarning: \n",
|
|||
|
"A value is trying to be set on a copy of a slice from a DataFrame\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",
|
|||
|
" X_resampled[['Volume_Change']].loc[X_resampled[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_train\n",
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:38: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
|
|||
|
"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",
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:38: SettingWithCopyWarning: \n",
|
|||
|
"A value is trying to be set on a copy of a slice from a DataFrame\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",
|
|||
|
" X_test[['Volume_Change']].loc[X_test[\"Volume_Change\"] == 0, \"Volume_Change\"] = median_Volume_Change_test\n",
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:39: FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!\n",
|
|||
|
"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",
|
|||
|
"C:\\Users\\K\\AppData\\Local\\Temp\\ipykernel_1752\\2904461267.py:39: SettingWithCopyWarning: \n",
|
|||
|
"A value is trying to be set on a copy of a slice from a DataFrame\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",
|
|||
|
" 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",
|
|||
|
"\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",
|
|||
|
"execution_count": 11,
|
|||
|
"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",
|
|||
|
"execution_count": 12,
|
|||
|
"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",
|
|||
|
"\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",
|
|||
|
"execution_count": 13,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Empty DataFrame\n",
|
|||
|
"Columns: [Date, Open, High, Low, Close, Adj Close, Volume, Volume_Change, id]\n",
|
|||
|
"Index: []\n",
|
|||
|
" Open High Low Close Adj Close Volume Close_Disc \\\n",
|
|||
|
"id \n",
|
|||
|
"0 3.428571 3.428571 3.428571 3.428571 2.806002 0.0 2-4 \n",
|
|||
|
"1 3.428571 3.428571 3.428571 3.428571 2.806002 0.0 2-4 \n",
|
|||
|
"2 3.714286 3.714286 3.714286 3.714286 3.039837 0.0 2-4 \n",
|
|||
|
"3 3.714286 3.714286 3.714286 3.714286 3.039837 0.0 2-4 \n",
|
|||
|
"4 3.714286 3.714286 3.714286 3.714286 3.039837 0.0 2-4 \n",
|
|||
|
"\n",
|
|||
|
" Volume_Change DAY(Date) MONTH(Date) WEEKDAY(Date) YEAR(Date) \n",
|
|||
|
"id \n",
|
|||
|
"0 -0.073594 22 6 4 2001 \n",
|
|||
|
"1 -0.073594 25 6 0 2001 \n",
|
|||
|
"2 -0.073594 26 6 1 2001 \n",
|
|||
|
"3 -0.073594 27 6 2 2001 \n",
|
|||
|
"4 -0.073594 28 6 3 2001 \n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"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",
|
|||
|
"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": [
|
|||
|
" Open High Low Close Adj Close Volume Volume_Change \\\n",
|
|||
|
"id \n",
|
|||
|
"0 5.66 5.73 5.47 5.56 5.341250 23355100.0 -0.033796 \n",
|
|||
|
"20 5.15 5.15 5.02 5.13 4.966732 15906300.0 -0.033816 \n",
|
|||
|
"21 10.60 10.65 10.48 10.52 8.794909 10456400.0 -0.033817 \n",
|
|||
|
"24 5.47 5.80 5.47 5.75 5.541336 12929600.0 -0.033782 \n",
|
|||
|
"28 6.15 6.16 5.98 6.04 5.847770 15080900.0 -0.033786 \n",
|
|||
|
"\n",
|
|||
|
" DAY(Date) MONTH(Date) WEEKDAY(Date) YEAR(Date) \n",
|
|||
|
"id \n",
|
|||
|
"0 8 7 2 2020 \n",
|
|||
|
"20 19 1 1 2021 \n",
|
|||
|
"21 8 4 3 2010 \n",
|
|||
|
"24 7 12 0 2020 \n",
|
|||
|
"28 5 1 1 2021 \n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"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"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import featuretools as ft\n",
|
|||
|
"\n",
|
|||
|
"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",
|
|||
|
" # Добавляем уникальный идентификатор\n",
|
|||
|
"# Предобработка данных (например, кодирование категориальных признаков, удаление дубликатов)\n",
|
|||
|
"# Удаление дубликатов по идентификатору\n",
|
|||
|
"df = df.drop_duplicates(subset='id')\n",
|
|||
|
"duplicates = X_resampled[X_resampled['id'].duplicated(keep=False)]\n",
|
|||
|
"\n",
|
|||
|
"# Удаление дубликатов из столбца \"id\", сохранив первое вхождение\n",
|
|||
|
"df = df.drop_duplicates(subset='id', keep='first')\n",
|
|||
|
"\n",
|
|||
|
"print(duplicates)\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"# Создание EntitySet\n",
|
|||
|
"es = ft.EntitySet(id='stock_data')\n",
|
|||
|
"\n",
|
|||
|
"# Добавление датафрейма с домами\n",
|
|||
|
"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",
|
|||
|
"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",
|
|||
|
"es = es.add_dataframe(dataframe_name='stocks', dataframe=X_resampled, index='id')\n",
|
|||
|
"\n",
|
|||
|
"# Генерация признаков\n",
|
|||
|
"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",
|
|||
|
"print(feature_matrix.head())\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"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",
|
|||
|
"execution_count": 14,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"\n",
|
|||
|
"LinearRegression:\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",
|
|||
|
"Время обучения модели: 56.77 секунд\n",
|
|||
|
"Среднеквадратичная ошибка: 0.05\n",
|
|||
|
"Средняя абсолютная ошибка: 0.04\n",
|
|||
|
"Кросс-валидация RMSE: 0.06955321972025767 \n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADIMUlEQVR4nOzdd3hUVf7H8fednkx6TyD03puiFEFBARVXxV4Asa29+1t37bqru7q21RUr9rWuXUFgURQBKypISwCpSUhPJpl67++PmJGYgAQDoXxezxMe5txzz5x7k5nkO+ec7zEsy7IQERERERGR38XW2h0QERERERHZHyi4EhERERERaQEKrkRERERERFqAgisREREREZEWoOBKRERERESkBSi4EhERERERaQEKrkRERERERFqAgisREREREZEWoOBKRERERESkBSi4EhEREZFWtXHjRp555pno43Xr1vHiiy+2XodEdpGCK5F9yNSpU4mLi2vtboiIiLQowzC45JJLmDVrFuvWreP666/n008/be1uiTSbo7U7ICI7VlJSwosvvsinn37K/Pnzqa2tZfz48QwcOJBTTjmFgQMHtnYXRUREfpc2bdpw/vnnM378eACys7P5+OOPW7dTIrvAsCzLau1OiEjTXn75Zc4//3yqq6vp0KEDoVCIgoICBg4cyHfffUcoFGLKlCk8/vjjuFyu1u6uiIjI75Kfn09xcTF9+vTB6/W2dndEmk3TAkX2UgsWLOCss84iKyuLBQsWsHbtWsaOHYvH4+HLL79k8+bNnH766Tz77LNcddVVDc699957GTZsGKmpqcTExDB48GBef/31Rs9hGAa33npr9HE4HOboo48mJSWFH3/8MVpnR1+jR48G4OOPP8YwjEafNB5zzDGNnmf06NHR8+qtW7cOwzAazLkHWLFiBSeddBIpKSl4PB6GDBnCO++80+haysvLueqqq+jQoQNut5u2bdsyefJkiouLt9u/zZs306FDB4YMGUJ1dTUAwWCQm2++mcGDB5OYmIjX62XkyJHMmzev0XMWFRVx7rnn0q5dO+x2e/Se7MzUzQ4dOnDsscc2Kr/00ksxDKNR+aZNm5g2bRqZmZm43W569+7N008/3aBO/TU29b2Oi4tj6tSp0celpaVce+219O3bl7i4OBISEpgwYQLffffdb/Yddvxz0aFDhwZ1fT4f11xzDbm5ubjdbrp37869997Lzn62t3jxYo4++miSk5Pxer3069ePBx98MHq8frrsmjVrGDduHF6vl5ycHG6//fZGz9Gc10b9l91up02bNlxwwQWUl5dH6zTnfkPdz+iVV14ZvQ9dunTh73//O6ZpRuvUvw7uvffeRm326dOnweumOa+5Z555BsMwWLduXbRs1qxZDBs2jNjYWBITEzn22GNZunRpo+dtit/v59Zbb6Vbt254PB6ys7M58cQTyc/P3+F5HTp02OHPzrYMw+DSSy/lxRdfpHv37ng8HgYPHsz8+fMbtfvtt98yYcIEEhISiIuLY8yYMSxatKhBnfp70NTXxo0bge1PvX799debvNevvfYagwcPJiYmhrS0NM466yw2bdrUoM6tt95Kr169oq+zQw45hLfeeqtBnabeE7/88stdvi/z5s3DMAzefPPNRtfy0ksvYRgGCxcujJbtzPts/f1zuVxs3bq1wbGFCxdG+/rVV181+x5NnTo1+r7RuXNnhg4dSmlpKTExMY1+bkX2dpoWKLKXuvvuuzFNk5dffpnBgwc3Op6WlsZzzz3Hjz/+yGOPPcYtt9xCRkYGAA8++CDHHXccZ555JsFgkJdffpmTTz6Z9957j2OOOWa7z3neeefx8ccfM3v2bHr16gXA888/Hz3+6aef8vjjj3P//feTlpYGQGZm5nbbmz9/Ph988MEuXT/AsmXLGD58OG3atOFPf/oTXq+XV199leOPP5433niDE044AYDq6mpGjhzJ8uXLmTZtGoMGDaK4uJh33nmHjRs3Rvu6rYqKCiZMmIDT6eSDDz6I/kFVWVnJk08+yemnn875559PVVUVTz31FOPGjeOLL75gwIAB0TamTJnCnDlzuOyyy+jfvz92u53HH3+cb775ZpevuSmFhYUccsgh0T+q0tPT+fDDDzn33HOprKzkyiuvbHaba9as4a233uLkk0+mY8eOFBYW8thjjzFq1Ch+/PFHcnJyfrONI488ksmTJzco++c//0lZWVn0sWVZHHfcccybN49zzz2XAQMGMGvWLK677jo2bdrE/fffv8PnmD17NsceeyzZ2dlcccUVZGVlsXz5ct577z2uuOKKaL1IJML48eM55JBD+Mc//sHMmTO55ZZbCIfD3H777dF6zXltnHDCCZx44omEw2EWLlzI448/Tm1tbYPXxM6qqalh1KhRbNq0iQsvvJB27drx+eefc8MNN7BlyxYeeOCBZrfZlJ19zX366accffTRtG/fnltuuYVQKMS///1vhg8fzpdffkm3bt22e24kEuHYY49l7ty5nHbaaVxxxRVUVVUxe/Zsli5dSufOnXf43AMGDOCaa65pUPbcc88xe/bsRnU/+eQTXnnlFS6//HLcbjf//ve/GT9+PF988QV9+vQB6t4nRo4cSUJCAtdffz1Op5PHHnuM0aNH88knnzB06NAGbd5+++107NixQVlKSsoO+9yUZ555hnPOOYeDDjqIu+66i8LCQh588EEWLFjAt99+S1JSElD34cIJJ5xAhw4dqK2t5ZlnnmHSpEksXLiQgw8+eLvt/9///d92j/3WfRk9ejS5ubm8+OKL0ff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vvrvRsYyMjOg0nO0pLS3lf//7H6eccgpVVVUUFxdTXFxMSUkJ48aNY/Xq1dGpJW+88Qb9+/dv9Akr0GhKjWmaTJ48mUWLFvHBBx80+pTdbrdH16+ZpklpaSnhcJghQ4Y0uH8+nw/TNElNTd25G7KLLMvijTfeYOLEiViWFb0
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"\n",
|
|||
|
"DecisionTreeRegressor:\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",
|
|||
|
"Время обучения модели: 0.31 секунд\n",
|
|||
|
"Среднеквадратичная ошибка: 0.00\n",
|
|||
|
"Средняя абсолютная ошибка: 0.00\n",
|
|||
|
"Кросс-валидация RMSE: 0.15865311270509808 \n",
|
|||
|
"\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+++6r8hw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QwaNAgtm/fzpVXXknTpk354YcfuP3229m5cydPPPFEjduszv6+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",
|
|||
|
"Время обучения модели: 14.12 секунд\n",
|
|||
|
"Среднеквадратичная ошибка: 0.03\n",
|
|||
|
"Средняя абсолютная ошибка: 0.02\n",
|
|||
|
"Кросс-валидация RMSE: 0.12050880197633333 \n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADEbklEQVR4nOzdd3hUVf7H8fednt5IhdCb9KYoRUFAQMRVsRdQsGNvu/7Wuurqrt21oGvB3lfXCgJLU1FERUVqQi/pbTLJ9Pv7I2YkJiDBQAJ8Xs+TB+bcc8+ce5OZ5DvnnO8xTNM0ERERERERkT/E0twdEBERERERORgouBIREREREWkCCq5ERERERESagIIrERERERGRJqDgSkREREREpAkouBIREREREWkCCq5ERERERESagIIrERERERGRJqDgSkREREREpAkouBIRERGRZrV161ZmzpwZebxx40ZeffXV5uuQyF5ScCVyADn//POJjY1t7m6IiIg0KcMwmD59OrNnz2bjxo3cdNNNLF68uLm7JdJotubugIjsXnFxMa+++iqLFy9m0aJFVFdXM27cOPr378/pp59O//79m7uLIiIif0jr1q256KKLGDduHACZmZksWLCgeTslshcM0zTN5u6EiDTsjTfe4KKLLqKyspL27dsTCATIy8ujf//+/PDDDwQCAaZMmcIzzzyDw+Fo7u6KiIj8Ibm5uRQVFdGrVy9iYmKauzsijaZpgSIt1BdffMG5555LRkYGX3zxBRs2bGD06NG4XC6++eYbtm/fzllnncWLL77ItddeW+fcBx54gCFDhpCSkkJUVBQDBw7knXfeqfcchmFwxx13RB4Hg0GOP/54kpOTWblyZaTO7r5GjBgBwIIFCzAMo94njRMmTKj3PCNGjIicV2vjxo0YhlFnzj3A6tWrOfXUU0lOTsblcjFo0CA++OCDetdSVlbGtddeS/v27XE6nbRp04bJkydTVFS0y/5t376d9u3bM2jQICorKwHw+/3cdtttDBw4kISEBGJiYhg+fDjz58+v95wFBQVMmzaNtm3bYrVaI/dkT6Zutm/fnhNOOKFe+RVXXIFhGPXKt23bxtSpU0lPT8fpdNKzZ0+ef/75OnVqr7Gh73VsbCznn39+5HFJSQk33HADvXv3JjY2lvj4eMaPH88PP/zwu32H3f9ctG/fvk5dj8fD9ddfT3Z2Nk6nk27duvHAAw+wp5/tff311xx//PEkJSURExNDnz59ePTRRyPHa6fLrl+/nrFjxxITE0NWVhZ/+9vf6j1HY14btV9Wq5XWrVtz8cUXU1ZWFqnTmPsNNT+j11xzTeQ+dO7cmX/84x+Ew+FIndrXwQMPPFCvzV69etV53TTmNTdz5kwMw2Djxo2RstmzZzNkyBCio6NJSEjghBNOYMWKFfWetyFer5c77riDrl274nK5yMzM5JRTTiE3N3e357Vv3363Pzs7MwyDK664gldffZVu3brhcrkYOHAgixYtqtfu999/z/jx44mPjyc2NpZRo0bx1Vdf1alTew8a+tq6dSuw66nX77zzToP3+u2332bgwIFERUXRqlUrzj33XLZt21anzh133EGPHj0ir7MjjzyS999/v06dht4Tv/nmm72+L/Pnz8cwDN5777161/Laa69hGAZLliyJlO3J+2zt/XM4HBQWFtY5tmTJkkhfly1b1uh7dP7550feNzp16sTgwYMpKSkhKiqq3s+tSEunaYEiLdR9991HOBzmjTfeYODAgfWOt2rVipdeeomVK1fy9NNPc/vtt5OWlgbAo48+yoknnsg555yD3+/njTfe4LTTTuOjjz5iwoQJu3zOCy+8kAULFjBnzhx69OgBwMsvvxw5vnjxYp555hkefvhhWrVqBUB6evou21u0aBGffPLJXl0/wM8//8zQoUNp3bo1f/nLX4iJieGtt97ipJNO4t133+Xkk08GoLKykuHDh7Nq1SqmTp3KgAEDKCoq4oMPPmDr1q2Rvu6svLyc8ePHY7fb+eSTTyJ/UFVUVPDss89y1llncdFFF+F2u3nuuecYO3YsS5cupV+/fpE2pkyZwty5c7nyyivp27cvVquVZ555hu+++26vr7kh+fn5HHnkkZE/qlJTU/n000+ZNm0aFRUVXHPNNY1uc/369bz//vucdtppdOjQgfz8fJ5++mmOOeYYVq5cSVZW1u+2MWbMGCZPnlyn7MEHH6S0tDTy2DRNTjzxRObPn8+0adPo168fs2fP5sYbb2Tbtm08/PDDu32OOXPmcMIJJ5CZmcnVV19NRkYGq1at4qOPPuLqq6+O1AuFQowbN44jjzySf/7zn8yaNYvbb7+dYDDI3/72t0i9xrw2Tj75ZE455RSCwSBLlizhmWeeobq6us5rYk9VVVVxzDHHsG3bNi655BLatm3Ll19+yc0338yOHTt45JFHGt1mQ/b0Nbd48WKOP/542rVrx+23304gEODJJ59k6NChfPPNN3Tt2nWX54ZCIU444QTmzZvHmWeeydVXX43b7WbOnDmsWLGCTp067fa5+/Xrx/XXX1+n7KWXXmLOnDn16i5cuJA333yTq666CqfTyZNPPsm4ceNYunQpvXr1AmreJ4YPH058fDw33XQTdrudp59+mhEjRrBw4UIGDx5cp82//e1vdOjQoU5ZcnLybvvckJkzZ3LBBRdw+OGHc++995Kfn8+jjz7KF198wffff09iYiJQ8+HCySefTPv27amurmbmzJlMmjSJJUuWcMQRR+yy/T//+c+7PPZ792XEiBFkZ2fz6quvRt4na7366qt06tSJo446Ctjz99laVquVV155pc6Hei+88AIulwuv17tX96ght912W732RA4Ipoi0SMnJyWa7du3qlE2ZMsWMiYmpU3brrbeagPnhhx9GyqqqqurU8fv9Zq9evcxjjz22Tjlg3n777aZpmubNN99sWq1W8/33399ln1544QUTMDds2FDv2Pz5803AnD9/fqRs8ODB5vjx4+s8j2ma5siRI82jjz66zvkbNmwwAfOFF16IlI0aNcrs3bu36fV6I2XhcNgcMmSI2aVLl0jZbbfdZgLmf/7zn3r9CofD9frn9XrNESNGmGlpaWZOTk6d+sFg0PT5fHXKSktLzfT0dHPq1KmRsurqatNisZiXXHJJnboNfY8a0q5dO3PChAn1yqdPn27+9q152rRpZmZmpllUVFSn/MwzzzQTEhIi3+/aa3z77bfrtRsTE2NOmTIl8tjr9ZqhUKhOnQ0bNphOp9P829/+9rv9B8zp06fXK58wYUKdn9v333/fBMy77767Tr1TTz3VNAyj3v3fWTAYNDt06GC2a9fOLC0trXOs9vtqmjX3HDCvvPLKOscnTJhgOhwOs7CwMFK+N6+NWkOGDDF79OgRedyY+33XXXeZMTEx5tq1a+vU+8tf/mJarVZz8+bNpmn++jq4//7767XZs2dP85hjjqn3/Hvymvvta3fgwIFmQkKCmZeXF6mzdu1a0263m5MmTar33Dt7/vnnTcB86KGH6h3b+fvSkMb83AMmYC5btixStmnTJtPlcpknn3xypOykk04yHQ6HmZubGynbvn27GRcXV+d9pvYefPPNN7vs365ev2+//Xade+33+820tDSzV69eZnV1daTeRx99ZALmbbfdtsvnKCgoMAHzgQceiJQdc8wxdb63n3zyiQmY48aN2+v7cvPNN5tOp9MsKyur89w2m63Oz8aevs/W3r+zzjrL7N27d6Tc4/GY8fHx5tlnn13n/jbmHk2ZMqXO+8aKFStMi8US+Vlu6HeOSEulaYEiLZTb7Y6MRO1O7chRRUVFpCwqKiry/9LSUsrLyxk+fPguR1Qef/xx7r33Xh577DH+9Kc//cGe1/jPf/7DN998w3333VfvWFpaWmQazq6UlJTwv//9j9NPPx23201RURFFRUUUFxczduxY1q1bF5la8u6779K3b996n7AC9abUhMNhJk+ezFdffcUnn3xS71N2q9UaWb8WDocpKSkhGAwyaNCgOvfP4/EQDodJSUnZsxuyl0zT5N1332XixImYphm5D0VFRYw
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"\n",
|
|||
|
"Lasso:\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"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.444e+01, tolerance: 9.545e+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\\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",
|
|||
|
"Время обучения модели: 0.64 секунд\n",
|
|||
|
"Среднеквадратичная ошибка: 0.15\n",
|
|||
|
"Средняя абсолютная ошибка: 0.10\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"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.330e+01, tolerance: 9.123e+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.844e+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.789e+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.893e+01, tolerance: 7.706e+00\n",
|
|||
|
" model = cd_fast.enet_coordinate_descent(\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Кросс-валидация RMSE: 0.14816158181157554 \n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"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": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACX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//+/O1vf2N7/7b34YcfctRRR5GVlYXX6+WAAw7gtttuSx9vmS77/fffM3HiRLxeL8XFxVx77bVtrtGR10bLl2EYlJSUMHv2bBoaGtJ1OnK/ofln9MILL0zfh759+/KXv/wFy7LSdVpeB3/729/atDlw4MBWr5uOvOYeeughNE1j1apV6bK5c+cyatQoPB4PgUCAY445hsWLF7e5bntisRhXX301++yzDy6Xi6KiIk444QTKysq2el6vXr22+rOzKU3TOO+883jsscfo378/LpeLYcOG8c4777Rp9/PPP2fy5MlkZGTg8/kYP348H3zwQas6Lfegva9169YBW556/cwzz7R7r59++mmGDRuG2+0mNzeXM844g/Xr17eqc/XVV7P//vunX2cjR47k+eefb1WnvffEjz/+eIfvy4IFC9A0jeeee67Nc3n88cfRNI1Fixaly7bnfbbl/jkcDqqrq1sdW7RoUbqvn3zySYfv0VlnnZV+3ygtLWXEiBHU1dXhdrvb/NwKsbuTaYFC7KZuvPFGLMviiSeeYNiwYW2O5+bm8sgjj/Dtt99yzz33cNVVV5Gfnw/AbbfdxrHHHsvpp59OIpHgiSee4KSTTuLll1/m6KOP3uI1f/nLX/LWW28xb9489t9/fwD+/e9/p4+/++673Hvvvdxyyy3k5uYCUFBQsMX23nnnHV599dUdev4A33zzDaNHj6akpITf/e53eL1ennrqKY477jieffZZjj/+eABCoRBjx45lyZIlzJw5kwMPPJCamhpefPFF1q1bl+7rphobG5k8eTJ2u51XX301/YGqqamJ++67j1NPPZWzzz6bYDDI/fffz8SJE/noo48YMmRIuo3p06czf/58zj//fAYPHoxhGNx777189tlnO/yc21NZWcnIkSPTH6ry8vJ47bXXmDVrFk1NTVx44YUdbvP777/n+eef56STTqJ3795UVlZyzz33cOihh/Ltt99SXFy8zTaOOOIIpk2b1qrs73//O/X19enHSimOPfZYFixYwKxZsxgyZAhz587l0ksvZf369dxyyy1bvca8efM45phjKCoq4oILLqCwsJAlS5bw8ssvc8EFF6TrmabJpEmTGDlyJH/96195/fXXueqqq0ilUlx77bXpeh15bRx//PGccMIJpFIpFi1axL333ks0Gm31mthekUiEQw89lPXr13POOefQo0cP3n//fS6//HIqKiq49dZbO9xme7b3Nffuu+9y1FFH0bNnT6666iqSySR33nkno0eP5uOPP2afffbZ4rmmaXLMMcfw5ptvcsopp3DBBRcQDAaZN28eixcvprS0dKvXHjJkCL/97W9blT3yyCPMmzevTd23336bJ598kt/85jc4nU7uvPNOJk2axEcffcTAgQOB5veJsWPHkpGRwWWXXYbdbueee+5h3LhxvP3224wYMaJVm9deey29e/duVZadnb3VPrfnoYceYsaMGRx00EHccMMNVFZWctttt7Fw4UI+//xzMjMzgeY/Lhx//PH06tWLaDTKQw89xNSpU1m0aBEHH3zwFtv/v//7vy0e29Z9GTduHN27d+exxx5Lv0+2eOyxxygtLeWQQw4Btv99toVhGDz66KOt/qj34IMP4nK5iMViO3SP2nPllVe2aU+IPYISQuyWsrOzVc+ePVuVTZ8+XXm93lZlV1xxhQLUSy+9lC6LRCKt6iQSCTVw4EB1+OGHtyoH1FVXXaWUUuryyy9XhmGo559/fot9evDBBxWgVq5c2ebYggULFKAWLFiQLhsxYoSaPHlyq+sopdRhhx2mfvazn7U6f+XKlQpQDz74YLps/PjxatCgQSoWi6XLLMtSo0aNUv369UuXXXnllQpQ//3vf9v0y7KsNv2LxWJq3LhxKj8/X61YsaJV/VQqpeLxeKuy+vp6VVBQoGbOnJkui0ajStd1dc4557Sq2973qD09e/ZURx99dJvyOXPmqM3fmmfNmqWKiopUTU1Nq/JTTjlFBQKB9Pe75Tk+/fTTbdr1er1q+vTp6cexWEyZptmqzsqVK5XT6VTXXnvtNvsPqDlz5rQpP/roo1v93D7//PMKUNdff32reieeeKLSNK3N/d9UKpVSvXv3Vj179lT19fWtjrV8X5VqvueAOv/881sdP/roo5XD4VDV1dXp8h15bbQYNWqU2n///dOPO3K/r7vuOuX1etWyZcta1fvd736nDMNQa9asUUr98Dq46aab2rQ5YMAAdeihh7a5/va85jZ/7Q4bNkwFAgG1YcOGdJ1ly5Ypu92upk6d2ubam3rggQcUoG6++eY2xzb9vrSnIz/3gALUJ598ki5bvXq1crlc6vjjj0+XHXfcccrhcKiysrJ0WXl5ufL7/a3eZ1ruwccff7zF/m3p9fv000+3uteJRELl5+ergQMHqmg0mq738ssvK0BdeeWVW7xGVVWVAtTf/va3dNmhhx7a6nv76quvKkBNmjRph+/L5ZdfrpxOp2poaGh1bZvN1upnY3vfZ1vu36mnnqoGDRqULg+HwyojI0Oddtppre5vR+7R9OnTW71vLF68WOm6nv5Zbu93jhC7K5kWKMRuKhgMpkeitqZl5KipqSld5na70/+vr6+nsbGRsWPHbnFE5fbbb+eGG27gH//4Bz//+c9/ZM+b/fe//+Xjjz/mxhtvbHMsPz8/PQ1nS+rq6vjf//7HySefTDAYpKamhpqaGmpra5k4cSLLly9PTy159tlnGTx4cJu/sAJtptRYlsW0adP44IMPePXVV9v8ld0wjPT6NcuyqKurI5VKMXz48Fb3LxwOY1kWOTk523dDdpBSimeffZYpU6a
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"\n",
|
|||
|
"Ridge:\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"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=4.52541e-19): result may not be accurate.\n",
|
|||
|
" return linalg.solve(A, Xy, assume_a=\"pos\", overwrite_a=True).T\n",
|
|||
|
"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": [
|
|||
|
"[18.53835972 3.02015664 12.61628667 2.90463617 15.50833261 3.52896844\n",
|
|||
|
" 4.48748051 4.63958216 8.68196839 1.74873254 9.20514286 8.47989483\n",
|
|||
|
" 2.58190809 17.08764245 8.55417677 15.33708822 16.41262996 2.58698205\n",
|
|||
|
" 14.3010449 12.34692824 9.25519508 12.41656262 11.99359427 5.66512081\n",
|
|||
|
" 2.38719333 12.26227744 6.05023814 2.66589584 2.70345542 5.964079\n",
|
|||
|
" 6.22816714 10.34137019 11.51700786 5.58517202 8.65205276 2.3460804\n",
|
|||
|
" 4.26479846 5.33712394 1.14710216 1.71608533 16.32955154 15.43209408\n",
|
|||
|
" 2.87442811 2.34765255 5.63198832 1.80827126 11.16627919 9.49829252\n",
|
|||
|
" 3.06416135 8.63872529 16.20075921 9.22693767 11.59973333 2.96131937\n",
|
|||
|
" 5.38377786 2.03008836 11.00039614 15.61757236 9.16666362 8.41083742\n",
|
|||
|
" 2.00373929 2.06287786 2.99954165 4.10065289 4.00877304 3.97321885\n",
|
|||
|
" 13.59597539 1.40790586 2.41256628 6.39209759 2.81312245 3.10132338\n",
|
|||
|
" 15.42511366 5.94643324 9.61579166 10.56492684 1.71759088 18.88228792\n",
|
|||
|
" 8.05540212 3.56264735 3.82692764 12.38823319 6.05270239 12.00332481\n",
|
|||
|
" 1.74086769 5.89288081 2.26264139 3.71532583 6.35786331 11.23384554\n",
|
|||
|
" 5.45126529 2.94152123 1.46216163 12.4333095 1.94823683 2.61723697\n",
|
|||
|
" 4.29052409 2.85243147 4.34693161 7.75903026 1.47957735 2.64745738\n",
|
|||
|
" 2.92764333 3.92477508 1.46188826 6.73850242 10.12033775 12.36907916\n",
|
|||
|
" 5.78680952 8.88212259 2.6207355 2.91355609 1.7150175 3.87183976\n",
|
|||
|
" 10.38956052 2.10033845 9.7789235 5.9518523 6.72768585 3.8733813\n",
|
|||
|
" 2.47072558 4.97819957 14.72779601 13.00943717 4.27660505 4.05121985\n",
|
|||
|
" 9.58757433 4.39987831 2.28963043 2.38275134 9.85194738 1.72535424\n",
|
|||
|
" 3.0769887 10.30207713 8.61146578 12.90911924 11.36712701 15.50623345\n",
|
|||
|
" 13.7589026 12.26527187 1.58603345 2.30532972 8.87056489 3.13362005\n",
|
|||
|
" 3.52305632 3.67792632 3.89649612 1.4386125 1.71897963 16.02063149\n",
|
|||
|
" 5.58214334 12.0190435 2.95246444 14.46332073 3.13793354 8.35731731\n",
|
|||
|
" 12.8190229 1.75046918 6.8243075 13.8579805 3.32922829 5.86296698\n",
|
|||
|
" 11.90112905 12.93140955 14.42031785 5.3216482 10.14847492 17.3251465\n",
|
|||
|
" 2.47138994 3.96190681 18.32627855 9.86892096 1.41331525 10.64773288\n",
|
|||
|
" 9.09088555 17.20324969 3.57395915 2.81320472 3.67705031 9.48759433\n",
|
|||
|
" 3.95038135 2.46245273 3.12790097 1.83174667 5.75616587 4.76223002\n",
|
|||
|
" 2.29396539 3.50878545 16.44701112 2.56198802 3.03031246 3.60246817\n",
|
|||
|
" 10.07925548 2.55678468 3.41922207 12.81354395 2.03218368 2.18411881\n",
|
|||
|
" 5.71737479 10.5187821 9.8243807 5.31478036 9.31603096 9.10138797\n",
|
|||
|
" 3.05260546 14.61014811 2.95722431 2.53560441 12.02355853 10.43694612\n",
|
|||
|
" 3.74326294 14.4808655 1.43951577 5.58075845 14.91277029 5.228079\n",
|
|||
|
" 11.88416143 4.76215204 2.75428552 3.89022373 9.16522942 13.05572311\n",
|
|||
|
" 9.70863685 2.95688892 17.62382334 11.02667669 9.46154392 4.51952775\n",
|
|||
|
" 2.28900873 12.89384822 4.27548303 13.28473553 1.14315432 3.55814162\n",
|
|||
|
" 4.08884875 14.30471291 1.81601334 18.80676865 2.3751151 13.26443122\n",
|
|||
|
" 3.75552258 9.37745094 6.04970249 2.08571758 18.48641005 3.90175208\n",
|
|||
|
" 7.94228462 2.85694027 15.98069971 3.49704604 10.64585213 2.8258999\n",
|
|||
|
" 9.09735439 5.04798097 2.34820756 3.98234323 3.05687448 9.78621841\n",
|
|||
|
" 2.8982907 9.72068384 2.06609795 8.4708919 2.55512651 5.80843487\n",
|
|||
|
" 11.58212182 14.7659963 9.90972259 2.03636776 7.38400216 2.28270996\n",
|
|||
|
" 6.73525348 12.67320166 3.00927587 9.77745413 4.02872521 14.59123614\n",
|
|||
|
" 5.67976841 11.84854574 2.53005349 4.32053876 3.00515769 8.17868205\n",
|
|||
|
" 2.91033416 1.44360989 2.61775999 10.2059313 4.41104931 4.51101966\n",
|
|||
|
" 6.32294616 3.5798359 14.29298242 10.1850001 7.58348729 4.28934805\n",
|
|||
|
" 4.1439929 7.1227075 3.50184952 2.87101774 4.87187746 3.75846851\n",
|
|||
|
" 2.00289192 12.2322784 3.82984137 1.6002216 10.87064848 6.02427509\n",
|
|||
|
" 12.19193643 10.45019334 3.20778262 2.81201506 3.79449686 2.46022196\n",
|
|||
|
" 9.31467235 2.15239862 2.92910412 8.51832994 2.61877179 5.04802801\n",
|
|||
|
" 5.69180959 2.30174729 2.78591436 13.26958071 16.64394446 8.87999939\n",
|
|||
|
" 2.49981874 14.93269447 4.45081163 8.23200249 3.55687264 15.62632032\n",
|
|||
|
" 12.35393654 18.94154334 2.4851807 1.71703064 11.80745358 2.29174295\n",
|
|||
|
" 4.33087948 8.8071983 8.89762856 3.76659625 9.01661689 3.8378286\n",
|
|||
|
" 2.13722881 9.02591117 7.26601453 8.50650449 12.79463264 4.12517895\n",
|
|||
|
" 11.63249865 9.66210348 3.15261767 4.41986823 3.44998087 10.98001111\n",
|
|||
|
" 4.60746822 3.59134612 14.06455102 2.99038467 2.71795072 2.56293166\n",
|
|||
|
" 2.86380398 10.39300275 11.23770423 4.95716077 1.46285195 4.53518564\n",
|
|||
|
" 4.030694 16.57787437 2.18449096 3.63219595 5.10131515 13.69275973\n",
|
|||
|
" 6.48100525 2.70557808 5.39534656 9.45176473 3.38046424 3.90224131\n",
|
|||
|
" 12.59789779 12.46234039 1.70942088 5.43824785 1.47168759 18.16270268\n",
|
|||
|
" 11.96367623 1.79205494 2.58470531 2.68016219 14.74912196 10.1040361\n",
|
|||
|
" 3.26318155 2.6378777 2.60610772 3.62567306 2.84074939 10.75006159\n",
|
|||
|
" 7.39066186 3.06160376 1.26314304 3.88996936 1.14486011 15.17777613\n",
|
|||
|
" 2.86507824 10.02941764 11.21523506 3.56782758 2.57867046 1.2635082\n",
|
|||
|
" 12.70475784 11.78453449 2.30180443 1.17985582 2.47902327 2.58727762\n",
|
|||
|
" 4.16686036 3.95105243 15.43508779 2.81761054 4.0322251 3.07596467\n",
|
|||
|
" 12.82461871 2.81444631 19.33636867 3.69986094 1.99687652 4.80581687\n",
|
|||
|
" 2.27689069 12.22263126 2.08777775 2.60298631 17.12802364 12.52639565\n",
|
|||
|
" 11.69244796 2.00589312 1.98988765 16.28233571 9.10732225 13.0165149\n",
|
|||
|
" 5.92164221 2.2505696 2.44209013 10.34767538 5.98523168 16.26028586\n",
|
|||
|
" 8.33935586 16.8204904 2.03558767 2.77620724 4.30384591 3.00854596\n",
|
|||
|
" 10.17185727 3.72924572 3.7670771 4.28711491 11.08123194 11.35512171\n",
|
|||
|
" 12.71567246 15.30622396 3.15587055 4.08257799 2.03327719 3.41659174\n",
|
|||
|
" 14.13036958 3.54284787 2.69887027 9.317551 7.91886701 5.82956199\n",
|
|||
|
" 11.2956263 4.05641343 11.15385568 10.89295838 11.36479919 2.86273986\n",
|
|||
|
" 4.80262184 10.58436197 9.18243093 1.80435676 3.35755569 1.73762343\n",
|
|||
|
" 2.02772398 9.05409416 3.00025958 5.328892 2.87397055 17.43294837\n",
|
|||
|
" 2.82128031 9.12124743 3.45413876 3.08416112 2.08600945 10.071014\n",
|
|||
|
" 2.35476915 10.81477834 13.69733219 11.06620676 6.04497979 15.14030966\n",
|
|||
|
" 14.91813751 3.32817428 8.57679193 17.13660103 8.38872085 14.42368735\n",
|
|||
|
" 15.28424061 2.75288466 14.33051295 2.73651334 10.16033205 7.3391554\n",
|
|||
|
" 2.42042554 16.73487862 2.57350632 3.524343 3.28983093 3.20648722\n",
|
|||
|
" 2.58769438 14.80494598 3.82870434 2.53057771 3.27421328 6.25488245\n",
|
|||
|
" 2.97443497 3.67971006 4.83441897 4.25943544 3.43624859 16.67124463\n",
|
|||
|
" 2.98236856 8.24938713 19.46524322 2.55245492 11.80036833 2.54928389\n",
|
|||
|
" 16.2374949 9.54536837 4.93137021 3.7290861 4.03051892 11.84523524\n",
|
|||
|
" 2.58673756 14.97983755 2.57569308 16.81738772 12.28515101 2.14814742\n",
|
|||
|
" 3.42051089 9.01921055 9.49621653 2.95933914 3.75237644 2.23972066\n",
|
|||
|
" 2.49277755 1.7958297 3.86582093 2.8674885 11.42639942 3.06073274\n",
|
|||
|
" 3.13961257 4.07270659 11.3555383 3.12213356 4.21349249 8.6944528\n",
|
|||
|
" 1.76443633 2.1899131 4.18629277 8.88741747 8.33202173 7.56865056\n",
|
|||
|
" 5.43031759 2.00601233 2.32724761 2.77278376 5.25002215 2.13399159\n",
|
|||
|
" 10.57578629 11.58732585 2.86180112 2.07601269 9.77807231 2.9222822\n",
|
|||
|
" 16.49825749 5.2869834 3.11327626 6.17030198 10.02044606 9.51853346\n",
|
|||
|
" 4.15921692 3.1338318 1.99023388 5.07213763 3.66805146 14.2182649\n",
|
|||
|
" 15.27840034 13.79492613 8.7106045 10.17749474 10.40411274 9.22057205\n",
|
|||
|
" 8.76561824 12.97598282 9.1910614 17.96203867 2.12718709 4.04214711\n",
|
|||
|
" 9.56797976 15.27220032 16.99049874 11.3642939 5.91326291 2.45308319\n",
|
|||
|
" 4.46940539 20.19433041 12.69880519 5.50994035 2.6682945 5.52958319\n",
|
|||
|
" 12.42290534 14.56567536 1.67923754 9.78182321 10.14994473 2.00056631\n",
|
|||
|
" 11.91937116 11.448476 3.00603484 4.37674718 18.29810163 10.22220423\n",
|
|||
|
" 11.76327836 11.7443404 6.22308342 5.81977575 10.74629097 2.64957524\n",
|
|||
|
" 14.18339329 5.28790528 4.21960812 2.46020194 12.78135003 2.81262627\n",
|
|||
|
" 3.56482063 9.18548323 10.77509061 2.11414128 11.74135626 5.59792502\n",
|
|||
|
" 8.51753377 2.14325374 17.29903726 5.36609587 12.94339358 3.12628909\n",
|
|||
|
" 14.37527003 11.23391531 15.23465018 8.32416306 19.23496585 10.72728053\n",
|
|||
|
" 6.25323716 5.54923781 3.42075517 15.17046362 1.74005129 1.82091277\n",
|
|||
|
" 15.78389194 10.02145557 1.86770706 15.23353752 2.77126333 12.98051255\n",
|
|||
|
" 1.99018252 14.74476653 1.71875456 4.12341993 3.19630416 3.17907961\n",
|
|||
|
" 2.86272064 14.0146559 5.94243459 1.27345519 15.139857 3.19217053\n",
|
|||
|
" 2.84853572 2.2721021 2.88287568 3.5868594 15.50908541 11.71567681\n",
|
|||
|
" 4.8065892 3.19212114 2.57103734 11.67912572 3.70752448 2.51133544\n",
|
|||
|
" 4.76364981 3.27797006 2.12666216 3.99289363 2.55004679 10.4122718\n",
|
|||
|
" 3.41915544 3.45791773 4.27428329 2.16475035 2.24357662 20.27107131\n",
|
|||
|
" 2.6211838 15.62812531 2.50006029 9.73341343 11.62414759 8.98773249\n",
|
|||
|
" 2.82862895 2.00722094 9.88201667 2.1846998 1.50637995 2.32878985\n",
|
|||
|
" 14.11192293 13.41634497 14.28146237 1.4591491 2.75790525 2.83246229\n",
|
|||
|
" 4.07144576 3.79653033 9.44913553 3.90219151 4.0168187 4.1243992\n",
|
|||
|
" 9.80958254 5.3800075 9.46195049 1.97717373 8.34077912 12.43010474\n",
|
|||
|
" 3.38649636 10.02097508 11.49680925 13.97190463 3.60431429 7.37584679\n",
|
|||
|
" 4.33912419 11.84222445 1.44089012 4.85941981 3.39159309 3.13357328\n",
|
|||
|
" 2.47096887 3.94502129 4.15493405 18.49504618 9.08651191 2.95832372\n",
|
|||
|
" 2.52244627 5.99553625 2.11520684 1.89749755 2.6973316 2.54822468\n",
|
|||
|
" 10.94537441 2.84587429 12.62276847 10.15800164 2.10079835 15.30418953\n",
|
|||
|
" 10.94837016 12.40484611 11.14575664 14.59172598 12.7621914 3.05184364\n",
|
|||
|
" 1.14525931 11.08995653 8.08010737 11.35478585 8.82251206 11.58877523\n",
|
|||
|
" 2.74174474 1.72758415 2.73267471 10.97797436 9.23096251 10.99237774\n",
|
|||
|
" 5.60784631 1.43780359 2.71939508 12.29089903 11.65782657 11.7466421\n",
|
|||
|
" 12.60767642 3.36428522 10.63306574 1.52817038 3.40656569 10.39742458\n",
|
|||
|
" 4.76747207 9.39296795 1.52353529 9.34627711 3.18889881 11.42316406\n",
|
|||
|
" 1.39855096 2.46862897 3.40834961 4.85487296 5.60442383 9.39185753\n",
|
|||
|
" 5.42768172 2.22885825 3.48311119 3.03352602 13.742788 2.18855936\n",
|
|||
|
" 8.85964886 7.3666449 5.94596985 1.91490109 5.15930417 2.2872242\n",
|
|||
|
" 15.50775001 4.19582067 11.82081366 3.0231326 3.81860312 5.49153365\n",
|
|||
|
" 8.99019113 3.41449445 8.55043021 15.14574943 2.30922244 18.83958163\n",
|
|||
|
" 4.0470322 11.25874087 4.40418921 5.87370827 16.54006959 12.39198049\n",
|
|||
|
" 2.79055698 5.0799784 2.6037895 ]\n",
|
|||
|
"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",
|
|||
|
"Время обучения модели: 1.91 секунд\n",
|
|||
|
"Среднеквадратичная ошибка: 0.05\n",
|
|||
|
"Средняя абсолютная ошибка: 0.04\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"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=5.67566e-19): result may not be accurate.\n",
|
|||
|
" return linalg.solve(A, Xy, assume_a=\"pos\", overwrite_a=True).T\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=5.85088e-19): result may not be accurate.\n",
|
|||
|
" return linalg.solve(A, Xy, assume_a=\"pos\", overwrite_a=True).T\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=6.03205e-19): result may not be accurate.\n",
|
|||
|
" return linalg.solve(A, Xy, assume_a=\"pos\", overwrite_a=True).T\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=5.92069e-19): result may not be accurate.\n",
|
|||
|
" return linalg.solve(A, Xy, assume_a=\"pos\", overwrite_a=True).T\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=4.94481e-19): result may not be accurate.\n",
|
|||
|
" return linalg.solve(A, Xy, assume_a=\"pos\", overwrite_a=True).T\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Кросс-валидация RMSE: 0.06936831513332838 \n",
|
|||
|
"\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1cAAAIjCAYAAADvBuGTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAADIJElEQVR4nOzdd3hUVf7H8fednt4rhN6kNwUpioICKq6Krl0E7GIvv3XXrru6q2tbXctasK51xQ4CUhQBKypKS+glvU8y9d7fHzEDMQEJBkP5vJ4nz5M599wz595kJvnOOed7DMuyLEREREREROQ3sbV2B0RERERERA4ECq5ERERERERagIIrERERERGRFqDgSkREREREpAUouBIREREREWkBCq5ERERERERagIIrERERERGRFqDgSkREREREpAUouBIREREREWkBCq5EREREpFVt3ryZ6dOnRx6vX7+el19+ufU6JLKHFFyJ7EfOP/98YmNjW7sbIiIiLcowDC6//HJmzZrF+vXrufHGG/n0009bu1sizeZo7Q6IyK6VlJTw8ssv8+mnn7Jw4UJqa2sZN24cAwYM4I9//CMDBgxo7S6KiIj8Jm3atOHCCy9k3LhxAGRlZTF//vzW7ZTIHjAsy7JauxMi0rRXX32VCy+8kOrqajp06EAwGCQ/P58BAwbw3XffEQwGmTRpEk899RQul6u1uysiIvKb5OXlUVxcTO/evYmJiWnt7og0m6YFiuyjFi1axDnnnENmZiaLFi1i3bp1jBkzBo/Hw5dffsnWrVs588wzef7557nmmmsanHv//fczbNgwUlJSiIqKYtCgQbz55puNnsMwDG6//fbI41AoxHHHHUdycjI//fRTpM6uvkaNGgXA/PnzMQyj0SeNxx9/fKPnGTVqVOS8euvXr8cwjAZz7gFWrlzJqaeeSnJyMh6Ph8GDB/Puu+82upby8nKuueYaOnTogNvtpm3btpx33nkUFxfvtH9bt26lQ4cODB48mOrqagACgQC33norgwYNIiEhgZiYGEaOHMm8efMa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dtppdOzYkYKCAp588kmOPPJIfvrpJ7Kzs3+1jWOOOYbzzjuvQdk///lPysrKIo8ty+LEE09k3rx5TJ06lf79+zNr1ixuuOEGtmzZwoMPPrjL55g9ezYnnHACWVlZXHXVVWRmZrJixQref/99rrrqqki9cDjMuHHjGDp0KP/4xz+YOXMmt912G6FQiDvvvDNSrzmvjZNPPplTTjmFUCjE4sWLeeqpp6itrW3wmthdNTU1HHnkkWzZsoWLL76Ydu3a8fnnn3PTTTexbds2HnrooWa32ZTdfc19+umnHHfccbRv357bbruNYDDIv//9b4YPH86XX35Jt27ddnpuOBzmhBNOYO7cuZxxxhlcddVVVFVVMXv2bJYvX07nzp13+dz9+/fnuuuua1D2wgsvMHv27EZ1FyxYwGuvvcaVV16J2+3m3//+N+PGjeOLL76gd+/eQN37xMiRI4mPj+fGG2/E6XTy5JNPMmrUKBYsWMCQIUMatHnnnXfSsWPHBmXJycm77HNTpk+fzuTJkzn00EO55557KCgo4OGHH2bRokV8++23JCYmAnUfLpx88sl06NCB2tpapk+fzsSJE1m8eDGHHXbYTtv/v//7v50e+7X7MmrUKHJycnj55Zcj75P1Xn75ZTp37szhhx8O7P77bD273c5LL73U4EO95557Do/Hg8/n26N71JRbb721UXsi+wVLRPZJycnJVvv27RuUTZo0yYqJiWlQdsstt1iA9d5770XKampqGtQJBAJW7969raOPPrpBOWDddtttlmVZ1k033WTZ7XZrxowZO+3Tc889ZwHWunXrGh2bN2+eBVjz5s2LlA0ZMsQaP358g+exLMs66qijrCOOOKLB+evWrbMA67nnnouUjR492urTp4/l8/kiZaZpWsOGDbO6du0aKbv11lstwPrf//7XqF+maTbqn8/ns0aNGmWlp6dbubm5DeqHQiHL7/c3KCsrK7MyMjKsKVOmRMpqa2stm81mXXzxxQ3qNvUzakr79u2t448/vlH55Zdfbv3yrXnq1KlWVlaWVVxc3KD8jDPOsBISEiI/7/prfOONNxq1GxMTY02aNCny2OfzWeFwuEGddevWWW6327rzzjt/tf+AdfnllzcqP/744xv83s6YMcMCrLvvvrtBvVNPPdUyDKPR/d9RKBSyOnbsaLVv394qKytrcKz+52pZdfccsK644ooGx48//njL5XJZRUVFkfI9eW3UGzZsmNWzZ8/I4+bc77vuusuKiYmxVq9e3aDen/70J8tut1sbN260LGv76+C+++5r1GavXr2sI488stHz785r7pev3UGDBlkJCQlWfn5+pM7q1astp9NpTZw4sdFz7+jZZ5+1AOuBBx5odGzHn0tTmvN7D1iA9dVXX0XKNmzYYHk8Huvkk0+OlJ100kmWy+Wy8vLyImVbt2614uLiGrzP1N+DL7/8cqf929nr94033mhwrwOBgJWenm717t3bqq2tjdR7//33LcC69dZbd/ochYWFFmDdf//9kbIjjzyywc/2ww8/tABr3Lhxe3xfbrrpJsvtdlvl5eUNntvhcDT43djd99n6+3fmmWdaffr0iZR7vV4rPj7eOuussxrc3+bco0mTJjV431i+fLlls9kiv8tN/c0R2VdpWqDIPqqqqioyErUr9SNHlZWVkbKoqKjI92VlZVRUVDBy5Midjqg8+uij3HPPPTzyyCP84Q9/+I09r/O///2PL7/8knvvvbfRsfT09Mg0nJ0pLS3lk08+4Y9//CNVVVUUFxdTXFxMSUkJY8eOZc2aNZGpJW+99Rb9+vVr9Akr0GhKjWmanHfeeSxZsoQPP/yw0afsdrs9sn7NNE1KS0sJhUIMHjy4wf3zer2YpklKSsru3ZA9ZFkWb731FhMmTMCyrMh9KC4
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1000x600 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",
|
|||
|
"feature_matrix = pd.get_dummies(feature_matrix, drop_first=True)\n",
|
|||
|
"val_feature_matrix = pd.get_dummies(val_feature_matrix, drop_first=True)\n",
|
|||
|
"test_feature_matrix = pd.get_dummies(test_feature_matrix, drop_first=True)\n",
|
|||
|
"\n",
|
|||
|
"feature_matrix.fillna(feature_matrix.median(), inplace=True)\n",
|
|||
|
"val_feature_matrix.fillna(val_feature_matrix.median(), inplace=True)\n",
|
|||
|
"test_feature_matrix.fillna(test_feature_matrix.median(), inplace=True)\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",
|
|||
|
"# Обучение модели\n",
|
|||
|
"model1 = LinearRegression()\n",
|
|||
|
"model2 = DecisionTreeRegressor()\n",
|
|||
|
"model3 = RandomForestRegressor(n_estimators=100) # Количество деревьев в лесу\n",
|
|||
|
"model4 = Lasso(alpha=0.1)\n",
|
|||
|
"model5 = Ridge(alpha=0.1)\n",
|
|||
|
"\n",
|
|||
|
"print('\\nLinearRegression:')\n",
|
|||
|
"start_time = time.time()\n",
|
|||
|
"model1.fit(X_train, y_train)\n",
|
|||
|
"\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",
|
|||
|
"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(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",
|
|||
|
"\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",
|
|||
|
"Время обучения у моделей варьируется значительно. Например, DecisionTreeRegressor обучается за короткое время (0.31 секунды), в то время как LinearRegression и RandomForestRegressor требуют больше времени. Это может быть критичным для сценариев, требующих частых обновлений модели.\n",
|
|||
|
"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
|
|||
|
}
|