ki-dhbw/Aufgaben/00 - Python Kurzeinführung...

1239 lines
170 KiB
Plaintext
Raw Permalink Normal View History

2025-01-16 14:14:58 +01:00
{
"cells": [
{
"cell_type": "markdown",
"id": "24e7652f",
"metadata": {},
"source": [
"# \"Python für ML\" Kurzeinführung"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "92bb5be1",
"metadata": {},
"outputs": [],
"source": [
"# imports überall im Code möglich, aber die Konvention ist alle benötigten import statements\n",
"# gleich zu Beginn einer Datei zu machen\n",
"\n",
"# numpy ist ein Python-Modul für Numerik, das sowohl Funktionalität als auch Effizienz bietet\n",
"import numpy as np\n",
"\n",
"# pandas ist sehr gut zum Arbeiten mit tabellarischen Daten, egal ob csv, xls oder xlsx\n",
"import pandas as pd\n",
"\n",
"# plotting settings\n",
"pd.plotting.register_matplotlib_converters()\n",
"\n",
"# matplotlib ist ein sehr umfangreiches Modul zum Erstellen von Visualisierungen/Plots\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"# seaborn erleichtert das Erstellen von oft verwendeten Plot-Typen;\n",
"# es basiert selbst auf matplotlib und man kann beides kombinieren\n",
"# eine schöne Einführung in Seaborn: https://www.kaggle.com/learn/data-visualization\n",
"import seaborn as sns"
]
},
{
"cell_type": "markdown",
"id": "0562db47",
"metadata": {},
"source": [
"Es gibt verschiedene Zelltypen in Jupyter - Code oder Markdown. Mit Markdown kann man den Code schöner dokumentieren als durch Kommentare im Code selbst. Es sind *verschiedene* **Formatierungen** und sogar LaTeX-ähnliche mathematische Formeln möglich. Sowohl inline ($h_\\theta(x) = \\theta^Tx$) als auch zentriert in separaten Zeilen:\n",
"\n",
"$$h_\\theta(x) = \\theta^Tx$$\n",
"\n",
"<p><b>HTML</b> wird ebenfalls erkannt.</p>\n",
"\n",
"Wir laden jetzt eine CSV-Datei mit Pandas:"
]
},
{
"cell_type": "markdown",
"id": "55f91177",
"metadata": {},
"source": [
"## Daten laden"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "724b4875",
"metadata": {},
"outputs": [],
"source": [
"data_file_path = '../data/exam-iq.csv'\n",
"data = pd.read_csv(data_file_path)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b5661e8d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Pass</th>\n",
" <th>Hours</th>\n",
" <th>IQ</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>0.50</td>\n",
" <td>110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>0.75</td>\n",
" <td>95</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>1.00</td>\n",
" <td>118</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>1.25</td>\n",
" <td>97</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>1.50</td>\n",
" <td>100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>0</td>\n",
" <td>1.75</td>\n",
" <td>110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>0</td>\n",
" <td>1.75</td>\n",
" <td>115</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>1</td>\n",
" <td>2.00</td>\n",
" <td>104</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>1</td>\n",
" <td>2.25</td>\n",
" <td>120</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>0</td>\n",
" <td>2.50</td>\n",
" <td>98</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>1</td>\n",
" <td>2.75</td>\n",
" <td>118</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>0</td>\n",
" <td>3.00</td>\n",
" <td>88</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>1</td>\n",
" <td>3.25</td>\n",
" <td>108</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>1</td>\n",
" <td>4.00</td>\n",
" <td>109</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>1</td>\n",
" <td>4.25</td>\n",
" <td>110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>1</td>\n",
" <td>4.50</td>\n",
" <td>112</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>1</td>\n",
" <td>4.75</td>\n",
" <td>97</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>1</td>\n",
" <td>5.00</td>\n",
" <td>102</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>1</td>\n",
" <td>5.50</td>\n",
" <td>109</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>0</td>\n",
" <td>3.50</td>\n",
" <td>125</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Pass Hours IQ\n",
"0 0 0.50 110\n",
"1 0 0.75 95\n",
"2 0 1.00 118\n",
"3 0 1.25 97\n",
"4 0 1.50 100\n",
"5 0 1.75 110\n",
"6 0 1.75 115\n",
"7 1 2.00 104\n",
"8 1 2.25 120\n",
"9 0 2.50 98\n",
"10 1 2.75 118\n",
"11 0 3.00 88\n",
"12 1 3.25 108\n",
"13 1 4.00 109\n",
"14 1 4.25 110\n",
"15 1 4.50 112\n",
"16 1 4.75 97\n",
"17 1 5.00 102\n",
"18 1 5.50 109\n",
"19 0 3.50 125"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "66f73953",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Pass</th>\n",
" <th>Hours</th>\n",
" <th>IQ</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>0.50</td>\n",
" <td>110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>0.75</td>\n",
" <td>95</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>1.00</td>\n",
" <td>118</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>1.25</td>\n",
" <td>97</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>1.50</td>\n",
" <td>100</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Pass Hours IQ\n",
"0 0 0.50 110\n",
"1 0 0.75 95\n",
"2 0 1.00 118\n",
"3 0 1.25 97\n",
"4 0 1.50 100"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.head()"
]
},
{
"cell_type": "markdown",
"id": "7a2feffb",
"metadata": {},
"source": [
"**Nützliche Shortcuts:<br>**\n",
"b - fügt eine leere Zelle unterhalb der aktuell aktiven hinzu<br>\n",
"a - fügt eine leere Zelle oberhalb der aktuell aktiven hinzu<br>\n",
"CTRL + ENTER - führt aktive Zelle aus (Mac: CMD + ENTER)<br>\n",
"SHIFT + ENTER - führt aktive Zelle aus und wechselt zur nächsten Zelle<br>\n",
"ENTER - wechselt in den Bearbeiten-Modus einer Zelle<br>\n",
"ESC - wechselt in den Ansicht-Modus einer Zelle<br>\n",
"d d - (2x d) - löscht aktive Zelle<br>\n",
"CTRL + C und CTRL + V funktionieren wie erwartet<br>"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "099ff4d7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Axes: xlabel='Hours', ylabel='IQ'>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjsAAAGwCAYAAABPSaTdAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAALa1JREFUeJzt3X90VPWd//HXoPmdmYlhJMNo0KBB8EdY1JZNpalIqsQelJoeS4qIv6DdghbRGnO2CP7oScCjpwsqeLp7zKn1x3YXpKecLSxLhWCNFMGc4I/1BDZKMAnsCJnJJCQzhPn+4ZfZTvMTTObOfPJ8nHPPYe77zs37TmZyX9wfn7GFw+GwAAAADDXG6gYAAABGEmEHAAAYjbADAACMRtgBAABGI+wAAACjEXYAAIDRCDsAAMBo51vdQDw4ffq0mpubZbfbZbPZrG4HAAAMQTgcVnt7uzwej8aM6f/4DWFHUnNzs3Jzc61uAwAAnIOmpiZdfPHF/dYJO5Lsdrukr14sh8NhcTcAAGAo/H6/cnNzI/vx/hB2pMipK4fDQdgBACDBDHYJChcoAwAAoxF2AACA0Qg7AADAaIQdAABgNMIOAAAwGmEHAAAYjbADA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Jmd6skXdAQDOlhHX7Lz22mtyuVy6+uqrVVFRoc7OzgGX7+7ult/vj5qAM7yBYK+gc0ZNg1feAKezACCRWHpkZzj86Ec/0iWXXCKPx6P6+nqVl5fr008/1aZNm/p9TmVlpZ588skYdol
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sns.scatterplot(x=data['Hours'], y=data['IQ'])\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "3e62008e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Axes: xlabel='Hours', ylabel='IQ'>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjsAAAGwCAYAAABPSaTdAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAOmxJREFUeJzt3Xl8VPW9//H3ZF9nQhKSEEjYN9kUUBpFFEmB2ItaaVVERKviAlpEK+beIri0IF69vSiKvy5SLUpbRbS0gohAXAKyNAUFKUskwSysmcm+TOb3Ry7TjkkgQGbOzMnr+Xich8z3O3PmcwJm3vM93/M9FpfL5RIAAIBJBRldAAAAgDcRdgAAgKkRdgAAgKkRdgAAgKkRdgAAgKkRdgAAgKkRdgAAgKmFGF2AP2hsbFRRUZFiY2NlsViMLgcAALSBy+VSeXm5UlNTFRTU+vgNYUdSUVGR0tLSjC4DAACch8LCQnXr1q3VfsKOpNjYWElNPyyr1WpwNQAAoC0cDofS0tLcn+OtIexI7lNXVquVsAMAQIA52xQUJigDAABTI+wAAABTI+wAAABTY84OAAABzOl0qr6+3ugyvCI0NFTBwcEXvB/CDgAAAcjlcqmkpERlZWVGl+JVcXFxSklJuaB18Ag7AAAEoNNBJykpSVFRUaZbFNflcqmqqkpHjx6VJHXp0uW890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ip8fCSAweoqpL1rpJdGSG/fKb3/oPTy96S1j0sVR42uDoC/qT7VPOhI0sENTb8/fDDC40u
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sns.scatterplot(x=data['Hours'], y=data['IQ'], hue=data['Pass'])"
]
},
{
"cell_type": "markdown",
"id": "a0f6f2ee",
"metadata": {},
"source": [
"Ein anderer Datensatz..."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "9f7c4ebd",
"metadata": {},
"outputs": [],
"source": [
"melbourne_file_path = 'data/melb_data.csv'\n",
"melbourne_data = pd.read_csv(melbourne_file_path)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "d5e017fe",
"metadata": {},
"outputs": [],
"source": [
"melbourne_data = melbourne_data.dropna(axis=0)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "0de6a41c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Suburb</th>\n",
" <th>Address</th>\n",
" <th>Rooms</th>\n",
" <th>Type</th>\n",
" <th>Price</th>\n",
" <th>Method</th>\n",
" <th>SellerG</th>\n",
" <th>Date</th>\n",
" <th>Distance</th>\n",
" <th>Postcode</th>\n",
" <th>...</th>\n",
" <th>Bathroom</th>\n",
" <th>Car</th>\n",
" <th>Landsize</th>\n",
" <th>BuildingArea</th>\n",
" <th>YearBuilt</th>\n",
" <th>CouncilArea</th>\n",
" <th>Lattitude</th>\n",
" <th>Longtitude</th>\n",
" <th>Regionname</th>\n",
" <th>Propertycount</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Abbotsford</td>\n",
" <td>25 Bloomburg St</td>\n",
" <td>2</td>\n",
" <td>h</td>\n",
" <td>1035000.0</td>\n",
" <td>S</td>\n",
" <td>Biggin</td>\n",
" <td>4/02/2016</td>\n",
" <td>2.5</td>\n",
" <td>3067.0</td>\n",
" <td>...</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>156.0</td>\n",
" <td>79.0</td>\n",
" <td>1900.0</td>\n",
" <td>Yarra</td>\n",
" <td>-37.8079</td>\n",
" <td>144.9934</td>\n",
" <td>Northern Metropolitan</td>\n",
" <td>4019.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Abbotsford</td>\n",
" <td>5 Charles St</td>\n",
" <td>3</td>\n",
" <td>h</td>\n",
" <td>1465000.0</td>\n",
" <td>SP</td>\n",
" <td>Biggin</td>\n",
" <td>4/03/2017</td>\n",
" <td>2.5</td>\n",
" <td>3067.0</td>\n",
" <td>...</td>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>134.0</td>\n",
" <td>150.0</td>\n",
" <td>1900.0</td>\n",
" <td>Yarra</td>\n",
" <td>-37.8093</td>\n",
" <td>144.9944</td>\n",
" <td>Northern Metropolitan</td>\n",
" <td>4019.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Abbotsford</td>\n",
" <td>55a Park St</td>\n",
" <td>4</td>\n",
" <td>h</td>\n",
" <td>1600000.0</td>\n",
" <td>VB</td>\n",
" <td>Nelson</td>\n",
" <td>4/06/2016</td>\n",
" <td>2.5</td>\n",
" <td>3067.0</td>\n",
" <td>...</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>120.0</td>\n",
" <td>142.0</td>\n",
" <td>2014.0</td>\n",
" <td>Yarra</td>\n",
" <td>-37.8072</td>\n",
" <td>144.9941</td>\n",
" <td>Northern Metropolitan</td>\n",
" <td>4019.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Abbotsford</td>\n",
" <td>124 Yarra St</td>\n",
" <td>3</td>\n",
" <td>h</td>\n",
" <td>1876000.0</td>\n",
" <td>S</td>\n",
" <td>Nelson</td>\n",
" <td>7/05/2016</td>\n",
" <td>2.5</td>\n",
" <td>3067.0</td>\n",
" <td>...</td>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>245.0</td>\n",
" <td>210.0</td>\n",
" <td>1910.0</td>\n",
" <td>Yarra</td>\n",
" <td>-37.8024</td>\n",
" <td>144.9993</td>\n",
" <td>Northern Metropolitan</td>\n",
" <td>4019.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Abbotsford</td>\n",
" <td>98 Charles St</td>\n",
" <td>2</td>\n",
" <td>h</td>\n",
" <td>1636000.0</td>\n",
" <td>S</td>\n",
" <td>Nelson</td>\n",
" <td>8/10/2016</td>\n",
" <td>2.5</td>\n",
" <td>3067.0</td>\n",
" <td>...</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>256.0</td>\n",
" <td>107.0</td>\n",
" <td>1890.0</td>\n",
" <td>Yarra</td>\n",
" <td>-37.8060</td>\n",
" <td>144.9954</td>\n",
" <td>Northern Metropolitan</td>\n",
" <td>4019.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 21 columns</p>\n",
"</div>"
],
"text/plain": [
" Suburb Address Rooms Type Price Method SellerG \\\n",
"1 Abbotsford 25 Bloomburg St 2 h 1035000.0 S Biggin \n",
"2 Abbotsford 5 Charles St 3 h 1465000.0 SP Biggin \n",
"4 Abbotsford 55a Park St 4 h 1600000.0 VB Nelson \n",
"6 Abbotsford 124 Yarra St 3 h 1876000.0 S Nelson \n",
"7 Abbotsford 98 Charles St 2 h 1636000.0 S Nelson \n",
"\n",
" Date Distance Postcode ... Bathroom Car Landsize BuildingArea \\\n",
"1 4/02/2016 2.5 3067.0 ... 1.0 0.0 156.0 79.0 \n",
"2 4/03/2017 2.5 3067.0 ... 2.0 0.0 134.0 150.0 \n",
"4 4/06/2016 2.5 3067.0 ... 1.0 2.0 120.0 142.0 \n",
"6 7/05/2016 2.5 3067.0 ... 2.0 0.0 245.0 210.0 \n",
"7 8/10/2016 2.5 3067.0 ... 1.0 2.0 256.0 107.0 \n",
"\n",
" YearBuilt CouncilArea Lattitude Longtitude Regionname \\\n",
"1 1900.0 Yarra -37.8079 144.9934 Northern Metropolitan \n",
"2 1900.0 Yarra -37.8093 144.9944 Northern Metropolitan \n",
"4 2014.0 Yarra -37.8072 144.9941 Northern Metropolitan \n",
"6 1910.0 Yarra -37.8024 144.9993 Northern Metropolitan \n",
"7 1890.0 Yarra -37.8060 144.9954 Northern Metropolitan \n",
"\n",
" Propertycount \n",
"1 4019.0 \n",
"2 4019.0 \n",
"4 4019.0 \n",
"6 4019.0 \n",
"7 4019.0 \n",
"\n",
"[5 rows x 21 columns]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"melbourne_data.head()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "b3523f16",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(0.0, 1000.0)]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjsAAAHACAYAAABEa6kcAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAArTZJREFUeJzsnXl8VPXV/z+zZyZ7ZhI2s8EEs4JBFmEmKLixipT6PAJtCdGqZdHWWgEFZVOh2tZHUGstoP1VsK0IsrhLKwm4Qsq+ZNgSSCBkyEyW2ZffH5N7meXOnSRkmUzO+/XqqzLLne+dmcz3c8/5nHMEbrfbDYIgCIIgiA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ZDYIQiCIAgioiGxQxAEQRBERENihyAIgiCIiIbEDkEQBEEQEQ2JHYIgCIIgIhoSOwRBEARBRDQkdgiCIAiCiGhI7BAEQRAEEdGQ2CEIgiAIIqIhsUMQBEEQRERDYocgCIIgiIiGxA5BEARBEBENiR2CIAiCICIaEjsEQRAEQUQ0JHYIgiAIgohoSOwQBEEQBBHRkNghCIIgCCKiIbFDEARBEEREQ2KHIAiCIIiIRtzdCyAIwoPRZENdkw0NFjvi5BKooqWIV0i7e1kEQRA9HhI7BBEGVBvMWLT1MEor6tjbxmapsGbGEPRPkHfjygiCIHo+lMYiiG7GaLIFCB0A2FtRh8VbD8NosnXTygiCICIDEjsE0c3UNdkChA7D3oo61DWR2CEIgrgRSOwQRDfTYLHz3t8Y4n6CIAiCHxI7BNHNxEVJeO+PDXE/QRAEwQ+JHYLoZlQxUozNUnHeNzZLBVUMVWQRBEH
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ax = sns.scatterplot(x=melbourne_data['BuildingArea'], y=melbourne_data['Price'])\n",
"ax.set(xlim=(0, 1000))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b3cc3971",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAAGdCAYAAABO2DpVAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAOkJJREFUeJzt3Xl4VPXd/vH3TPaEJKyBQMK+BAJkEUVEiwtIFRFcABNarVp/WoOgCBbcKG7Roli2Um0t8jySICDghqKguIAKmEkI+w6BsEP2ZJLMnN8fbXmKyjLJTE5mcr+ua/7IcE7m5nsNc27O58yMxTAMAxERERE3sJodQERERHyHioWIiIi4jYqFiIiIuI2KhYiIiLiNioWIiIi4jYqFiIiIuI2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1Hmbg4h6KKaiKC/Zk2IoHB8a3MjiU1oGIhIiKmsVc7SF+xnbfX7QcgMbYxs1OTiGkSam4wqTEVCxERMcWBU6WMybCRe7gQgP/3q45MHNyNAD+rycmkNlQsRESkzn286QiT3ttEsb2axqEBTB+ZwPVxLc2OJW7gUi1s3749FovlZ7e0tDRP5RMRER9SUeXg6eW5pGVkUWyvpk+7JqwYe41KhQ9x6YzFhg0bcDgcZ3/evHkzgwYNYsSIEW4PJiIivmXviRLSMmxsO1IEwMPXdmL8oK74a/ThU1wqFi1atDjn55dffplOnToxYMAAt4YSERHf8n72YZ5cmktppYNmYYFMH5XIgK4tLr6jeJ0aX2NRWVnJO++8w/j
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"xplot = [1,2]\n",
"yplot = [3, 8]\n",
"ax = sns.lineplot(x=xplot, y=yplot)"
]
},
{
"cell_type": "markdown",
"id": "b3f8a1a5",
"metadata": {},
"source": [
"Sie plotten verschiedene Dinge in eine Grafik, indem Sie seaborn mehrfach hintereinander innerhalb derselben Codezelle aufrufen. Wir plotten jetzt sowohl die Datenpunkte von oben, als auch eine Gerade:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "410a31ee",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6196"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(melbourne_data)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "fb578f78",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Axes: xlabel='BuildingArea', ylabel='Price'>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAioAAAHACAYAAACMB0PKAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlw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ICAmzQOiIyh7JJheyNhQYhRScjOQz/nDsKgT4eIrSMiMRkzvVbMnNU1Go1Nm3ahMbGRqSnp4vdHCKygOoGVbchBQB2nq1GdQOHgIhsoa6lDTm5ClTVt4jdFLOJOvQDAMeOHUN6ejpaWlrg5+eHzZs3Y9iwYd0+trW1Fa2trfqf6+rqbNVMIuqDupa2Xu+vN3I/EfXPlYZWrNtdgg/3nEd9azvqWtqwfNZQsZtlFtGDyuDBg3H48GEolUp89tlnmDdvHvLz87sNKytWrMCLL74oQiuJqC8CvNx7vd/fyP1E1DeVyha8u7MYG/eXorlNDQBIDvfDiOggcRvWB5KbozJ9+nQkJSXhnXfe6XJfdz0qMTExnKNCJFHKJhWe3FiInZyjQmQTpVeasCa/CJ8XXIBKrQEApA4KRFamHLcOGwgXF5nILdQyZ46K6D0q19NoNAZhpDNPT094enrauEVE1FeBPh5YOScNyz4/ahBWMpLD8MqcNIYUIgs5e6keq/OK8N8j5VBrtP0PY+NDkDVVjozkMMhk0ggofSFqUFm+fDlmzZqF2NhY1NfX4+OPP0ZeXh6+/fZbMZtFRBYUFeSNf84dheoGFepb2uDv5Y4wPw+
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ax = sns.scatterplot(x=melbourne_data['BuildingArea'][:100], y=melbourne_data['Price'][:100])\n",
"xplot = [0,300]\n",
"yplot = [1e5, 3e6]\n",
"sns.lineplot(x=xplot, y=yplot)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "223eeae8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l = [1,2,3]\n",
"l.append(4)\n",
"l"
]
},
{
"cell_type": "markdown",
"id": "8e335cc5",
"metadata": {},
"source": [
"So könnte man die Feature-Matrix X und den Vektor der Outputs erstellen:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "30b87fbd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"l1 = [1,2,3]\n",
"l2 = [4]\n",
"l1 + l2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "a5215abe",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[1, 2, 3], [4, 5, 6]]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"M = [\n",
" [1,2,3],\n",
" [4,5,6]\n",
"]\n",
"M"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "791052f6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1, 2, 3],\n",
" [4, 5, 6]])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array(M)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "79166874",
"metadata": {},
"outputs": [],
"source": [
"X = []\n",
"Y = []\n",
"for i, row in melbourne_data.iterrows():\n",
" X.append([1] + [row['BuildingArea']])\n",
" Y.append(row['Price'])\n",
"\n",
"# Für Matrixmultiplikation eiget sich numpy besser, daher wandeln wir die Python-Listen in numpy arrays um:\n",
"X = np.array(X)\n",
"Y = np.array(Y)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "23f97e97",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1. , 79. ],\n",
" [ 1. , 150. ],\n",
" [ 1. , 142. ],\n",
" ...,\n",
" [ 1. , 35.64],\n",
" [ 1. , 61.6 ],\n",
" [ 1. , 388.5 ]], shape=(6196, 2))"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X"
]
},
{
"cell_type": "markdown",
"id": "860aea24",
"metadata": {},
"source": [
"### Slicen von numpy arrays"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "69d5eed6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1. 79.]\n",
" [ 1. 150.]\n",
" [ 1. 142.]\n",
" [ 1. 210.]\n",
" [ 1. 107.]]\n",
"[1035000. 1465000. 1600000. 1876000. 1636000. 1097000. 1350000.]\n"
]
}
],
"source": [
"# slicen von numpy arrays\n",
"print(X[:5])\n",
"print(Y[:7])"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "a5ebf4dd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 79. 150. 142. ... 35.64 61.6 388.5 ]\n"
]
}
],
"source": [
"# slicen von numpy arrays: Auswahl einer Spalte\n",
"print(X[:,1])"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "796dfee7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 79. 150. 142. 210. 107.]\n"
]
}
],
"source": [
"# slicen von numpy arrays: die ersten 5 Zeilen von Spalte 2 (also index 1):\n",
"print(X[:5,1])"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "681e36cf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1. 1. 1. 1. 1.]\n"
]
}
],
"source": [
"# slicen von numpy arrays: die ersten 5 Zeilen von Spalte 1 (also index ):\n",
"print(X[:5,0])"
]
},
{
"cell_type": "markdown",
"id": "ce97c986",
"metadata": {},
"source": [
"### Multiplikation bei numpy arrays\n",
"\n",
"Sie können numpy arrays sowohl elementweise multiplizieren als auch als Matrixmultiplikation."
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "6f4cabc0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"str"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = 'asdas {}'\n",
"type(s)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "73cc9eb1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'a: 7.1234567'"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = 7.1234567\n",
"s = 'a: {}'.format(a)\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "c853f2d8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a: [1 1 1]\n",
"b: [1 2 3]\n",
"elementweise Operationen:\n",
"a+b: [2 3 4]\n",
"a*b: [1 2 3]\n",
"a/b: [1. 0.5 0.33333333]\n",
"\n",
"Skalarprodukt:\n",
"a@b: 6\n",
"\n",
"Matrix x Vektor:\n",
"M:\n",
"[[1 3]\n",
" [2 1]]\n",
"x: [1 1]\n",
"M@x: [4 3]\n",
"\n",
"Matrix transponieren:\n",
"M.T:\n",
"[[1 2]\n",
" [3 1]]\n"
]
}
],
"source": [
"a = np.array([1,1,1])\n",
"b = np.array([1,2,3])\n",
"print('a: {}'.format(a))\n",
"print('b: {}'.format(b))\n",
"\n",
"print('elementweise Operationen:')\n",
"print('a+b: {}'.format(a+b))\n",
"print('a*b: {}'.format(a*b))\n",
"print('a/b: {}'.format(a/b))\n",
"\n",
"print()\n",
"print('Skalarprodukt:')\n",
"print('a@b: {}'.format(a@b))\n",
"\n",
"print()\n",
"print('Matrix x Vektor:')\n",
"M = np.array([[1,3], [2,1]])\n",
"x = np.array([1,1])\n",
"print('M:\\n{}'.format(M))\n",
"print('x: {}'.format(x))\n",
"print('M@x: {}'.format(M@x))\n",
"\n",
"print()\n",
"print('Matrix transponieren:')\n",
"print('M.T:\\n{}'.format(M.T))"
]
},
{
"cell_type": "markdown",
"id": "e0577f21",
"metadata": {},
"source": [
"## Analytische Lösung der linearen Regression\n",
"\n",
"`np.linalg.solve(A, b)` berechnet $w$ im linearen Gleichungssystem\n",
"\n",
"$ A w = b $\n",
"\n",
"$A$ - Matrix,\n",
"$w$ - Vektor (unsere unbekannten),\n",
"$b$ - Vektor.\n",
"\n",
"Wir suchen die Lösung $w$ im folgenden Gleichungssystem:\n",
"\n",
"$$ X^T X w = X^T Y $$\n",
"\n",
"Mit $A = X^TX$ und $b = X^T Y$ berechnet `np.linalg.solve(A, b)` unsere gesuchten Paramter für die lineare Regression."
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "35a78137",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[510531.72552189 3943.64499525]\n",
"CPU times: user 302 μs, sys: 10 μs, total: 312 μs\n",
"Wall time: 316 μs\n"
]
}
],
"source": [
"%%time\n",
"w_ana = np.linalg.solve(X.T @ X, X.T @ Y)\n",
"print(w_ana)"
]
}
],
"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.10.12"
},
"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": 5
}