{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

WS 10 Klassifikation - Modellvergleiche

\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* vergleichen Sie alle bis jetzt vorgestellten Klassifikatoren miteinander in Bezug auf\n", " * Performance\n", " * Rechenzeiten, differenziert nach .fit() und .predict() \n", " und visualisieren Sie die Ergebnisse\n", "* Tipp: modifizieren / ergänzen Sie dazu den abgegebenen Code von Kapitel 2.2.6 Modellvergleiche\n", "\n", "* optional: fügen Sie andere, im Kurs nicht behandelte Klassifikatoren dazu, welche Sie in der Dokumentation von scikit-learn finden\n", "* optional: falls Sie im Rahmen von Feaure Engineering alternatives Preprocessing erarbeitet haben, können Sie die Auswirkungen desselben jetzt auch noch einbeziehen\n", "* optional: wie wirkt sich Skalierung (z.B. mit StandardScaler) auf die Performance von MLPClassifier aus?" ] }, { "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", "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('bank_data_prep.csv', target='y', seed=1234)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "## Funktionen (Klassen) importieren\n", "from sklearn.neighbors import KNeighborsClassifier\n", "from sklearn.tree import DecisionTreeClassifier\n", "from sklearn.ensemble import RandomForestClassifier\n", "## tbd ergänzen\n", "\n", "\n", "\n", "from sklearn.metrics import accuracy_score\n", "import time ## für Zeitmessung" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "## Modelle definieren und in Liste hinterlegen\n", "models = [\n", " KNeighborsClassifier(),\n", " DecisionTreeClassifier(min_impurity_decrease=0.002),\n", " RandomForestClassifier(n_estimators=100)\n", " ## tbd ergänzen\n", " \n", " \n", " \n", "]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "KNeighborsClassifier()\n", "DecisionTreeClassifier(min_impurity_decrease=0.002)\n", "RandomForestClassifier()\n" ] } ], "source": [ "## zum Sammeln der Resultate\n", "scores = []\n", "times_fit = []\n", "times_pred = []\n", "model_names = []\n", "\n", "#print('Classifier Score Time fit Time pred')\n", "#print('====================================================================')\n", "\n", "## Loop\n", "for model in models:\n", " print(model)\n", " ## tbd\n", " \n", " ## start timer1 - fit - stop timer1\n", " \n", " \n", " ## start timer2 - predict - stop timer2\n", " \n", " \n", " ## berechne Score & pick Modellname\n", " \n", " \n", " ## Ergebnisse an vorbereitete Listen anhängen\n", " \n", " \n", " ## Iterationsergebnisse in Konsole ausgeben (optional)\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "## visualisieren\n", "## tbd ergänzen\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Fazit:** \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": "", "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "WS 10 Klassifikation - Modellvergleiche", "title_sidebar": "Contents", "toc_cell": true, "toc_position": { "height": "calc(100% - 180px)", "left": "10px", "top": "150px", "width": "205.2px" }, "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()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }