added some Information

main
klara 2024-06-21 17:05:39 +02:00
parent a936b47f2b
commit 4d0cdf876f
1 changed files with 93 additions and 4 deletions

View File

@ -7,6 +7,29 @@
"# Decison Tree" "# Decison Tree"
] ]
}, },
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import sqlite3\n",
"import os\n",
"from datetime import datetime\n",
"from joblib import dump, load\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import xgboost as xgb\n",
"from sklearn.model_selection import GridSearchCV\n",
"from sklearn.metrics import confusion_matrix, f1_score\n",
"from sklearn.ensemble import GradientBoostingClassifier\n",
"from sklearn.impute import SimpleImputer\n",
"from sklearn.metrics import accuracy_score\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"\n",
"import seaborn as sns"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -16,7 +39,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -40,9 +63,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"train_x shape: (3502, 10)\n",
"test_x shape: (438, 10)\n",
"valid_x shape: (438, 10)\n",
"features: ['age', 'gender', 'artial_rate', 'ventricular_rate', 'qrs_duration', 'qt_length', 'qrs_count', 'q_peak', 'r_axis', 't_axis']\n",
"number of classes: 4\n"
]
}
],
"source": [ "source": [
"# get the target and features\n", "# get the target and features\n",
"train_y = train['y']\n", "train_y = train['y']\n",
@ -93,11 +128,65 @@
"num_classes= len(set(valid_y.to_list()))\n", "num_classes= len(set(valid_y.to_list()))\n",
"print('number of classes:', num_classes)" "print('number of classes:', num_classes)"
] ]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Validierungsgenauigkeit: 0.7557077625570776\n",
"Testgenauigkeit: 0.7922374429223744\n"
]
}
],
"source": [
"# Schritt 1: Importiere die notwendigen Bibliotheken\n",
"from sklearn.tree import DecisionTreeClassifier\n",
"from sklearn.metrics import accuracy_score\n",
"\n",
"# Schritt 2: Erstelle das Decision Tree Modell\n",
"# Beispiel: Begrenzung der Tiefe des Baumes\n",
"dt_classifier = DecisionTreeClassifier(max_depth=5)\n",
"\n",
"# Schritt 3: Trainiere das Modell\n",
"dt_classifier.fit(train_x, train_y)\n",
"\n",
"# Schritt 4: Vorhersagen und Auswertung auf den Validierungsdaten\n",
"valid_pred = dt_classifier.predict(valid_x)\n",
"valid_accuracy = accuracy_score(valid_y, valid_pred)\n",
"print(f'Validierungsgenauigkeit: {valid_accuracy}')\n",
"\n",
"# Optional: Tuning des Modells basierend auf den Validierungsergebnissen\n",
"# Experimentiere mit verschiedenen Parametern und trainiere bei Bedarf neu\n",
"\n",
"# Schritt 6: Endgültige Bewertung mit Testdaten\n",
"test_pred = dt_classifier.predict(test_x)\n",
"test_accuracy = accuracy_score(test_y, test_pred)\n",
"print(f'Testgenauigkeit: {test_accuracy}')\n"
]
} }
], ],
"metadata": { "metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": { "language_info": {
"name": "python" "codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
} }
}, },
"nbformat": 4, "nbformat": 4,