246 lines
5.4 KiB
Plaintext
246 lines
5.4 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"toc": true
|
|
},
|
|
"source": [
|
|
"# WS 10 Performancevergleiche Regression"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"* Vergleichen Sie alle Regressoren (ausser `SVR` und `MLPRegressor`) mit folgenden Modifikationen\n",
|
|
" * die Vergleiche werden ohne und mit Standardisierung der Features durchgeführt\n",
|
|
" * die Resultate (r2_score) werden in Form einer Heatmap zusammengestellt\n",
|
|
"* informieren Sie sich zum Vorgehen am Code in 3.4 Regression - Modellvergleiche.ipynb\n",
|
|
"* Präsentation der Ergebnisse als \n",
|
|
" * seaborn heatmap\n",
|
|
" * alternative Visualisierung: Grouped barplots"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "raw",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"## for scikit-learn 1.4.2, to silence warnings regarding physical cores\n",
|
|
"import os\n",
|
|
"os.environ['LOKY_MAX_CPU_COUNT'] = '4' ## depending on the hardware used"
|
|
]
|
|
},
|
|
{
|
|
"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'\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('melb_data_prep.csv', target='Price', seed=1234)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2020-04-08T10:33:02.116059Z",
|
|
"start_time": "2020-04-08T10:33:02.087399Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"## standardize features (lead: train)\n",
|
|
"from sklearn.preprocessing import StandardScaler\n",
|
|
"scaler = StandardScaler()\n",
|
|
"scaler.fit(X_train)\n",
|
|
"X_train_sc = scaler.transform(X_train)\n",
|
|
"X_test_sc = scaler.transform(X_test)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2020-04-08T10:33:02.294366Z",
|
|
"start_time": "2020-04-08T10:33:02.120049Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"## import trainer classes\n",
|
|
"## tbd\n",
|
|
"\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2020-04-08T10:33:02.326199Z",
|
|
"start_time": "2020-04-08T10:33:02.299732Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"## define models\n",
|
|
"## tbd\n",
|
|
"\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2020-04-08T10:33:15.141363Z",
|
|
"start_time": "2020-04-08T10:33:02.341448Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"## compare models\n",
|
|
"## tbd: prepare empty lists for results\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"# for model in models:\n",
|
|
"\n",
|
|
" ## not scaled\n",
|
|
" ## tbd\n",
|
|
" \n",
|
|
" \n",
|
|
" \n",
|
|
" ## scaled\n",
|
|
" ## tbd\n",
|
|
" \n",
|
|
"\n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "raw",
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2020-04-08T10:33:15.742776Z",
|
|
"start_time": "2020-04-08T10:33:15.150619Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"## visualize results\n",
|
|
"\"\"\"\n",
|
|
"scores = pd.DataFrame(\n",
|
|
" {'r2_no': r2_nos, \n",
|
|
" 'r2_yes': r2_yess\n",
|
|
" }, index=regressors)\n",
|
|
"\n",
|
|
"sns.heatmap(scores);\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 14 Regression - Modellvergleiche 2",
|
|
"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
|
|
}
|