{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "# WS 11 permutation_importance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* ermitteln Sie die Importance der Features der *Rohdaten* von `melb_data.csv` unter Einsatz von `sklearn.inspection.ermutation_importance`\n", "* setzen Sie dazu minimales Feature Engineering wie folgt ein:\n", " * entfernen fragwürdiger Variablen: 'Unnamed: 0', 'Suburb', 'Address', 'SellerG', 'Postcode', 'Bedroom2', 'Date', 'CouncilArea'\n", " * One-Hot encoding aller verbleibenden kategorialen Variablen (der Parameter `dummy_na=True` von `pd.get_dummies()` erstellt auch Dummy-Variablen für NAs)\n", " * einsetzen von geschätzten Werten für NAs in verbleibenden numerischen Variablen mit `sklearn.impute.KNNImputer`\n", "* danach:\n", " * features - target - split\n", " * **kein** train - test - split\n", " * ermitteln der Importance unter Einsatz von \n", " * `sklearn.inspection.permutation_importance`\n", " * `sklearn.tree.DecisionTreeRegressor`\n", " * tabellarische und graphische Darstellung der Ergebnisse" ] }, { "cell_type": "code", "execution_count": 4, "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'\n", "datapath = '../3_data'\n", "from sys import path; path.insert(1, codepath)\n", "from os import chdir; chdir(datapath)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "## read data\n", "data = pd.read_csv('melb_data.csv')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "## drop columns\n", "vars_to_drop = ['Unnamed: 0', 'Suburb', 'Address', 'SellerG', 'Postcode', 'Bedroom2', 'Date', 'CouncilArea']\n", "data = data.drop(vars_to_drop, axis=1)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "## one-hot encode (incl. NAs)\n", "data = pd.get_dummies(data, drop_first=False, dummy_na=True)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "## KNNImputer for NAs\n", "## tbd\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "## features - target - split\n", "## tbd\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "## permutation_importance\n", "## tbd\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "## collect results in a dataframe, ordered by mean\n", "## tbd\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "tags": [] }, "outputs": [], "source": [ "## visualize results\n", "## tbd\n", "\n", "\n" ] } ], "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 14 Regression - Modellvergleiche 2 - 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": false }, "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 }