lab_4 #4

Merged
Arutunyan-Dmitry merged 4 commits from lab_4 into main 2024-11-18 18:00:57 +04:00
Showing only changes of commit f5d149a2d7 - Show all commits

View File

@ -166,7 +166,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Конвертация данных:" "### Предобработка данных:"
] ]
}, },
{ {
@ -1130,7 +1130,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 323, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1177,10 +1177,10 @@
"\n", "\n",
"\n", "\n",
"# Оценка качества различных моделей на основе метрик\n", "# Оценка качества различных моделей на основе метрик\n",
"def evaluate_models(models, \n", "def evaluate_models(models: dict[str, Any], \n",
" pipeline_end, \n", " pipeline_end: Pipeline, \n",
" X_train, y_train, \n", " X_train: DataFrame, y_train, \n",
" X_test, y_test) -> dict[str, dict[str, Any]]:\n", " X_test: DataFrame, y_test) -> dict[str, dict[str, Any]]:\n",
" results: dict[str, dict[str, Any]] = {}\n", " results: dict[str, dict[str, Any]] = {}\n",
" \n", " \n",
" for model_name, model in models.items():\n", " for model_name, model in models.items():\n",
@ -1298,7 +1298,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 325, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -1368,6 +1368,7 @@
"# Меняем знак, так как берем отрицательное значение MSE\n", "# Меняем знак, так как берем отрицательное значение MSE\n",
"new_best_mse = -new_grid_search.best_score_\n", "new_best_mse = -new_grid_search.best_score_\n",
"\n", "\n",
"\n",
"# Обучение модели с лучшими параметрами для новых значений\n", "# Обучение модели с лучшими параметрами для новых значений\n",
"model_best = RandomForestRegressor(**new_best_params)\n", "model_best = RandomForestRegressor(**new_best_params)\n",
"model_best.fit(X_train_processing_result, y_train)\n", "model_best.fit(X_train_processing_result, y_train)\n",
@ -1379,6 +1380,7 @@
"mse = metrics.mean_squared_error(y_test, y_pred)\n", "mse = metrics.mean_squared_error(y_test, y_pred)\n",
"rmse = np.sqrt(mse)\n", "rmse = np.sqrt(mse)\n",
"\n", "\n",
"\n",
"# Вывод результатов\n", "# Вывод результатов\n",
"print(\"Старые параметры:\", old_best_params)\n", "print(\"Старые параметры:\", old_best_params)\n",
"print(\"Лучший результат (MSE) на старых параметрах:\", old_best_mse)\n", "print(\"Лучший результат (MSE) на старых параметрах:\", old_best_mse)\n",