renamed directory, created mad method python file in tools

This commit is contained in:
2025-12-10 19:29:18 +01:00
parent 2ee8b96b22
commit c7295f310c
2 changed files with 23 additions and 0 deletions
@@ -0,0 +1,47 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "e790b157",
"metadata": {},
"source": [
"Im folgenden wird auf die Daten das MAD Outlier removal angewendet."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4bd7c061",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn.preprocessing import StandardScaler, MinMaxScaler\n",
"\n",
"def mad_outlier_removal(df, columns, threshold=3.5):\n",
" \"\"\"\n",
" Entfernt Ausreißer basierend auf Median Absolute Deviation (MAD).\n",
" threshold: typischer Wert ist 3.5 (entspricht robustem Z-Score Cutoff).\n",
" \"\"\"\n",
" df_clean = df.copy()\n",
" for col in columns:\n",
" median = df_clean[col].median()\n",
" mad = np.median(np.abs(df_clean[col] - median))\n",
" if mad == 0:\n",
" continue # keine Streuung, keine Ausreißer\n",
" robust_z = 0.6745 * (df_clean[col] - median) / mad\n",
" mask = np.abs(robust_z) <= threshold\n",
" df_clean = df_clean[mask]\n",
" return df_clean"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}