{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "# WS 06 Klassifikation - RandomForestClassifier" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* untersuchen Sie die folgenden Tuning-Parameter von RandomForestClassifier in Bezug auf die erreichte Performance (accuracy_score) mit dem vorbereiteten Dataset:\n", " * n_estimators als `range(100, 500, 50)`\n", " * max_features als `range(1, 11)`\n", " * min_impurity_decrease als `np.arange(0, 0.1, 0.01)`\n", "* wie wirkt sich der random_state aus?\n", "* welche der ausserdem zur Verfügung stehenden Parameter sind keine Tuning Parameter? Konsultieren Sie dazu die (Online-) Dokumentation" ] }, { "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": [ "from sklearn.ensemble import RandomForestClassifier" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "n_estimators:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100\n", "150\n", "200\n", "250\n", "300\n", "350\n", "400\n", "450\n" ] } ], "source": [ "model = RandomForestClassifier()\n", "scores = []\n", "params = range(100, 500, 50)\n", "\n", "for param in params:\n", " print(param)\n", " ## tbd\n", " \n", "\n", "## tbd\n", "#fig = sns.lineplot(x=params, y=scores)\n", "#...\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "max_features:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n" ] } ], "source": [ "model = RandomForestClassifier()\n", "scores = []\n", "params = range(1, 11)\n", "\n", "for param in params:\n", " print(param)\n", " ## tbd\n", " \n", " \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "min_impurity_decrease:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0\n", "0.01\n", "0.02\n", "0.03\n", "0.04\n", "0.05\n", "0.06\n", "0.07\n", "0.08\n", "0.09\n" ] } ], "source": [ "model = RandomForestClassifier()\n", "scores = []\n", "params = np.arange(0, 0.1, 0.01)\n", "\n", "for param in params:\n", " print(param)\n", " ## tbd\n", " \n", " \n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Fazit:**\n", "* tbd\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "keine Tuning Parameter sind hier:\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": "2.2", "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "WS 09 Klassifikation - RandomForestClassifier", "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": 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()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }