{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "# WS 08 Regression mit Standardisieren und Logarithmieren" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* untersuchen Sie den Einfluss des Standardisierens der Features auf folgende Ergebnisse der Linearen Regression:\n", " * Modellkoeffizienten\n", " * Predictions\n", " * Score\n", "* untersuchen Sie den Einfluss des Logarithmierens des Targets auf die Performance der Linearen Regression" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "## prepare env, read and prepare data\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns; sns.set()\n", "\n", "codepath = '../2_code' ## for import of user defined module\n", "datapath = '../3_data'\n", "#codepath = '.././2_code' ## for import of user defined module\n", "#datapath = '../../3_data'\n", "\n", "from sys import path; path.insert(1, codepath)\n", "from os import chdir; chdir(datapath)\n", "\n", "from bfh_cas_pml import prep_data\n", "X_train, X_test, y_train, y_test = prep_data('melb_data_prep.csv', target='Price', seed=1234)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-105513873.23403685\n", "[ 245383.60581414 -141356.39759052 -40383.66643969 161336.03949841\n", " 40391.14829949 83303.27089591]\n", "[1331246.16325189 2557493.2373921 871684.82823291 1495633.275723\n", " 1549557.61151302 634348.67092323]\n", "0.5601419746121152\n" ] } ], "source": [ "## baseline\n", "from sklearn.linear_model import LinearRegression\n", "from sklearn.metrics import r2_score\n", "model = LinearRegression()\n", "model.fit(X_train, y_train)\n", "y_pred = model.predict(X_test)\n", "\n", "print(model.intercept_)\n", "print(model.coef_[:6])\n", "print(y_pred[:6])\n", "print(r2_score(y_test, y_pred))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "## scaled features\n", "## tbd\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "## log target\n", "## tbd\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Fazit**\n", "* tbd" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.7" }, "toc": { "base_numbering": "1", "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": true, "title_cell": "WS 11 Regression - mit FE - solution", "title_sidebar": "Contents", "toc_cell": true, "toc_position": { "height": "calc(100% - 180px)", "left": "10px", "top": "150px", "width": "195.933px" }, "toc_section_display": true, "toc_window_display": true }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "position": { "height": "321.85px", "left": "785px", "right": "20px", "top": "118px", "width": "350px" }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }