<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Norman&#39;s Academic Blog</title>
<link>https://www.sefiroth.de/blog.html</link>
<atom:link href="https://www.sefiroth.de/blog.xml" rel="self" type="application/rss+xml"/>
<description>Norman&#39;s Academic Blog</description>
<generator>quarto-1.9.38</generator>
<lastBuildDate>Wed, 17 Jun 2026 22:00:00 GMT</lastBuildDate>
<item>
  <title>Die Log-Loss Funktion</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-06-18-die-log-loss-funktion/</link>
  <description><![CDATA[ 





<section id="die-log-loss-funktion" class="level1">
<h1>Die Log-Loss Funktion</h1>
<p>Der <strong>Logarithmischer Verlust</strong> (engl. <strong>log loss</strong>), allgemein bekannt als <em>Log Loss</em> oder <em>Cross-Entropy Loss</em>, ist eine zentrale Kennzahl im Machine Learning, insbesondere bei Klassifikationsproblemen. Er bewertet die Leistung eines Klassifikationsmodells, indem er den Unterschied zwischen vorhergesagten Wahrscheinlichkeiten und den tatsächlichen Ergebnissen misst. Wie werfen einen Blick auf das Konzept hinter <em>Log Loss</em>, seiner Bedeutung und zeigen ein praktisches Beispiel mit <strong>Python</strong> und <code>scikit-learn</code>.</p>
<section id="was-ist-log-loss" class="level2">
<h2 class="anchored" data-anchor-id="was-ist-log-loss">Was ist Log Loss?</h2>
<p><strong>Log Loss</strong> ist eine logarithmische Transformation der Likelihood‑Funktion und wird hauptsächlich zur Bewertung der Leistung probabilistischer Klassifikatoren verwendet. Im Gegensatz zu anderen Metriken wie der Genauigkeit berücksichtigt Log Loss die Unsicherheit von Vorhersagen, indem Modelle für selbstbewusst falsche Vorhersagen deutlich stärker bestraft werden.</p>
<p>Die Formal lautet:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cbegin%7Balign*%7D%0A%20%20LogLoss%0A%20%20&amp;=%20-%20%5Cfrac%7B1%7D%7BN%7D%20%5Csum_%7Bi=1%7D%5E%7BN%7D%0A%20%20%5Cbegin%7Bcases%7D%0A%20%20%20%20%20%20%5Clog(p_i)%20&amp;:%20y_i%20=%201%20%5C%5C%0A%20%20%20%20%20%20%5Clog(1-p_i)%20&amp;:%20y_i%20=%200%0A%20%20%20%20%5Cend%7Bcases%7D%20%5C%5C%0A%20%20%20%20&amp;=%20-%5Cfrac%7B1%7D%7BN%7D%20%5Csum_%7Bi=1%7D%5E%7BN%7D%20%20%5Cleft(y_i%20%5Clog(p_i)%20+%20%20(1-y_i)%20%5Clog(1-p_i)%5Cright)%0A%20%20%5Cend%7Balign*%7D%0A"> Wobei:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?N"> die Anzahl der Beobachtungen ist.</li>
<li><img src="https://latex.codecogs.com/png.latex?y_i"> ist die binäre Vorhersage (also <img src="https://latex.codecogs.com/png.latex?0"> oder <img src="https://latex.codecogs.com/png.latex?1">) der i. Beobachtung.</li>
<li><img src="https://latex.codecogs.com/png.latex?p_i"> ist die Vorhersagewahrscheinlichkeit, das die i. Beobachtung zur Klasse <img src="https://latex.codecogs.com/png.latex?1"> gehört.</li>
</ul>
</section>
<section id="verständnis-von-log-losswerten" class="level2">
<h2 class="anchored" data-anchor-id="verständnis-von-log-losswerten">Verständnis von Log Loss‑Werten</h2>
<p>Ein niedriger Log Loss weist auf eine bessere Modellleistung hin. Ein Log Loss von <img src="https://latex.codecogs.com/png.latex?0"> bedeutet, dass die vorhergesagten Wahrscheinlichkeiten die tatsächlichen Ergebnisse perfekt widerspiegeln, während höhere Werte auf zunehmende Abweichungen hinweisen. Es ist wichtig zu beachten, dass Log Loss empfindlich auf die Sicherheit der Vorhersagen reagiert, was ihn zu einer leistungsstarken Kennzahl für die Bewertung probabilistischer Modelle macht.</p>
</section>
<section id="log-loss-in-klassifikationsproblemen" class="level2">
<h2 class="anchored" data-anchor-id="log-loss-in-klassifikationsproblemen">Log Loss in Klassifikationsproblemen</h2>
<p>Log Loss wird häufig in binären und multiklassigen Klassifikationsproblemen verwendet, insbesondere bei Modellen, die Wahrscheinlichkeitswerte für jede Klasse ausgeben (z.B. logistische Regression, neuronale Netze). Er motiviert Modelle dazu, nicht nur korrekt, sondern auch sicher in ihren Vorhersagen zu sein, was ihn besonders nützlich in Szenarien macht, in denen Fehlklassifikationen unterschiedlich hohe Kosten verursachen.</p>
<section id="beispiel-in-python" class="level3">
<h3 class="anchored" data-anchor-id="beispiel-in-python">Beispiel in Python</h3>
<div id="ec724d99" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.metrics <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> log_loss</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.linear_model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> LogisticRegression</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.model_selection <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> train_test_split</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.datasets <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> make_classification</span>
<span id="cb1-5"></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. Beispiel-Daten erzeugen (binäre Klassifikation)</span></span>
<span id="cb1-7">X, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_classification(</span>
<span id="cb1-8">    n_samples<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,</span>
<span id="cb1-9">    n_features<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb1-10">    n_informative<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb1-11">    n_redundant<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb1-12">    random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span></span>
<span id="cb1-13">)</span>
<span id="cb1-14"></span>
<span id="cb1-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. Train/Test-Split</span></span>
<span id="cb1-16">X_train, X_test, y_train, y_test <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> train_test_split(</span>
<span id="cb1-17">    X, y, test_size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span></span>
<span id="cb1-18">)</span>
<span id="cb1-19"></span>
<span id="cb1-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 3. Modell trainieren</span></span>
<span id="cb1-21">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> LogisticRegression()</span>
<span id="cb1-22">model.fit(X_train, y_train)</span>
<span id="cb1-23"></span>
<span id="cb1-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 4. Wahrscheinlichkeiten vorhersagen</span></span>
<span id="cb1-25">y_pred_proba <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.predict_proba(X_test)</span>
<span id="cb1-26"></span>
<span id="cb1-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 5. Log Loss berechnen</span></span>
<span id="cb1-28">loss <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> log_loss(y_test, y_pred_proba)</span>
<span id="cb1-29"></span>
<span id="cb1-30"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Log Loss: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>loss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Log Loss: 0.3049</code></pre>
</div>
</div>
<p>Ein LogLoss von <img src="https://latex.codecogs.com/png.latex?%60python%20print(f%22%7Bloss:.4%7D%22))%60"> bedeutet, das Modell relativ gut kalibriert ist. Die vorhergesagten Wahrscheinlichkeiten liegen meist nah an den tatsächlichen Werten (<strong>Labels</strong>). Es macht wenige selbstbewusst falsche Vorhersagen.</p>
<p>Die LogLoss Funktion gibt es aber auch für nicht-binäre Vorhersagen.</p>
<p>Wir sprechen dann auch von <strong>Multicast-Log-Loss</strong>.</p>
</section>
<section id="beispiel-in-python-1" class="level3">
<h3 class="anchored" data-anchor-id="beispiel-in-python-1">Beispiel in Python</h3>
<div id="a9171ac3" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.datasets <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> make_classification</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.model_selection <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> train_test_split</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.linear_model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> LogisticRegression</span>
<span id="cb3-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.metrics <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> log_loss</span>
<span id="cb3-5"></span>
<span id="cb3-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. Synthetisches Multiclass-Dataset erzeugen</span></span>
<span id="cb3-7">X, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_classification(</span>
<span id="cb3-8">    n_samples<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>,</span>
<span id="cb3-9">    n_features<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb3-10">    n_informative<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb3-11">    n_redundant<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb3-12">    n_classes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Multiclass!</span></span>
<span id="cb3-13">    n_clusters_per_class<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb3-14">    random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span></span>
<span id="cb3-15">)</span>
<span id="cb3-16"></span>
<span id="cb3-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. Train/Test-Split</span></span>
<span id="cb3-18">X_train, X_test, y_train, y_test <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> train_test_split(</span>
<span id="cb3-19">    X, y, test_size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span></span>
<span id="cb3-20">)</span>
<span id="cb3-21"></span>
<span id="cb3-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 3. Multiclass-Logistische Regression (softmax)</span></span>
<span id="cb3-23">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> LogisticRegression(solver<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lbfgs"</span>)</span>
<span id="cb3-24">model.fit(X_train, y_train)</span>
<span id="cb3-25"></span>
<span id="cb3-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 4. Wahrscheinlichkeiten für alle Klassen vorhersagen</span></span>
<span id="cb3-27">y_pred_proba <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.predict_proba(X_test)</span>
<span id="cb3-28"></span>
<span id="cb3-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 5. Multiclass Log Loss berechnen</span></span>
<span id="cb3-30">loss <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> log_loss(y_test, y_pred_proba)</span>
<span id="cb3-31"></span>
<span id="cb3-32"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Multiclass Log Loss: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>loss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:.4}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Multiclass Log Loss: 0.2195</code></pre>
</div>
</div>
</section>
</section>
<section id="mathematische-definition" class="level2">
<h2 class="anchored" data-anchor-id="mathematische-definition">Mathematische Definition</h2>
<p>Für ein Klassifikationsproblem mit <img src="https://latex.codecogs.com/png.latex?N"> Beobachtungen und <img src="https://latex.codecogs.com/png.latex?K"> Klassen lautet der <strong>Logarithmic Loss</strong> (<strong>Cross‑Entropy Loss</strong>):</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20LogLoss%20=%20-%5Cfrac%7B1%7D%7BN%7D%20%5Csum_%7Bi=1%7D%5E%7BN%7D%20%20%5Csum_%7Bk=1%7D%5E%7BK%7D%20y_%7Bi,k%7D%20%5Clog(p_%7Bi,k%7D)%0A"></p>
<p>wobei:</p>
<ul>
<li><p><img src="https://latex.codecogs.com/png.latex?y_%7Bi,k%7D"> : <strong>One-Hot-Label</strong> der wahren Klasse. (1, wenn Beispiel <img src="https://latex.codecogs.com/png.latex?i"> zur Klasse <img src="https://latex.codecogs.com/png.latex?k"> gehört, sonst <img src="https://latex.codecogs.com/png.latex?0">)</p></li>
<li><p><img src="https://latex.codecogs.com/png.latex?p_%7Bi,k%7D"> : Vorhergesagte Wahrscheinlichkeit, dass Beispiel <img src="https://latex.codecogs.com/png.latex?i"> zur Klasse <img src="https://latex.codecogs.com/png.latex?k"> gehört (vom Modell ausgegeben, z.B. durch Softmax)</p></li>
<li><p><img src="https://latex.codecogs.com/png.latex?N"> : Anzahl der Datenpunkte</p></li>
<li><p><img src="https://latex.codecogs.com/png.latex?K"> : Anzahl der Klassen</p></li>
</ul>
</section>
<section id="intuitive-interpätation-der-werte" class="level2">
<h2 class="anchored" data-anchor-id="intuitive-interpätation-der-werte">Intuitive Interpätation der Werte</h2>
<p>Wenn das Modell hohe Wahrscheinlichkeit für die richtige Klasse vergibt <img src="https://latex.codecogs.com/png.latex?%5CRightarrow"> kleiner Log Loss</p>
<p>Wenn das Modell sicher falsch liegt <img src="https://latex.codecogs.com/png.latex?%5CRightarrow"> großer Log Loss</p>
<p>Perfekte Vorhersagen <img src="https://latex.codecogs.com/png.latex?%5CRightarrow"> Log Loss = 0</p>
<p>Typische Werte liegen zwischen <img src="https://latex.codecogs.com/png.latex?0.1"> und <img src="https://latex.codecogs.com/png.latex?0.7">, je nach Schwierigkeit des Problems.</p>


</section>
</section>

 ]]></description>
  <category>Phyton</category>
  <category>Metriken der KI</category>
  <category>KI</category>
  <category>Machine Learning</category>
  <category>Klassifikation</category>
  <category>LogLoss</category>
  <category>Log Loss</category>
  <category>Cross-Entropy Loss</category>
  <guid>https://www.sefiroth.de/posts/2026-06-18-die-log-loss-funktion/</guid>
  <pubDate>Wed, 17 Jun 2026 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Logarithmischer Verlust oder Genauigkeit?</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-06-18-genauigkeit-vs-logloss/</link>
  <description><![CDATA[ 





<section id="accuracy-vs.-log-loss" class="level2">
<h2 class="anchored" data-anchor-id="accuracy-vs.-log-loss">Accuracy vs.&nbsp;Log Loss</h2>
<section id="genauigkeit" class="level3">
<h3 class="anchored" data-anchor-id="genauigkeit">Genauigkeit</h3>
<p>Genauigkeit (engl. <strong>Accuracy</strong>) misst nur richtig oder falsch Accuracy berechnet den Anteil korrekt vorhergesagter Klassen:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Ctext%7BAccuracy%7D%20=%20%5Cfrac%7B%5Ctext%7Bkorrekte%20Vorhersagen%7D%7D%7B%5Ctext%7Balle%20Vorhersagen%7D%7D%0A"></p>
<ul>
<li>Jede Vorhersage zählt <strong>gleich viel</strong><br>
</li>
<li>Die <strong>Höhe der Wahrscheinlichkeit</strong> spielt <strong>keine Rolle</strong><br>
</li>
<li>Ein Modell mit 51 % Wahrscheinlichkeit für die richtige Klasse gilt als <strong>genauso korrekt</strong> wie eines mit 99 %</li>
</ul>
<p><strong>Vorteil:</strong> Einfach zu verstehen<br>
<strong>Nachteil:</strong> Ignoriert Unsicherheit und Kalibrierung</p>
</section>
<section id="logarithmischer-verlust" class="level3">
<h3 class="anchored" data-anchor-id="logarithmischer-verlust">Logarithmischer Verlust</h3>
<p>Logarithmischer Verlust (engl. <strong>Log Loss</strong>) misst die Qualität der Wahrscheinlichkeiten Log Loss bewertet, wie gut die vorhergesagten Wahrscheinlichkeiten zu den tatsächlichen Labels passen.</p>
<ul>
<li>Bestraft <strong>selbstbewusst falsche</strong> Vorhersagen stark<br>
</li>
<li>Belohnt <strong>gut kalibrierte</strong> Wahrscheinlichkeiten<br>
</li>
<li>Nutzt die vollständige Wahrscheinlichkeitsverteilung (z. B. Softmax)</li>
</ul>
<p><strong>Vorteil:</strong> Sehr empfindlich gegenüber Unsicherheit<br>
<strong>Nachteil:</strong> Schwerer zu interpretieren als Accuracy</p>
</section>
</section>
<section id="konkretes-beispiel" class="level2">
<h2 class="anchored" data-anchor-id="konkretes-beispiel">Konkretes Beispiel</h2>
<table class="caption-top table">
<colgroup>
<col style="width: 12%">
<col style="width: 16%">
<col style="width: 28%">
<col style="width: 14%">
<col style="width: 14%">
<col style="width: 14%">
</colgroup>
<thead>
<tr class="header">
<th>Beispiel</th>
<th>Vorhersage</th>
<th>Wahrscheinlichkeit</th>
<th>Richtig?</th>
<th>Accuracy</th>
<th>Log Loss</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Modell A</td>
<td>Klasse 1</td>
<td>0.51</td>
<td>✔️</td>
<td>gut</td>
<td>gut</td>
</tr>
<tr class="even">
<td>Modell B</td>
<td>Klasse 1</td>
<td>0.99</td>
<td>✔️</td>
<td>gut</td>
<td><strong>viel besser</strong></td>
</tr>
</tbody>
</table>
<p><strong>Accuracy sagt:</strong> Beide Modelle sind gleich gut.<br>
<strong>Log Loss sagt:</strong> Modell B ist deutlich besser, weil es sicherer und besser kalibriert ist.</p>
</section>
<section id="wann-verwende-ich-eher-was" class="level2">
<h2 class="anchored" data-anchor-id="wann-verwende-ich-eher-was">Wann verwende ich (eher) was?</h2>
<section id="verwende-genauigkeit-wenn" class="level3">
<h3 class="anchored" data-anchor-id="verwende-genauigkeit-wenn">Verwende Genauigkeit, wenn:</h3>
<ul>
<li>nur die Endentscheidung zählt<br>
</li>
<li>Wahrscheinlichkeiten egal sind<br>
</li>
<li>Klassen ausgewogen sind</li>
</ul>
<p><strong>Beispiele:</strong></p>
<ul>
<li>Spam / Nicht‑Spam<br>
</li>
<li>Katzen oder Hunde</li>
</ul>
</section>
<section id="verwende-logarithmischer-verlust-wenn" class="level3">
<h3 class="anchored" data-anchor-id="verwende-logarithmischer-verlust-wenn">Verwende Logarithmischer Verlust, wenn:</h3>
<ul>
<li>Wahrscheinlichkeiten wichtig sind<br>
</li>
<li>Fehlklassifikationen unterschiedlich teuer sind<br>
</li>
<li>du Modelle vergleichen willst, die Wahrscheinlichkeiten ausgeben<br>
</li>
<li>du Kalibrierung bewerten willst</li>
</ul>
<p><strong>Beispiele:</strong></p>
<ul>
<li>Medizinische Diagnosen<br>
</li>
<li>Kreditrisiko<br>
</li>
<li>Unbalancierte Klassen</li>
</ul>
</section>
</section>
<section id="fazit" class="level2">
<h2 class="anchored" data-anchor-id="fazit">Fazit</h2>
<blockquote class="blockquote">
<p><strong>Accuracy misst, ob du richtig liegst.</strong><br>
<strong>Log Loss misst, wie gut du weißt, dass du richtig liegst.</strong></p>
</blockquote>


</section>

 ]]></description>
  <category>Phyton</category>
  <category>Metriken der KI</category>
  <category>KI</category>
  <category>Machine Learning</category>
  <category>Klassifikation</category>
  <category>Log Loss</category>
  <category>LogLoss</category>
  <category>Accuracy</category>
  <category>Genauigkeit</category>
  <guid>https://www.sefiroth.de/posts/2026-06-18-genauigkeit-vs-logloss/</guid>
  <pubDate>Wed, 17 Jun 2026 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Lineare und logistische Regression in Python</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-05-30-lineare-und-logistische-regression-mit-python/</link>
  <description><![CDATA[ 





<section id="vorbereitung" class="level2">
<h2 class="anchored" data-anchor-id="vorbereitung">Vorbereitung</h2>
<p>Wir laden die Schwertlinien Datentabelle (engl. <em>iris flower data set</em>) von Anderson bzw. Fisher. <sup>1</sup></p>
<p>Die Datentabelle enthält 150 Messungen von fünf Attributen:</p>
<ul>
<li>Länge des Kelchblatts (sepal length in cm),</li>
<li>Breite des Kelchblatts (sepal width in cm),</li>
<li>Länge des Kronblatts (petal length in cm),</li>
<li>Breite des Kronblatts (petal width in cm) sowie</li>
<li>Spezies (Iris setosa = 0, Iris versicolor = 1 und Iris virginica = 2)</li>
</ul>
<p>Wir laden sie aus dem Paket <code>sklearn.datasets</code> mit dem Befehl <code>load_iris()</code>:</p>
<div id="65dd7557" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.datasets <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> load_iris</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-3"></span>
<span id="cb1-4">iris <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> load_iris()</span>
<span id="cb1-5">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(iris.data, columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>iris.feature_names)</span>
<span id="cb1-6">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> iris.target</span>
<span id="cb1-7"></span>
<span id="cb1-8">X.head()</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="36">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">sepal length (cm)</th>
<th data-quarto-table-cell-role="th">sepal width (cm)</th>
<th data-quarto-table-cell-role="th">petal length (cm)</th>
<th data-quarto-table-cell-role="th">petal width (cm)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>5.1</td>
<td>3.5</td>
<td>1.4</td>
<td>0.2</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>4.9</td>
<td>3.0</td>
<td>1.4</td>
<td>0.2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>4.7</td>
<td>3.2</td>
<td>1.3</td>
<td>0.2</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>4.6</td>
<td>3.1</td>
<td>1.5</td>
<td>0.2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>5.0</td>
<td>3.6</td>
<td>1.4</td>
<td>0.2</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<div id="44c51e76" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">y</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="37">
<pre><code>array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])</code></pre>
</div>
</div>
</section>
<section id="einfache-lineare-regression" class="level2">
<h2 class="anchored" data-anchor-id="einfache-lineare-regression">(Einfache) Lineare Regression</h2>
<p>Wir beginnen mit einer einfachen linearen Regression. Dabei erstellen wir ein Model, bei dem wir die Länge des Kronblatts (<em>petal length</em>) auf Grundlage der Länge des Kelchblatts (<em>sepal length</em>) modellieren wollen.</p>
<div id="bfe50be8" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.linear_model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> LinearRegression</span>
<span id="cb4-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.model_selection <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> train_test_split</span>
<span id="cb4-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.metrics <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> mean_squared_error</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zielvariable y_reg: Petal Length</span></span>
<span id="cb4-6">y_reg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"petal length (cm)"</span>]</span>
<span id="cb4-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Modellierungsvariable X_reg: Sepal Legth</span></span>
<span id="cb4-8">X_reg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X.drop(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"petal length (cm)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sepal width (cm)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"petal width (cm)"</span>])</span></code></pre></div></div>
</div>
<p>Wir teilen nun unsere Daten in Test- und Trainingsdaten auf. Dabei sollen <img src="https://latex.codecogs.com/png.latex?0.2=20%5C,%5C%25"> der Daten zu Testdaten werden und <img src="https://latex.codecogs.com/png.latex?1-0.2=0.8=80%5C,%5C%25"> zu Trainingsdaten.</p>
<p>Die Auswahl erfolgt zufällig. Wobei wir hier einen mit <code>random_state=2009</code> dafür sorgen, dass dieser Zufall reproduzierbar ist.</p>
<div id="45943d47" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Aufteilen in Test- und Trainingsdaten</span></span>
<span id="cb5-2">X_train, X_test, y_train, y_test <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> train_test_split(X_reg, y_reg, test_size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span></code></pre></div></div>
</div>
<p>Nun erstellen wir das lineare Regressionmodell und trainieren dieses mit den Daten <code>X_train</code> und <code>y_train</code></p>
<div id="2dda953f" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Modell</span></span>
<span id="cb6-2">linreg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> LinearRegression()</span>
<span id="cb6-3">linreg.fit(X_train, y_train)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="40">
<style>#sk-container-id-5 {
  /* Definition of color scheme common for light and dark mode */
  --sklearn-color-text: #000;
  --sklearn-color-text-muted: #666;
  --sklearn-color-line: gray;
  /* Definition of color scheme for unfitted estimators */
  --sklearn-color-unfitted-level-0: #fff5e6;
  --sklearn-color-unfitted-level-1: #f6e4d2;
  --sklearn-color-unfitted-level-2: #ffe0b3;
  --sklearn-color-unfitted-level-3: chocolate;
  /* Definition of color scheme for fitted estimators */
  --sklearn-color-fitted-level-0: #f0f8ff;
  --sklearn-color-fitted-level-1: #d4ebff;
  --sklearn-color-fitted-level-2: #b3dbfd;
  --sklearn-color-fitted-level-3: cornflowerblue;
}

#sk-container-id-5.light {
  /* Specific color for light theme */
  --sklearn-color-text-on-default-background: black;
  --sklearn-color-background: white;
  --sklearn-color-border-box: black;
  --sklearn-color-icon: #696969;
}

#sk-container-id-5.dark {
  --sklearn-color-text-on-default-background: white;
  --sklearn-color-background: #111;
  --sklearn-color-border-box: white;
  --sklearn-color-icon: #878787;
}

#sk-container-id-5 {
  color: var(--sklearn-color-text);
}

#sk-container-id-5 pre {
  padding: 0;
}

#sk-container-id-5 input.sk-hidden--visually {
  border: 0;
  clip: rect(1px 1px 1px 1px);
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

#sk-container-id-5 div.sk-dashed-wrapped {
  border: 1px dashed var(--sklearn-color-line);
  margin: 0 0.4em 0.5em 0.4em;
  box-sizing: border-box;
  padding-bottom: 0.4em;
  background-color: var(--sklearn-color-background);
}

#sk-container-id-5 div.sk-container {
  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`
     but bootstrap.min.css set `[hidden] { display: none !important; }`
     so we also need the `!important` here to be able to override the
     default hidden behavior on the sphinx rendered scikit-learn.org.
     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
  display: inline-block !important;
  position: relative;
}

#sk-container-id-5 div.sk-text-repr-fallback {
  display: none;
}

div.sk-parallel-item,
div.sk-serial,
div.sk-item {
  /* draw centered vertical line to link estimators */
  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
  background-size: 2px 100%;
  background-repeat: no-repeat;
  background-position: center center;
}

/* Parallel-specific style estimator block */

#sk-container-id-5 div.sk-parallel-item::after {
  content: "";
  width: 100%;
  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
  flex-grow: 1;
}

#sk-container-id-5 div.sk-parallel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background-color: var(--sklearn-color-background);
  position: relative;
}

#sk-container-id-5 div.sk-parallel-item {
  display: flex;
  flex-direction: column;
}

#sk-container-id-5 div.sk-parallel-item:first-child::after {
  align-self: flex-end;
  width: 50%;
}

#sk-container-id-5 div.sk-parallel-item:last-child::after {
  align-self: flex-start;
  width: 50%;
}

#sk-container-id-5 div.sk-parallel-item:only-child::after {
  width: 0;
}

/* Serial-specific style estimator block */

#sk-container-id-5 div.sk-serial {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--sklearn-color-background);
  padding-right: 1em;
  padding-left: 1em;
}


/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/

/* Pipeline and ColumnTransformer style (default) */

#sk-container-id-5 div.sk-toggleable {
  /* Default theme specific background. It is overwritten whether we have a
  specific estimator or a Pipeline/ColumnTransformer */
  background-color: var(--sklearn-color-background);
}

/* Toggleable label */
#sk-container-id-5 label.sk-toggleable__label {
  cursor: pointer;
  display: flex;
  width: 100%;
  margin-bottom: 0;
  padding: 0.5em;
  box-sizing: border-box;
  text-align: center;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}

#sk-container-id-5 label.sk-toggleable__label .caption {
  font-size: 0.6rem;
  font-weight: lighter;
  color: var(--sklearn-color-text-muted);
}

#sk-container-id-5 label.sk-toggleable__label-arrow:before {
  /* Arrow on the left of the label */
  content: "▸";
  float: left;
  margin-right: 0.25em;
  color: var(--sklearn-color-icon);
}

#sk-container-id-5 label.sk-toggleable__label-arrow:hover:before {
  color: var(--sklearn-color-text);
}

/* Toggleable content - dropdown */

#sk-container-id-5 div.sk-toggleable__content {
  display: none;
  text-align: left;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-5 div.sk-toggleable__content.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-5 div.sk-toggleable__content pre {
  margin: 0.2em;
  border-radius: 0.25em;
  color: var(--sklearn-color-text);
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-5 div.sk-toggleable__content.fitted pre {
  /* unfitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-5 input.sk-toggleable__control:checked~div.sk-toggleable__content {
  /* Expand drop-down */
  display: block;
  width: 100%;
  overflow: visible;
}

#sk-container-id-5 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
  content: "▾";
}

/* Pipeline/ColumnTransformer-specific style */

#sk-container-id-5 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-5 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator-specific style */

/* Colorize estimator box */
#sk-container-id-5 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-5 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

#sk-container-id-5 div.sk-label label.sk-toggleable__label,
#sk-container-id-5 div.sk-label label {
  /* The background is the default theme color */
  color: var(--sklearn-color-text-on-default-background);
}

/* On hover, darken the color of the background */
#sk-container-id-5 div.sk-label:hover label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

/* Label box, darken color on hover, fitted */
#sk-container-id-5 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator label */

#sk-container-id-5 div.sk-label label {
  font-family: monospace;
  font-weight: bold;
  line-height: 1.2em;
}

#sk-container-id-5 div.sk-label-container {
  text-align: center;
}

/* Estimator-specific */
#sk-container-id-5 div.sk-estimator {
  font-family: monospace;
  border: 1px dotted var(--sklearn-color-border-box);
  border-radius: 0.25em;
  box-sizing: border-box;
  margin-bottom: 0.5em;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-5 div.sk-estimator.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

/* on hover */
#sk-container-id-5 div.sk-estimator:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-5 div.sk-estimator.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Specification for estimator info (e.g. "i" and "?") */

/* Common style for "i" and "?" */

.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
  float: right;
  font-size: smaller;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1em;
  height: 1em;
  width: 1em;
  text-decoration: none !important;
  margin-left: 0.5em;
  text-align: center;
  /* unfitted */
  border: var(--sklearn-color-unfitted-level-3) 1pt solid;
  color: var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3) 1pt solid;
  color: var(--sklearn-color-fitted-level-3);
}

/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-unfitted-level-0);
  text-decoration: none;
}

div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-fitted-level-0);
  text-decoration: none;
}

/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
  display: none;
  z-index: 9999;
  position: relative;
  font-weight: normal;
  right: .2ex;
  padding: .5ex;
  margin: .5ex;
  width: min-content;
  min-width: 20ex;
  max-width: 50ex;
  color: var(--sklearn-color-text);
  box-shadow: 2pt 2pt 4pt #999;
  /* unfitted */
  background: var(--sklearn-color-unfitted-level-0);
  border: .5pt solid var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted span {
  /* fitted */
  background: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3);
}

.sk-estimator-doc-link:hover span {
  display: block;
}

/* "?"-specific style due to the `<a>` HTML tag */

#sk-container-id-5 a.estimator_doc_link {
  float: right;
  font-size: 1rem;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1rem;
  height: 1rem;
  width: 1rem;
  text-decoration: none;
  /* unfitted */
  color: var(--sklearn-color-unfitted-level-1);
  border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}

#sk-container-id-5 a.estimator_doc_link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-1) 1pt solid;
  color: var(--sklearn-color-fitted-level-1);
}

/* On hover */
#sk-container-id-5 a.estimator_doc_link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  color: var(--sklearn-color-background);
  text-decoration: none;
}

#sk-container-id-5 a.estimator_doc_link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
}

.estimator-table {
    font-family: monospace;
}

.estimator-table summary {
    padding: .5rem;
    cursor: pointer;
}

.estimator-table summary::marker {
    font-size: 0.7rem;
}

.estimator-table details[open] {
    padding-left: 0.1rem;
    padding-right: 0.1rem;
    padding-bottom: 0.3rem;
}

.estimator-table .parameters-table {
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: 0;
}

.estimator-table .parameters-table tr:nth-child(odd) {
    background-color: #fff;
}

.estimator-table .parameters-table tr:nth-child(even) {
    background-color: #f6f6f6;
}

.estimator-table .parameters-table tr:hover {
    background-color: #e0e0e0;
}

.estimator-table table td {
    border: 1px solid rgba(106, 105, 104, 0.232);
}

/*
    `table td`is set in notebook with right text-align.
    We need to overwrite it.
*/
.estimator-table table td.param {
    text-align: left;
    position: relative;
    padding: 0;
}

.user-set td {
    color:rgb(255, 94, 0);
    text-align: left !important;
}

.user-set td.value {
    color:rgb(255, 94, 0);
    background-color: transparent;
}

.default td {
    color: black;
    text-align: left !important;
}

.user-set td i,
.default td i {
    color: black;
}

/*
    Styles for parameter documentation links
    We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
    text-decoration: underline dashed;
    text-underline-offset: .3em;
    color: inherit;
    display: block;
    padding: .5em;
}

/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
    position: absolute;
    content: "";
    inset: 0;
}

.param-doc-description {
    display: none;
    position: absolute;
    z-index: 9999;
    left: 0;
    padding: .5ex;
    margin-left: 1.5em;
    color: var(--sklearn-color-text);
    box-shadow: .3em .3em .4em #999;
    width: max-content;
    text-align: left;
    max-height: 10em;
    overflow-y: auto;

    /* unfitted */
    background: var(--sklearn-color-unfitted-level-0);
    border: thin solid var(--sklearn-color-unfitted-level-3);
}

/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
    /* fitted */
    background: var(--sklearn-color-fitted-level-0);
    border: thin solid var(--sklearn-color-fitted-level-3);
}

.param-doc-link:hover .param-doc-description {
    display: block;
}

.copy-paste-icon {
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
    background-repeat: no-repeat;
    background-size: 14px 14px;
    background-position: 0;
    display: inline-block;
    width: 14px;
    height: 14px;
    cursor: pointer;
}
</style><div id="sk-container-id-5" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>LinearRegression()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br>On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden=""><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-5" type="checkbox" checked=""><label for="sk-estimator-id-5" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LinearRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html">?<span>Documentation for LinearRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
        <div class="estimator-table">
            <details>
                <summary>Parameters</summary>
                
<table class="parameters-table caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<tbody>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue" class="param-doc-link" rel="noreferrer" target="_blank">fit_intercept <span class="param-doc-description">fit_intercept: bool, default=True<br>
<br>
Whether to calculate the intercept for this model. If set<br>
to False, no intercept will be used in calculations<br>
(i.e. data is expected to be centered).</span></a></td>
<td class="value">True</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=copy_X,-bool%2C%20default%3DTrue" class="param-doc-link" rel="noreferrer" target="_blank">copy_X <span class="param-doc-description">copy_X: bool, default=True<br>
<br>
If True, X will be copied; else, it may be overwritten.</span></a></td>
<td class="value">True</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=tol,-float%2C%20default%3D1e-6" class="param-doc-link" rel="noreferrer" target="_blank">tol <span class="param-doc-description">tol: float, default=1e-6<br>
<br>
The precision of the solution (`coef_`) is determined by `tol` which<br>
specifies a different convergence criterion for the `lsqr` solver.<br>
`tol` is set as `atol` and `btol` of :func:`scipy.sparse.linalg.lsqr` when<br>
fitting on sparse training data. This parameter has no effect when fitting<br>
on dense data.<br>
<br>
.. versionadded:: 1.7</span></a></td>
<td class="value">1e-06</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">n_jobs <span class="param-doc-description">n_jobs: int, default=None<br>
<br>
The number of jobs to use for the computation. This will only provide<br>
speedup in case of sufficiently large problems, that is if firstly<br>
`n_targets &gt; 1` and secondly `X` is sparse or if `positive` is set<br>
to `True`. ``None`` means 1 unless in a<br>
:obj:`joblib.parallel_backend` context. ``-1`` means using all<br>
processors. See :term:`Glossary <n_jobs>` for more details.</n_jobs></span></a></td>
<td class="value">None</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=positive,-bool%2C%20default%3DFalse" class="param-doc-link" rel="noreferrer" target="_blank">positive <span class="param-doc-description">positive: bool, default=False<br>
<br>
When set to ``True``, forces the coefficients to be positive. This<br>
option is only supported for dense arrays.<br>
<br>
For a comparison between a linear regression model with positive constraints<br>
on the regression coefficients and a linear regression without such constraints,<br>
see :ref:`sphx_glr_auto_examples_linear_model_plot_nnls.py`.<br>
<br>
.. versionadded:: 0.24</span></a></td>
<td class="value">False</td>
</tr>
</tbody>
</table>

            </details>
        </div>
    </div></div></div></div></div><script>function copyToClipboard(text, element) {
    // Get the parameter prefix from the closest toggleable content
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;

    const originalStyle = element.style;
    const computedStyle = window.getComputedStyle(element);
    const originalWidth = computedStyle.width;
    const originalHTML = element.innerHTML.replace('Copied!', '');

    navigator.clipboard.writeText(fullParamName)
        .then(() => {
            element.style.width = originalWidth;
            element.style.color = 'green';
            element.innerHTML = "Copied!";

            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        })
        .catch(err => {
            console.error('Failed to copy:', err);
            element.style.color = 'red';
            element.innerHTML = "Failed!";
            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        });
    return false;
}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) {
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const paramName = element.parentElement.nextElementSibling
        .textContent.trim().split(' ')[0];
    const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

    element.setAttribute('title', fullParamName);
});


/**
 * Adapted from Skrub
 * https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/skrub/_reporting/_data/templates/report.js#L789
 * @returns "light" or "dark"
 */
function detectTheme(element) {
    const body = document.querySelector('body');

    // Check VSCode theme
    const themeKindAttr = body.getAttribute('data-vscode-theme-kind');
    const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) {
        const themeKind = themeKindAttr.toLowerCase();
        const themeName = themeNameAttr.toLowerCase();

        if (themeKind.includes("dark") || themeName.includes("dark")) {
            return "dark";
        }
        if (themeKind.includes("light") || themeName.includes("light")) {
            return "light";
        }
    }

    // Check Jupyter theme
    if (body.getAttribute('data-jp-theme-light') === 'false') {
        return 'dark';
    } else if (body.getAttribute('data-jp-theme-light') === 'true') {
        return 'light';
    }

    // Guess based on a parent element's color
    const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color');
    const match = color.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i);
    if (match) {
        const [r, g, b] = [
            parseFloat(match[1]),
            parseFloat(match[2]),
            parseFloat(match[3])
        ];

        // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
        const luma = 0.299 * r + 0.587 * g + 0.114 * b;

        if (luma > 180) {
            // If the text is very bright we have a dark theme
            return 'dark';
        }
        if (luma < 75) {
            // If the text is very dark we have a light theme
            return 'light';
        }
        // Otherwise fall back to the next heuristic.
    }

    // Fallback to system preference
    return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}


function forceTheme(elementId) {
    const estimatorElement = document.querySelector(`#${elementId}`);
    if (estimatorElement === null) {
        console.error(`Element with id ${elementId} not found.`);
    } else {
        const theme = detectTheme(estimatorElement);
        estimatorElement.classList.add(theme);
    }
}

forceTheme('sk-container-id-5');</script>
</div>
</div>
<p>Um das Modell zu prüfen lassen wir es nun aus unseren Testdaten (<code>X_test</code>) die Zieldaten (<code>y_pred</code>) modellieren:</p>
<div id="16b9dada" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vorhersage</span></span>
<span id="cb7-2">y_pred <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linreg.predict(X_test)</span></code></pre></div></div>
</div>
<p>Da wir mit <code>y_test</code> die tatsächlichen Daten kennen, können wir das nun mit unserem vom Modell modellierten Werten vergleichen und so unsere Modell bewerten.</p>
<p>Wir nutzen dazu das die mittlere quadratische Abweichung (engl. <em>mean squared error</em>, kurz <em>MSE</em>) und das Bestimmtheitsmaß <img src="https://latex.codecogs.com/png.latex?R%5E2">.</p>
<div id="5ebd0c7b" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSE:"</span>, mean_squared_error(y_test, y_pred))</span>
<span id="cb8-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R^2:"</span>, linreg.score(X_reg, y_reg))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>MSE: 0.7036607653595639
R^2: 0.7593651994880084</code></pre>
</div>
</div>
<p>Wir können die Regressiongerade mit Hilfe der Koeffizienten und der Ordinate (engl.: <em>Intercept</em>) bestimmen:</p>
<div id="dbba45e2" class="cell" data-execution_count="8">
<div class="cell-output cell-output-stdout">
<pre><code>Koeffizienten: [1.87753167]
Intercept: -7.252744633173977</code></pre>
</div>
</div>
<p>Daraus ergibt sich für die Regressiongerade die Darstellung:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Chat%7By%7D%20=%20%5Chat%7Bf%7D(x)%20%5Capprox%201.8775%20%5Ccdot%20x%20-%20%207.2527%0A"></p>
<p>Schauen wir uns das Streudiagramm unserer Test-und Trainingsdaten mit der Regressiongeraden an:</p>
<div id="71027581" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb11-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb11-3"></span>
<span id="cb11-4">plt.figure(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb11-5"></span>
<span id="cb11-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Streudiagramm der Trainingsdaten</span></span>
<span id="cb11-7">plt.scatter(X_train, y_train, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Trainingswerte"</span>)</span>
<span id="cb11-8">plt.scatter(X_test, y_test, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Testwerte"</span>)</span>
<span id="cb11-9"></span>
<span id="cb11-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Regressionsgerade</span></span>
<span id="cb11-11">xp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb11-12">yp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> xp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b</span>
<span id="cb11-13">pm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span></span>
<span id="cb11-14">plt.plot(xp, yp, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r'</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">hat{y}</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f'= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">x </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>pm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>absb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb11-15"></span>
<span id="cb11-16"></span>
<span id="cb11-17">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Länge des Kelchblatts (cm)"</span>)</span>
<span id="cb11-18">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Länge des Kronblatts (cm)"</span>)</span>
<span id="cb11-19">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lineare Regression auf den Liliendaten"</span>)</span>
<span id="cb11-20">plt.legend()</span>
<span id="cb11-21">plt.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb11-22">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-30-lineare-und-logistische-regression-mit-python/index_files/figure-html/cell-11-output-1.webp" width="651" height="449" class="figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="multiple-lineare-regression" class="level2">
<h2 class="anchored" data-anchor-id="multiple-lineare-regression">(Multiple) Lineare Regression</h2>
<p>Wir wollen nun bei der Modellierung auf alle drei anderen numerischen Variabeln zurpückgreifen. Das führt zu einer multiplen linearen Regression.</p>
<div id="f7a78d4c" class="cell" data-execution_count="11">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.linear_model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> LinearRegression</span>
<span id="cb12-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.model_selection <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> train_test_split</span>
<span id="cb12-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.metrics <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> mean_squared_error</span>
<span id="cb12-4"></span>
<span id="cb12-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zielvariable: Petal Length</span></span>
<span id="cb12-6">y_reg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"petal length (cm)"</span>]</span>
<span id="cb12-7"></span>
<span id="cb12-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Modellierungsvariablen: Sepal Width, Petal Length und Petal Width</span></span>
<span id="cb12-9">X_reg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X.drop(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"petal length (cm)"</span>])</span>
<span id="cb12-10"></span>
<span id="cb12-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Aufteilen in Test- und Trainingsdaten</span></span>
<span id="cb12-12">X_train, X_test, y_train, y_test <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> train_test_split(X_reg, y_reg, test_size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.20</span>, random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb12-13"></span>
<span id="cb12-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Modell</span></span>
<span id="cb12-15">linreg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> LinearRegression()</span>
<span id="cb12-16">linreg.fit(X_train, y_train)</span>
<span id="cb12-17"></span>
<span id="cb12-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vorhersage</span></span>
<span id="cb12-19">y_pred <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> linreg.predict(X_test)</span>
<span id="cb12-20"></span>
<span id="cb12-21"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MSE:"</span>, mean_squared_error(y_test, y_pred))</span>
<span id="cb12-22"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R^2:"</span>, linreg.score(X_reg, y_reg))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>MSE: 0.11749487412693703
R^2: 0.9675532979408549</code></pre>
</div>
</div>
<div id="33116d8d" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Koeffizienten:"</span>, linreg.coef_)</span>
<span id="cb14-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept:"</span>, linreg.intercept_)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Koeffizienten: [ 0.70649516 -0.66257783  1.49483392]
Intercept: -0.11204676270834524</code></pre>
</div>
</div>
<p>Wir erhalten somit die folgende Regressionsfunktion:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Chat%7By%7D%20=%20%5Chat%7Bf%7D(x_1,%20x_2,%20x_3)%0A%20%20%20%20%20%20%20%20%20%20=%200.7065%20%5Ccdot%20x_1%20-%0A%20%20%20%20%20%20%20%20%20%20%20%200.6626%20%5Ccdot%20x_2%20+%0A%20%20%20%20%20%20%20%20%20%20%20%201.4948%20%5Ccdot%20x_3%20-%200.112%20%20%0A"></p>
</section>
<section id="einfache-logistische-regression" class="level2">
<h2 class="anchored" data-anchor-id="einfache-logistische-regression">Einfache Logistische Regression</h2>
<p>Unsere Liliendaten bestehen aus den Längen und Breiten der Kelch- bzw. Korbblüten von drei Lilienarten. In der Variable <code>y</code> sind diese Arten wie folgt kodiert:</p>
<p>0 = setosa</p>
<p>1 = versicolor</p>
<p>2 = virginica</p>
<p>Wir schauen uns zunächst nur die Iris setosa an, dafür setzen wir ‘y’ immer dann auf 1, wenn eine solche Lilienart vorliegt, sonst auf 0:</p>
<div id="d16046b3" class="cell" data-execution_count="14">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">y_setosa <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.where( y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb16-2">y_setosa</span>
<span id="cb16-3">X_setosa <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X.drop(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"petal length (cm)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sepal width (cm)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"petal width (cm)"</span>])</span>
<span id="cb16-4">X_setosa</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="49">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">sepal length (cm)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>5.1</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>4.9</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>4.7</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>4.6</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>5.0</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">145</th>
<td>6.7</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">146</th>
<td>6.3</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">147</th>
<td>6.5</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">148</th>
<td>6.2</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">149</th>
<td>5.9</td>
</tr>
</tbody>
</table>

<p>150 rows × 1 columns</p>
</div>
</div>
</div>
<p>Betrachten wir nun unsere Situation als Streudiagramm:</p>
<div id="b2dc3630" class="cell" data-execution_count="15">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">plt.figure(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb17-2"></span>
<span id="cb17-3">plt.subplot(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb17-4">setosa <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X_setosa[y_setosa <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb17-5">notsetosa <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X_setosa[y_setosa <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span>
<span id="cb17-6">plt.ylim(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb17-7">setosa.boxplot()</span>
<span id="cb17-8">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Iris setosa"</span>)</span>
<span id="cb17-9">plt.subplot(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb17-10">notsetosa.boxplot()</span>
<span id="cb17-11">plt.ylim(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb17-12">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nicht Iris setosa"</span>)</span>
<span id="cb17-13"></span>
<span id="cb17-14"></span>
<span id="cb17-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#grp =[X_setosa[y_setosa == g] for g in (0, 1)]</span></span>
<span id="cb17-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#plt.boxplot(grp, tick_labels=["I. setosa", "Nicht I. setosa"])</span></span>
<span id="cb17-17">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-30-lineare-und-logistische-regression-mit-python/index_files/figure-html/cell-16-output-1.webp" width="632" height="431" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Wenn wir eine lineare Regression nur der ??? durchführen würden, so sähe das wie folgt aus:</p>
<div id="28a19069" class="cell" data-execution_count="16">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb18-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.linear_model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> LinearRegression</span>
<span id="cb18-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.model_selection <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> train_test_split</span>
<span id="cb18-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.metrics <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> mean_squared_error</span>
<span id="cb18-4"></span>
<span id="cb18-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Aufteilen in Test- und Trainingsdaten</span></span>
<span id="cb18-6">X_train, X_test, y_train, y_test <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> train_test_split(X_setosa, y_setosa, test_size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb18-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#X_train</span></span>
<span id="cb18-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#y_train</span></span></code></pre></div></div>
</div>
<div id="801c3a7d" class="cell" data-execution_count="17">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1">linmod_linreg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> LinearRegression()</span>
<span id="cb19-2">linmod_linreg.fit(X_train, y_train)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="52">
<style>#sk-container-id-6 {
  /* Definition of color scheme common for light and dark mode */
  --sklearn-color-text: #000;
  --sklearn-color-text-muted: #666;
  --sklearn-color-line: gray;
  /* Definition of color scheme for unfitted estimators */
  --sklearn-color-unfitted-level-0: #fff5e6;
  --sklearn-color-unfitted-level-1: #f6e4d2;
  --sklearn-color-unfitted-level-2: #ffe0b3;
  --sklearn-color-unfitted-level-3: chocolate;
  /* Definition of color scheme for fitted estimators */
  --sklearn-color-fitted-level-0: #f0f8ff;
  --sklearn-color-fitted-level-1: #d4ebff;
  --sklearn-color-fitted-level-2: #b3dbfd;
  --sklearn-color-fitted-level-3: cornflowerblue;
}

#sk-container-id-6.light {
  /* Specific color for light theme */
  --sklearn-color-text-on-default-background: black;
  --sklearn-color-background: white;
  --sklearn-color-border-box: black;
  --sklearn-color-icon: #696969;
}

#sk-container-id-6.dark {
  --sklearn-color-text-on-default-background: white;
  --sklearn-color-background: #111;
  --sklearn-color-border-box: white;
  --sklearn-color-icon: #878787;
}

#sk-container-id-6 {
  color: var(--sklearn-color-text);
}

#sk-container-id-6 pre {
  padding: 0;
}

#sk-container-id-6 input.sk-hidden--visually {
  border: 0;
  clip: rect(1px 1px 1px 1px);
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

#sk-container-id-6 div.sk-dashed-wrapped {
  border: 1px dashed var(--sklearn-color-line);
  margin: 0 0.4em 0.5em 0.4em;
  box-sizing: border-box;
  padding-bottom: 0.4em;
  background-color: var(--sklearn-color-background);
}

#sk-container-id-6 div.sk-container {
  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`
     but bootstrap.min.css set `[hidden] { display: none !important; }`
     so we also need the `!important` here to be able to override the
     default hidden behavior on the sphinx rendered scikit-learn.org.
     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
  display: inline-block !important;
  position: relative;
}

#sk-container-id-6 div.sk-text-repr-fallback {
  display: none;
}

div.sk-parallel-item,
div.sk-serial,
div.sk-item {
  /* draw centered vertical line to link estimators */
  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
  background-size: 2px 100%;
  background-repeat: no-repeat;
  background-position: center center;
}

/* Parallel-specific style estimator block */

#sk-container-id-6 div.sk-parallel-item::after {
  content: "";
  width: 100%;
  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
  flex-grow: 1;
}

#sk-container-id-6 div.sk-parallel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background-color: var(--sklearn-color-background);
  position: relative;
}

#sk-container-id-6 div.sk-parallel-item {
  display: flex;
  flex-direction: column;
}

#sk-container-id-6 div.sk-parallel-item:first-child::after {
  align-self: flex-end;
  width: 50%;
}

#sk-container-id-6 div.sk-parallel-item:last-child::after {
  align-self: flex-start;
  width: 50%;
}

#sk-container-id-6 div.sk-parallel-item:only-child::after {
  width: 0;
}

/* Serial-specific style estimator block */

#sk-container-id-6 div.sk-serial {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--sklearn-color-background);
  padding-right: 1em;
  padding-left: 1em;
}


/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/

/* Pipeline and ColumnTransformer style (default) */

#sk-container-id-6 div.sk-toggleable {
  /* Default theme specific background. It is overwritten whether we have a
  specific estimator or a Pipeline/ColumnTransformer */
  background-color: var(--sklearn-color-background);
}

/* Toggleable label */
#sk-container-id-6 label.sk-toggleable__label {
  cursor: pointer;
  display: flex;
  width: 100%;
  margin-bottom: 0;
  padding: 0.5em;
  box-sizing: border-box;
  text-align: center;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}

#sk-container-id-6 label.sk-toggleable__label .caption {
  font-size: 0.6rem;
  font-weight: lighter;
  color: var(--sklearn-color-text-muted);
}

#sk-container-id-6 label.sk-toggleable__label-arrow:before {
  /* Arrow on the left of the label */
  content: "▸";
  float: left;
  margin-right: 0.25em;
  color: var(--sklearn-color-icon);
}

#sk-container-id-6 label.sk-toggleable__label-arrow:hover:before {
  color: var(--sklearn-color-text);
}

/* Toggleable content - dropdown */

#sk-container-id-6 div.sk-toggleable__content {
  display: none;
  text-align: left;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-6 div.sk-toggleable__content.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-6 div.sk-toggleable__content pre {
  margin: 0.2em;
  border-radius: 0.25em;
  color: var(--sklearn-color-text);
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-6 div.sk-toggleable__content.fitted pre {
  /* unfitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-6 input.sk-toggleable__control:checked~div.sk-toggleable__content {
  /* Expand drop-down */
  display: block;
  width: 100%;
  overflow: visible;
}

#sk-container-id-6 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
  content: "▾";
}

/* Pipeline/ColumnTransformer-specific style */

#sk-container-id-6 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-6 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator-specific style */

/* Colorize estimator box */
#sk-container-id-6 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-6 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

#sk-container-id-6 div.sk-label label.sk-toggleable__label,
#sk-container-id-6 div.sk-label label {
  /* The background is the default theme color */
  color: var(--sklearn-color-text-on-default-background);
}

/* On hover, darken the color of the background */
#sk-container-id-6 div.sk-label:hover label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

/* Label box, darken color on hover, fitted */
#sk-container-id-6 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator label */

#sk-container-id-6 div.sk-label label {
  font-family: monospace;
  font-weight: bold;
  line-height: 1.2em;
}

#sk-container-id-6 div.sk-label-container {
  text-align: center;
}

/* Estimator-specific */
#sk-container-id-6 div.sk-estimator {
  font-family: monospace;
  border: 1px dotted var(--sklearn-color-border-box);
  border-radius: 0.25em;
  box-sizing: border-box;
  margin-bottom: 0.5em;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-6 div.sk-estimator.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

/* on hover */
#sk-container-id-6 div.sk-estimator:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-6 div.sk-estimator.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Specification for estimator info (e.g. "i" and "?") */

/* Common style for "i" and "?" */

.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
  float: right;
  font-size: smaller;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1em;
  height: 1em;
  width: 1em;
  text-decoration: none !important;
  margin-left: 0.5em;
  text-align: center;
  /* unfitted */
  border: var(--sklearn-color-unfitted-level-3) 1pt solid;
  color: var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3) 1pt solid;
  color: var(--sklearn-color-fitted-level-3);
}

/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-unfitted-level-0);
  text-decoration: none;
}

div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-fitted-level-0);
  text-decoration: none;
}

/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
  display: none;
  z-index: 9999;
  position: relative;
  font-weight: normal;
  right: .2ex;
  padding: .5ex;
  margin: .5ex;
  width: min-content;
  min-width: 20ex;
  max-width: 50ex;
  color: var(--sklearn-color-text);
  box-shadow: 2pt 2pt 4pt #999;
  /* unfitted */
  background: var(--sklearn-color-unfitted-level-0);
  border: .5pt solid var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted span {
  /* fitted */
  background: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3);
}

.sk-estimator-doc-link:hover span {
  display: block;
}

/* "?"-specific style due to the `<a>` HTML tag */

#sk-container-id-6 a.estimator_doc_link {
  float: right;
  font-size: 1rem;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1rem;
  height: 1rem;
  width: 1rem;
  text-decoration: none;
  /* unfitted */
  color: var(--sklearn-color-unfitted-level-1);
  border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}

#sk-container-id-6 a.estimator_doc_link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-1) 1pt solid;
  color: var(--sklearn-color-fitted-level-1);
}

/* On hover */
#sk-container-id-6 a.estimator_doc_link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  color: var(--sklearn-color-background);
  text-decoration: none;
}

#sk-container-id-6 a.estimator_doc_link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
}

.estimator-table {
    font-family: monospace;
}

.estimator-table summary {
    padding: .5rem;
    cursor: pointer;
}

.estimator-table summary::marker {
    font-size: 0.7rem;
}

.estimator-table details[open] {
    padding-left: 0.1rem;
    padding-right: 0.1rem;
    padding-bottom: 0.3rem;
}

.estimator-table .parameters-table {
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: 0;
}

.estimator-table .parameters-table tr:nth-child(odd) {
    background-color: #fff;
}

.estimator-table .parameters-table tr:nth-child(even) {
    background-color: #f6f6f6;
}

.estimator-table .parameters-table tr:hover {
    background-color: #e0e0e0;
}

.estimator-table table td {
    border: 1px solid rgba(106, 105, 104, 0.232);
}

/*
    `table td`is set in notebook with right text-align.
    We need to overwrite it.
*/
.estimator-table table td.param {
    text-align: left;
    position: relative;
    padding: 0;
}

.user-set td {
    color:rgb(255, 94, 0);
    text-align: left !important;
}

.user-set td.value {
    color:rgb(255, 94, 0);
    background-color: transparent;
}

.default td {
    color: black;
    text-align: left !important;
}

.user-set td i,
.default td i {
    color: black;
}

/*
    Styles for parameter documentation links
    We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
    text-decoration: underline dashed;
    text-underline-offset: .3em;
    color: inherit;
    display: block;
    padding: .5em;
}

/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
    position: absolute;
    content: "";
    inset: 0;
}

.param-doc-description {
    display: none;
    position: absolute;
    z-index: 9999;
    left: 0;
    padding: .5ex;
    margin-left: 1.5em;
    color: var(--sklearn-color-text);
    box-shadow: .3em .3em .4em #999;
    width: max-content;
    text-align: left;
    max-height: 10em;
    overflow-y: auto;

    /* unfitted */
    background: var(--sklearn-color-unfitted-level-0);
    border: thin solid var(--sklearn-color-unfitted-level-3);
}

/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
    /* fitted */
    background: var(--sklearn-color-fitted-level-0);
    border: thin solid var(--sklearn-color-fitted-level-3);
}

.param-doc-link:hover .param-doc-description {
    display: block;
}

.copy-paste-icon {
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
    background-repeat: no-repeat;
    background-size: 14px 14px;
    background-position: 0;
    display: inline-block;
    width: 14px;
    height: 14px;
    cursor: pointer;
}
</style><div id="sk-container-id-6" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>LinearRegression()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br>On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden=""><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-6" type="checkbox" checked=""><label for="sk-estimator-id-6" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LinearRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html">?<span>Documentation for LinearRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
        <div class="estimator-table">
            <details>
                <summary>Parameters</summary>
                
<table class="parameters-table caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<tbody>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue" class="param-doc-link" rel="noreferrer" target="_blank">fit_intercept <span class="param-doc-description">fit_intercept: bool, default=True<br>
<br>
Whether to calculate the intercept for this model. If set<br>
to False, no intercept will be used in calculations<br>
(i.e. data is expected to be centered).</span></a></td>
<td class="value">True</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=copy_X,-bool%2C%20default%3DTrue" class="param-doc-link" rel="noreferrer" target="_blank">copy_X <span class="param-doc-description">copy_X: bool, default=True<br>
<br>
If True, X will be copied; else, it may be overwritten.</span></a></td>
<td class="value">True</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=tol,-float%2C%20default%3D1e-6" class="param-doc-link" rel="noreferrer" target="_blank">tol <span class="param-doc-description">tol: float, default=1e-6<br>
<br>
The precision of the solution (`coef_`) is determined by `tol` which<br>
specifies a different convergence criterion for the `lsqr` solver.<br>
`tol` is set as `atol` and `btol` of :func:`scipy.sparse.linalg.lsqr` when<br>
fitting on sparse training data. This parameter has no effect when fitting<br>
on dense data.<br>
<br>
.. versionadded:: 1.7</span></a></td>
<td class="value">1e-06</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">n_jobs <span class="param-doc-description">n_jobs: int, default=None<br>
<br>
The number of jobs to use for the computation. This will only provide<br>
speedup in case of sufficiently large problems, that is if firstly<br>
`n_targets &gt; 1` and secondly `X` is sparse or if `positive` is set<br>
to `True`. ``None`` means 1 unless in a<br>
:obj:`joblib.parallel_backend` context. ``-1`` means using all<br>
processors. See :term:`Glossary <n_jobs>` for more details.</n_jobs></span></a></td>
<td class="value">None</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LinearRegression.html#:~:text=positive,-bool%2C%20default%3DFalse" class="param-doc-link" rel="noreferrer" target="_blank">positive <span class="param-doc-description">positive: bool, default=False<br>
<br>
When set to ``True``, forces the coefficients to be positive. This<br>
option is only supported for dense arrays.<br>
<br>
For a comparison between a linear regression model with positive constraints<br>
on the regression coefficients and a linear regression without such constraints,<br>
see :ref:`sphx_glr_auto_examples_linear_model_plot_nnls.py`.<br>
<br>
.. versionadded:: 0.24</span></a></td>
<td class="value">False</td>
</tr>
</tbody>
</table>

            </details>
        </div>
    </div></div></div></div></div><script>function copyToClipboard(text, element) {
    // Get the parameter prefix from the closest toggleable content
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;

    const originalStyle = element.style;
    const computedStyle = window.getComputedStyle(element);
    const originalWidth = computedStyle.width;
    const originalHTML = element.innerHTML.replace('Copied!', '');

    navigator.clipboard.writeText(fullParamName)
        .then(() => {
            element.style.width = originalWidth;
            element.style.color = 'green';
            element.innerHTML = "Copied!";

            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        })
        .catch(err => {
            console.error('Failed to copy:', err);
            element.style.color = 'red';
            element.innerHTML = "Failed!";
            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        });
    return false;
}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) {
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const paramName = element.parentElement.nextElementSibling
        .textContent.trim().split(' ')[0];
    const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

    element.setAttribute('title', fullParamName);
});


/**
 * Adapted from Skrub
 * https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/skrub/_reporting/_data/templates/report.js#L789
 * @returns "light" or "dark"
 */
function detectTheme(element) {
    const body = document.querySelector('body');

    // Check VSCode theme
    const themeKindAttr = body.getAttribute('data-vscode-theme-kind');
    const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) {
        const themeKind = themeKindAttr.toLowerCase();
        const themeName = themeNameAttr.toLowerCase();

        if (themeKind.includes("dark") || themeName.includes("dark")) {
            return "dark";
        }
        if (themeKind.includes("light") || themeName.includes("light")) {
            return "light";
        }
    }

    // Check Jupyter theme
    if (body.getAttribute('data-jp-theme-light') === 'false') {
        return 'dark';
    } else if (body.getAttribute('data-jp-theme-light') === 'true') {
        return 'light';
    }

    // Guess based on a parent element's color
    const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color');
    const match = color.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i);
    if (match) {
        const [r, g, b] = [
            parseFloat(match[1]),
            parseFloat(match[2]),
            parseFloat(match[3])
        ];

        // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
        const luma = 0.299 * r + 0.587 * g + 0.114 * b;

        if (luma > 180) {
            // If the text is very bright we have a dark theme
            return 'dark';
        }
        if (luma < 75) {
            // If the text is very dark we have a light theme
            return 'light';
        }
        // Otherwise fall back to the next heuristic.
    }

    // Fallback to system preference
    return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}


function forceTheme(elementId) {
    const estimatorElement = document.querySelector(`#${elementId}`);
    if (estimatorElement === null) {
        console.error(`Element with id ${elementId} not found.`);
    } else {
        const theme = detectTheme(estimatorElement);
        estimatorElement.classList.add(theme);
    }
}

forceTheme('sk-container-id-6');</script>
</div>
</div>
<div id="4ebb99d0" class="cell" data-execution_count="18">
<div class="cell-output cell-output-stdout">
<pre><code>Koeffizienten: [-0.40773779]
Intercept: 2.7296683561998614</code></pre>
</div>
</div>
<p>Das Streudiagramm</p>
<div id="b373a16c" class="cell" data-execution_count="20">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb21-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb21-3"></span>
<span id="cb21-4">plt.figure(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb21-5"></span>
<span id="cb21-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Streudiagramm der Trainingsdaten</span></span>
<span id="cb21-7">plt.scatter(X_train, y_train, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Trainingswerte"</span>)</span>
<span id="cb21-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plt.scatter(X_test, y_test, color="green", label="Testwerte")</span></span>
<span id="cb21-9"></span>
<span id="cb21-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Regressionsgerade</span></span>
<span id="cb21-11">xp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb21-12">yp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> xp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b</span>
<span id="cb21-13">pm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span></span>
<span id="cb21-14">plt.plot(xp, yp, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r'</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">hat{y}</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f'= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">x </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>pm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>absb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb21-15"></span>
<span id="cb21-16"></span>
<span id="cb21-17">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Länge des Kelchblatts (cm)"</span>)</span>
<span id="cb21-18">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Länge des Kronblatts (cm)"</span>)</span>
<span id="cb21-19">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lineare Regression auf den Liliendaten"</span>)</span>
<span id="cb21-20">plt.legend()</span>
<span id="cb21-21">plt.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb21-22">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-30-lineare-und-logistische-regression-mit-python/index_files/figure-html/cell-21-output-1.webp" width="674" height="449" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Statt des linearen Ansatzes, wollen wir eine Wahrscheinlichkeit modellieren ob eine entsprechende Länge des Kelchsblattes für oder gegen eine Iris setosa spricht.</p>
<div id="0e311a33" class="cell" data-execution_count="21">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.linear_model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> LogisticRegression</span>
<span id="cb22-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.model_selection <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> train_test_split</span>
<span id="cb22-3"></span>
<span id="cb22-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Modell</span></span>
<span id="cb22-5">logreg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> LogisticRegression(max_iter<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb22-6">logreg.fit(X_train, y_train)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="56">
<style>#sk-container-id-7 {
  /* Definition of color scheme common for light and dark mode */
  --sklearn-color-text: #000;
  --sklearn-color-text-muted: #666;
  --sklearn-color-line: gray;
  /* Definition of color scheme for unfitted estimators */
  --sklearn-color-unfitted-level-0: #fff5e6;
  --sklearn-color-unfitted-level-1: #f6e4d2;
  --sklearn-color-unfitted-level-2: #ffe0b3;
  --sklearn-color-unfitted-level-3: chocolate;
  /* Definition of color scheme for fitted estimators */
  --sklearn-color-fitted-level-0: #f0f8ff;
  --sklearn-color-fitted-level-1: #d4ebff;
  --sklearn-color-fitted-level-2: #b3dbfd;
  --sklearn-color-fitted-level-3: cornflowerblue;
}

#sk-container-id-7.light {
  /* Specific color for light theme */
  --sklearn-color-text-on-default-background: black;
  --sklearn-color-background: white;
  --sklearn-color-border-box: black;
  --sklearn-color-icon: #696969;
}

#sk-container-id-7.dark {
  --sklearn-color-text-on-default-background: white;
  --sklearn-color-background: #111;
  --sklearn-color-border-box: white;
  --sklearn-color-icon: #878787;
}

#sk-container-id-7 {
  color: var(--sklearn-color-text);
}

#sk-container-id-7 pre {
  padding: 0;
}

#sk-container-id-7 input.sk-hidden--visually {
  border: 0;
  clip: rect(1px 1px 1px 1px);
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

#sk-container-id-7 div.sk-dashed-wrapped {
  border: 1px dashed var(--sklearn-color-line);
  margin: 0 0.4em 0.5em 0.4em;
  box-sizing: border-box;
  padding-bottom: 0.4em;
  background-color: var(--sklearn-color-background);
}

#sk-container-id-7 div.sk-container {
  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`
     but bootstrap.min.css set `[hidden] { display: none !important; }`
     so we also need the `!important` here to be able to override the
     default hidden behavior on the sphinx rendered scikit-learn.org.
     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
  display: inline-block !important;
  position: relative;
}

#sk-container-id-7 div.sk-text-repr-fallback {
  display: none;
}

div.sk-parallel-item,
div.sk-serial,
div.sk-item {
  /* draw centered vertical line to link estimators */
  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
  background-size: 2px 100%;
  background-repeat: no-repeat;
  background-position: center center;
}

/* Parallel-specific style estimator block */

#sk-container-id-7 div.sk-parallel-item::after {
  content: "";
  width: 100%;
  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
  flex-grow: 1;
}

#sk-container-id-7 div.sk-parallel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background-color: var(--sklearn-color-background);
  position: relative;
}

#sk-container-id-7 div.sk-parallel-item {
  display: flex;
  flex-direction: column;
}

#sk-container-id-7 div.sk-parallel-item:first-child::after {
  align-self: flex-end;
  width: 50%;
}

#sk-container-id-7 div.sk-parallel-item:last-child::after {
  align-self: flex-start;
  width: 50%;
}

#sk-container-id-7 div.sk-parallel-item:only-child::after {
  width: 0;
}

/* Serial-specific style estimator block */

#sk-container-id-7 div.sk-serial {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--sklearn-color-background);
  padding-right: 1em;
  padding-left: 1em;
}


/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/

/* Pipeline and ColumnTransformer style (default) */

#sk-container-id-7 div.sk-toggleable {
  /* Default theme specific background. It is overwritten whether we have a
  specific estimator or a Pipeline/ColumnTransformer */
  background-color: var(--sklearn-color-background);
}

/* Toggleable label */
#sk-container-id-7 label.sk-toggleable__label {
  cursor: pointer;
  display: flex;
  width: 100%;
  margin-bottom: 0;
  padding: 0.5em;
  box-sizing: border-box;
  text-align: center;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}

#sk-container-id-7 label.sk-toggleable__label .caption {
  font-size: 0.6rem;
  font-weight: lighter;
  color: var(--sklearn-color-text-muted);
}

#sk-container-id-7 label.sk-toggleable__label-arrow:before {
  /* Arrow on the left of the label */
  content: "▸";
  float: left;
  margin-right: 0.25em;
  color: var(--sklearn-color-icon);
}

#sk-container-id-7 label.sk-toggleable__label-arrow:hover:before {
  color: var(--sklearn-color-text);
}

/* Toggleable content - dropdown */

#sk-container-id-7 div.sk-toggleable__content {
  display: none;
  text-align: left;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-7 div.sk-toggleable__content.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-7 div.sk-toggleable__content pre {
  margin: 0.2em;
  border-radius: 0.25em;
  color: var(--sklearn-color-text);
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-7 div.sk-toggleable__content.fitted pre {
  /* unfitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-7 input.sk-toggleable__control:checked~div.sk-toggleable__content {
  /* Expand drop-down */
  display: block;
  width: 100%;
  overflow: visible;
}

#sk-container-id-7 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
  content: "▾";
}

/* Pipeline/ColumnTransformer-specific style */

#sk-container-id-7 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-7 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator-specific style */

/* Colorize estimator box */
#sk-container-id-7 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-7 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

#sk-container-id-7 div.sk-label label.sk-toggleable__label,
#sk-container-id-7 div.sk-label label {
  /* The background is the default theme color */
  color: var(--sklearn-color-text-on-default-background);
}

/* On hover, darken the color of the background */
#sk-container-id-7 div.sk-label:hover label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

/* Label box, darken color on hover, fitted */
#sk-container-id-7 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator label */

#sk-container-id-7 div.sk-label label {
  font-family: monospace;
  font-weight: bold;
  line-height: 1.2em;
}

#sk-container-id-7 div.sk-label-container {
  text-align: center;
}

/* Estimator-specific */
#sk-container-id-7 div.sk-estimator {
  font-family: monospace;
  border: 1px dotted var(--sklearn-color-border-box);
  border-radius: 0.25em;
  box-sizing: border-box;
  margin-bottom: 0.5em;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-7 div.sk-estimator.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

/* on hover */
#sk-container-id-7 div.sk-estimator:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-7 div.sk-estimator.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Specification for estimator info (e.g. "i" and "?") */

/* Common style for "i" and "?" */

.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
  float: right;
  font-size: smaller;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1em;
  height: 1em;
  width: 1em;
  text-decoration: none !important;
  margin-left: 0.5em;
  text-align: center;
  /* unfitted */
  border: var(--sklearn-color-unfitted-level-3) 1pt solid;
  color: var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3) 1pt solid;
  color: var(--sklearn-color-fitted-level-3);
}

/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-unfitted-level-0);
  text-decoration: none;
}

div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-fitted-level-0);
  text-decoration: none;
}

/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
  display: none;
  z-index: 9999;
  position: relative;
  font-weight: normal;
  right: .2ex;
  padding: .5ex;
  margin: .5ex;
  width: min-content;
  min-width: 20ex;
  max-width: 50ex;
  color: var(--sklearn-color-text);
  box-shadow: 2pt 2pt 4pt #999;
  /* unfitted */
  background: var(--sklearn-color-unfitted-level-0);
  border: .5pt solid var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted span {
  /* fitted */
  background: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3);
}

.sk-estimator-doc-link:hover span {
  display: block;
}

/* "?"-specific style due to the `<a>` HTML tag */

#sk-container-id-7 a.estimator_doc_link {
  float: right;
  font-size: 1rem;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1rem;
  height: 1rem;
  width: 1rem;
  text-decoration: none;
  /* unfitted */
  color: var(--sklearn-color-unfitted-level-1);
  border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}

#sk-container-id-7 a.estimator_doc_link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-1) 1pt solid;
  color: var(--sklearn-color-fitted-level-1);
}

/* On hover */
#sk-container-id-7 a.estimator_doc_link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  color: var(--sklearn-color-background);
  text-decoration: none;
}

#sk-container-id-7 a.estimator_doc_link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
}

.estimator-table {
    font-family: monospace;
}

.estimator-table summary {
    padding: .5rem;
    cursor: pointer;
}

.estimator-table summary::marker {
    font-size: 0.7rem;
}

.estimator-table details[open] {
    padding-left: 0.1rem;
    padding-right: 0.1rem;
    padding-bottom: 0.3rem;
}

.estimator-table .parameters-table {
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: 0;
}

.estimator-table .parameters-table tr:nth-child(odd) {
    background-color: #fff;
}

.estimator-table .parameters-table tr:nth-child(even) {
    background-color: #f6f6f6;
}

.estimator-table .parameters-table tr:hover {
    background-color: #e0e0e0;
}

.estimator-table table td {
    border: 1px solid rgba(106, 105, 104, 0.232);
}

/*
    `table td`is set in notebook with right text-align.
    We need to overwrite it.
*/
.estimator-table table td.param {
    text-align: left;
    position: relative;
    padding: 0;
}

.user-set td {
    color:rgb(255, 94, 0);
    text-align: left !important;
}

.user-set td.value {
    color:rgb(255, 94, 0);
    background-color: transparent;
}

.default td {
    color: black;
    text-align: left !important;
}

.user-set td i,
.default td i {
    color: black;
}

/*
    Styles for parameter documentation links
    We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
    text-decoration: underline dashed;
    text-underline-offset: .3em;
    color: inherit;
    display: block;
    padding: .5em;
}

/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
    position: absolute;
    content: "";
    inset: 0;
}

.param-doc-description {
    display: none;
    position: absolute;
    z-index: 9999;
    left: 0;
    padding: .5ex;
    margin-left: 1.5em;
    color: var(--sklearn-color-text);
    box-shadow: .3em .3em .4em #999;
    width: max-content;
    text-align: left;
    max-height: 10em;
    overflow-y: auto;

    /* unfitted */
    background: var(--sklearn-color-unfitted-level-0);
    border: thin solid var(--sklearn-color-unfitted-level-3);
}

/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
    /* fitted */
    background: var(--sklearn-color-fitted-level-0);
    border: thin solid var(--sklearn-color-fitted-level-3);
}

.param-doc-link:hover .param-doc-description {
    display: block;
}

.copy-paste-icon {
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
    background-repeat: no-repeat;
    background-size: 14px 14px;
    background-position: 0;
    display: inline-block;
    width: 14px;
    height: 14px;
    cursor: pointer;
}
</style><div id="sk-container-id-7" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>LogisticRegression(max_iter=200)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br>On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden=""><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-7" type="checkbox" checked=""><label for="sk-estimator-id-7" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LogisticRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html">?<span>Documentation for LogisticRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
        <div class="estimator-table">
            <details>
                <summary>Parameters</summary>
                
<table class="parameters-table caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<tbody>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=penalty,-%7B%27l1%27%2C%20%27l2%27%2C%20%27elasticnet%27%2C%20None%7D%2C%20default%3D%27l2%27" class="param-doc-link" rel="noreferrer" target="_blank">penalty <span class="param-doc-description">penalty: {'l1', 'l2', 'elasticnet', None}, default='l2'<br>
<br>
Specify the norm of the penalty:<br>
<br>
- `None`: no penalty is added;<br>
- `'l2'`: add a L2 penalty term and it is the default choice;<br>
- `'l1'`: add a L1 penalty term;<br>
- `'elasticnet'`: both L1 and L2 penalty terms are added.<br>
<br>
.. warning::<br>
Some penalties may not work with some solvers. See the parameter<br>
`solver` below, to know the compatibility between the penalty and<br>
solver.<br>
<br>
.. versionadded:: 0.19<br>
l1 penalty with SAGA solver (allowing 'multinomial' + L1)<br>
<br>
.. deprecated:: 1.8<br>
`penalty` was deprecated in version 1.8 and will be removed in 1.10.<br>
Use `l1_ratio` instead. `l1_ratio=0` for `penalty='l2'`, `l1_ratio=1` for<br>
`penalty='l1'` and `l1_ratio` set to any float between 0 and 1 for<br>
`'penalty='elasticnet'`.</span></a></td>
<td class="value">'deprecated'</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0" class="param-doc-link" rel="noreferrer" target="_blank">C <span class="param-doc-description">C: float, default=1.0<br>
<br>
Inverse of regularization strength; must be a positive float.<br>
Like in support vector machines, smaller values specify stronger<br>
regularization. `C=np.inf` results in unpenalized logistic regression.<br>
For a visual example on the effect of tuning the `C` parameter<br>
with an L1 penalty, see:<br>
:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.</span></a></td>
<td class="value">1.0</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0" class="param-doc-link" rel="noreferrer" target="_blank">l1_ratio <span class="param-doc-description">l1_ratio: float, default=0.0<br>
<br>
The Elastic-Net mixing parameter, with `0 &lt;= l1_ratio &lt;= 1`. Setting<br>
`l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.<br>
Any value between 0 and 1 gives an Elastic-Net penalty of the form<br>
`l1_ratio * L1 + (1 - l1_ratio) * L2`.<br>
<br>
.. warning::<br>
Certain values of `l1_ratio`, i.e. some penalties, may not work with some<br>
solvers. See the parameter `solver` below, to know the compatibility between<br>
the penalty and solver.<br>
<br>
.. versionchanged:: 1.8<br>
Default value changed from None to 0.0.<br>
<br>
.. deprecated:: 1.8<br>
`None` is deprecated and will be removed in version 1.10. Always use<br>
`l1_ratio` to specify the penalty type.</span></a></td>
<td class="value">0.0</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse" class="param-doc-link" rel="noreferrer" target="_blank">dual <span class="param-doc-description">dual: bool, default=False<br>
<br>
Dual (constrained) or primal (regularized, see also<br>
:ref:`this equation <regularized-logistic-loss>`) formulation. Dual formulation<br>
is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br>
when n_samples &gt; n_features.</regularized-logistic-loss></span></a></td>
<td class="value">False</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4" class="param-doc-link" rel="noreferrer" target="_blank">tol <span class="param-doc-description">tol: float, default=1e-4<br>
<br>
Tolerance for stopping criteria.</span></a></td>
<td class="value">0.0001</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue" class="param-doc-link" rel="noreferrer" target="_blank">fit_intercept <span class="param-doc-description">fit_intercept: bool, default=True<br>
<br>
Specifies if a constant (a.k.a. bias or intercept) should be<br>
added to the decision function.</span></a></td>
<td class="value">True</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1" class="param-doc-link" rel="noreferrer" target="_blank">intercept_scaling <span class="param-doc-description">intercept_scaling: float, default=1<br>
<br>
Useful only when the solver `liblinear` is used<br>
and `self.fit_intercept` is set to `True`. In this case, `x` becomes<br>
`[x, self.intercept_scaling]`,<br>
i.e. a "synthetic" feature with constant value equal to<br>
`intercept_scaling` is appended to the instance vector.<br>
The intercept becomes<br>
``intercept_scaling * synthetic_feature_weight``.<br>
<br>
.. note::<br>
The synthetic feature weight is subject to L1 or L2<br>
regularization as all other features.<br>
To lessen the effect of regularization on synthetic feature weight<br>
(and therefore on the intercept) `intercept_scaling` has to be increased.</span></a></td>
<td class="value">1</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=class_weight,-dict%20or%20%27balanced%27%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">class_weight <span class="param-doc-description">class_weight: dict or 'balanced', default=None<br>
<br>
Weights associated with classes in the form ``{class_label: weight}``.<br>
If not given, all classes are supposed to have weight one.<br>
<br>
The "balanced" mode uses the values of y to automatically adjust<br>
weights inversely proportional to class frequencies in the input data<br>
as ``n_samples / (n_classes * np.bincount(y))``.<br>
<br>
Note that these weights will be multiplied with sample_weight (passed<br>
through the fit method) if sample_weight is specified.<br>
<br>
.. versionadded:: 0.17<br>
*class_weight='balanced'*</span></a></td>
<td class="value">None</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">random_state <span class="param-doc-description">random_state: int, RandomState instance, default=None<br>
<br>
Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the<br>
data. See :term:`Glossary <random_state>` for details.</random_state></span></a></td>
<td class="value">None</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27liblinear%27%2C%20%27newton-cg%27%2C%20%27newton-cholesky%27%2C%20%27sag%27%2C%20%27saga%27%7D%2C%20%20%20%20%20%20%20%20%20%20%20%20%20default%3D%27lbfgs%27" class="param-doc-link" rel="noreferrer" target="_blank">solver <span class="param-doc-description">solver: {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'}, default='lbfgs'<br>
<br>
Algorithm to use in the optimization problem. Default is 'lbfgs'.<br>
To choose a solver, you might want to consider the following aspects:<br>
<br>
- 'lbfgs' is a good default solver because it works reasonably well for a wide<br>
class of problems.<br>
- For :term:`multiclass` problems (`n_classes &gt;= 3`), all solvers except<br>
'liblinear' minimize the full multinomial loss, 'liblinear' will raise an<br>
error.<br>
- 'newton-cholesky' is a good choice for<br>
`n_samples` &gt;&gt; `n_features * n_classes`, especially with one-hot encoded<br>
categorical features with rare categories. Be aware that the memory usage<br>
of this solver has a quadratic dependency on `n_features * n_classes`<br>
because it explicitly computes the full Hessian matrix.<br>
- For small datasets, 'liblinear' is a good choice, whereas 'sag'<br>
and 'saga' are faster for large ones;<br>
- 'liblinear' can only handle binary classification by default. To apply a<br>
one-versus-rest scheme for the multiclass setting one can wrap it with the<br>
:class:`~sklearn.multiclass.OneVsRestClassifier`.<br>
<br>
.. warning::<br>
The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`<br>
for L2-penalty, `l1_ratio=1` for L1-penalty and `0 &lt; l1_ratio &lt; 1` for<br>
Elastic-Net) and on (multinomial) multiclass support:<br>
<br>
================= ======================== ======================<br>
solver l1_ratio multinomial multiclass<br>
================= ======================== ======================<br>
'lbfgs' l1_ratio=0 yes<br>
'liblinear' l1_ratio=1 or l1_ratio=0 no<br>
'newton-cg' l1_ratio=0 yes<br>
'newton-cholesky' l1_ratio=0 yes<br>
'sag' l1_ratio=0 yes<br>
'saga' 0&lt;=l1_ratio&lt;=1 yes<br>
================= ======================== ======================<br>
<br>
.. note::<br>
'sag' and 'saga' fast convergence is only guaranteed on features<br>
with approximately the same scale. You can preprocess the data with<br>
a scaler from :mod:`sklearn.preprocessing`.<br>
<br>
.. seealso::<br>
Refer to the :ref:`User Guide <logistic_regression>` for more<br>
information regarding :class:`LogisticRegression` and more specifically the<br>
:ref:`Table <logistic_regression_solvers>`<br>
summarizing solver/penalty supports.<br>
<br>
.. versionadded:: 0.17<br>
Stochastic Average Gradient (SAG) descent solver. Multinomial support in<br>
version 0.18.<br>
.. versionadded:: 0.19<br>
SAGA solver.<br>
.. versionchanged:: 0.22<br>
The default solver changed from 'liblinear' to 'lbfgs' in 0.22.<br>
.. versionadded:: 1.2<br>
newton-cholesky solver. Multinomial support in version 1.6.</logistic_regression_solvers></logistic_regression></span></a></td>
<td class="value">'lbfgs'</td>
</tr>
<tr class="user-set odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100" class="param-doc-link" rel="noreferrer" target="_blank">max_iter <span class="param-doc-description">max_iter: int, default=100<br>
<br>
Maximum number of iterations taken for the solvers to converge.</span></a></td>
<td class="value">200</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0" class="param-doc-link" rel="noreferrer" target="_blank">verbose <span class="param-doc-description">verbose: int, default=0<br>
<br>
For the liblinear and lbfgs solvers set verbose to any positive<br>
number for verbosity.</span></a></td>
<td class="value">0</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse" class="param-doc-link" rel="noreferrer" target="_blank">warm_start <span class="param-doc-description">warm_start: bool, default=False<br>
<br>
When set to True, reuse the solution of the previous call to fit as<br>
initialization, otherwise, just erase the previous solution.<br>
Useless for liblinear solver. See :term:`the Glossary <warm_start>`.<br>
<br>
.. versionadded:: 0.17<br>
*warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.</warm_start></span></a></td>
<td class="value">False</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">n_jobs <span class="param-doc-description">n_jobs: int, default=None<br>
<br>
Does not have any effect.<br>
<br>
.. deprecated:: 1.8<br>
`n_jobs` is deprecated in version 1.8 and will be removed in 1.10.</span></a></td>
<td class="value">None</td>
</tr>
</tbody>
</table>

            </details>
        </div>
    </div></div></div></div></div><script>function copyToClipboard(text, element) {
    // Get the parameter prefix from the closest toggleable content
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;

    const originalStyle = element.style;
    const computedStyle = window.getComputedStyle(element);
    const originalWidth = computedStyle.width;
    const originalHTML = element.innerHTML.replace('Copied!', '');

    navigator.clipboard.writeText(fullParamName)
        .then(() => {
            element.style.width = originalWidth;
            element.style.color = 'green';
            element.innerHTML = "Copied!";

            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        })
        .catch(err => {
            console.error('Failed to copy:', err);
            element.style.color = 'red';
            element.innerHTML = "Failed!";
            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        });
    return false;
}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) {
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const paramName = element.parentElement.nextElementSibling
        .textContent.trim().split(' ')[0];
    const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

    element.setAttribute('title', fullParamName);
});


/**
 * Adapted from Skrub
 * https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/skrub/_reporting/_data/templates/report.js#L789
 * @returns "light" or "dark"
 */
function detectTheme(element) {
    const body = document.querySelector('body');

    // Check VSCode theme
    const themeKindAttr = body.getAttribute('data-vscode-theme-kind');
    const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) {
        const themeKind = themeKindAttr.toLowerCase();
        const themeName = themeNameAttr.toLowerCase();

        if (themeKind.includes("dark") || themeName.includes("dark")) {
            return "dark";
        }
        if (themeKind.includes("light") || themeName.includes("light")) {
            return "light";
        }
    }

    // Check Jupyter theme
    if (body.getAttribute('data-jp-theme-light') === 'false') {
        return 'dark';
    } else if (body.getAttribute('data-jp-theme-light') === 'true') {
        return 'light';
    }

    // Guess based on a parent element's color
    const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color');
    const match = color.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i);
    if (match) {
        const [r, g, b] = [
            parseFloat(match[1]),
            parseFloat(match[2]),
            parseFloat(match[3])
        ];

        // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
        const luma = 0.299 * r + 0.587 * g + 0.114 * b;

        if (luma > 180) {
            // If the text is very bright we have a dark theme
            return 'dark';
        }
        if (luma < 75) {
            // If the text is very dark we have a light theme
            return 'light';
        }
        // Otherwise fall back to the next heuristic.
    }

    // Fallback to system preference
    return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}


function forceTheme(elementId) {
    const estimatorElement = document.querySelector(`#${elementId}`);
    if (estimatorElement === null) {
        console.error(`Element with id ${elementId} not found.`);
    } else {
        const theme = detectTheme(estimatorElement);
        estimatorElement.classList.add(theme);
    }
}

forceTheme('sk-container-id-7');</script>
</div>
</div>
<div id="ab864107" class="cell" data-execution_count="22">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1">a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(logreg.coef_.item(), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb23-2">b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">round</span>(logreg.intercept_.item(), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
</div>
<div id="43bf3ece" class="cell" data-execution_count="23">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb24-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb24-3"></span>
<span id="cb24-4">plt.figure(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb24-5"></span>
<span id="cb24-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Streudiagramm der Trainingsdaten</span></span>
<span id="cb24-7">plt.scatter(X_train, y_train, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Trainingswerte"</span>)</span>
<span id="cb24-8">plt.scatter(X_test, y_test, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Testwerte"</span>)</span>
<span id="cb24-9"></span>
<span id="cb24-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Regressionsfunktion ermitteln</span></span>
<span id="cb24-11"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb24-12"></span>
<span id="cb24-13">xp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(</span>
<span id="cb24-14">    np.linspace(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>),</span>
<span id="cb24-15">    columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sepal length (cm)"</span>]</span>
<span id="cb24-16">)</span>
<span id="cb24-17">yp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> logreg.predict_proba(xp)[:,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] </span>
<span id="cb24-18">pm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+"</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span></span>
<span id="cb24-19">plt.plot(xp, yp, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r'</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">P</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">(</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">y = 1</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">)</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> = </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f'expit(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">x </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>pm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>absb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">)'</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb24-20"></span>
<span id="cb24-21"></span>
<span id="cb24-22">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Länge des Kelchblatts (cm)"</span>)</span>
<span id="cb24-23">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Wahrscheinlichkeit für Iris setosa"</span>)</span>
<span id="cb24-24">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Logistische Regression auf den Liliendaten"</span>)</span>
<span id="cb24-25">plt.legend()</span>
<span id="cb24-26">plt.grid(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb24-27">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-30-lineare-und-logistische-regression-mit-python/index_files/figure-html/cell-24-output-1.webp" width="663" height="449" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Dabei bezeichnet <img src="https://latex.codecogs.com/png.latex?expit(x)"> die logistische Funktion (auch sigmonide Funktion genannt) und ist die Umkehrfunktion der <img src="https://latex.codecogs.com/png.latex?logit">-Funktion.</p>
<p>Wir können an der Grafik schon erkennen, das unser Ansatz so nicht unbedingt optimal ist. Schauen wir uns aber dennoch die Gütemaße an:</p>
<div id="60229c89" class="cell" data-execution_count="24">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb25-1">y_test</span>
<span id="cb25-2">y_pred <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> logreg.predict(X_test)</span>
<span id="cb25-3">y_pred</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="59">
<pre><code>array([1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,
       1, 1, 0, 0, 0, 0, 0, 1])</code></pre>
</div>
</div>
<div id="9044e920" class="cell" data-execution_count="25">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb27-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.metrics <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> accuracy_score, f1_score, precision_score, recall_score, classification_report</span>
<span id="cb27-2"></span>
<span id="cb27-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Accuracy:"</span>, accuracy_score(y_test, y_pred))</span>
<span id="cb27-4"></span>
<span id="cb27-5"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Precision:"</span>, precision_score(y_test, y_pred))</span>
<span id="cb27-6"></span>
<span id="cb27-7"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Recall:"</span>, recall_score(y_test, y_pred))</span>
<span id="cb27-8"></span>
<span id="cb27-9"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"F1-Score:"</span>, f1_score(y_test, y_pred))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Accuracy: 0.9
Precision: 0.75
Recall: 0.8571428571428571
F1-Score: 0.8</code></pre>
</div>
</div>
<p>Etwas detailierter können wir uns das mit dem folgenden Befehl komplett ansehen:</p>
<div id="2ec82923" class="cell" data-execution_count="26">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb29-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(classification_report(y_test, y_pred, target_names<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"positiv"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"negativ"</span>], digits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>              precision    recall  f1-score   support

     positiv      0.955     0.913     0.933        23
     negativ      0.750     0.857     0.800         7

    accuracy                          0.900        30
   macro avg      0.852     0.885     0.867        30
weighted avg      0.907     0.900     0.902        30
</code></pre>
</div>
</div>
<p>Wagen wir kurz einen Blick auf alle Daten (Test- wie Trainingsdaten):</p>
<div id="33be8f59" class="cell" data-execution_count="27">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb31-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(classification_report(y_setosa, logreg.predict(X_setosa), target_names<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"negativ"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"positiv"</span>], digits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>              precision    recall  f1-score   support

     negativ      0.904     0.940     0.922       100
     positiv      0.870     0.800     0.833        50

    accuracy                          0.893       150
   macro avg      0.887     0.870     0.877       150
weighted avg      0.892     0.893     0.892       150
</code></pre>
</div>
</div>
</section>
<section id="multinomiale-logistische-regression" class="level2">
<h2 class="anchored" data-anchor-id="multinomiale-logistische-regression">Multinomiale Logistische Regression</h2>
<div id="1059f02c" class="cell" data-execution_count="28">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb33-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.linear_model <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> LogisticRegression</span>
<span id="cb33-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.model_selection <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> train_test_split</span>
<span id="cb33-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> sklearn.metrics <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> accuracy_score, f1_score, precision_score, recall_score, classification_report</span></code></pre></div></div>
</div>
<p>Wir teilen unsere Daten wieder in Test- und Trainingsdaten auf:</p>
<div id="be9c14f4" class="cell" data-execution_count="29">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb34-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Klassifikationsdaten</span></span>
<span id="cb34-2">X_train, X_test, y_train, y_test <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> train_test_split(X, y, test_size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, random_state<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span></code></pre></div></div>
</div>
<p>Erstelen wir nun ein logistisches Regressionsmodell und trainieren dieses.</p>
<div id="16c7bea9" class="cell" data-execution_count="30">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb35-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Modell</span></span>
<span id="cb35-2">logreg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> LogisticRegression(max_iter<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb35-3">logreg.fit(X_train, y_train)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="65">
<style>#sk-container-id-8 {
  /* Definition of color scheme common for light and dark mode */
  --sklearn-color-text: #000;
  --sklearn-color-text-muted: #666;
  --sklearn-color-line: gray;
  /* Definition of color scheme for unfitted estimators */
  --sklearn-color-unfitted-level-0: #fff5e6;
  --sklearn-color-unfitted-level-1: #f6e4d2;
  --sklearn-color-unfitted-level-2: #ffe0b3;
  --sklearn-color-unfitted-level-3: chocolate;
  /* Definition of color scheme for fitted estimators */
  --sklearn-color-fitted-level-0: #f0f8ff;
  --sklearn-color-fitted-level-1: #d4ebff;
  --sklearn-color-fitted-level-2: #b3dbfd;
  --sklearn-color-fitted-level-3: cornflowerblue;
}

#sk-container-id-8.light {
  /* Specific color for light theme */
  --sklearn-color-text-on-default-background: black;
  --sklearn-color-background: white;
  --sklearn-color-border-box: black;
  --sklearn-color-icon: #696969;
}

#sk-container-id-8.dark {
  --sklearn-color-text-on-default-background: white;
  --sklearn-color-background: #111;
  --sklearn-color-border-box: white;
  --sklearn-color-icon: #878787;
}

#sk-container-id-8 {
  color: var(--sklearn-color-text);
}

#sk-container-id-8 pre {
  padding: 0;
}

#sk-container-id-8 input.sk-hidden--visually {
  border: 0;
  clip: rect(1px 1px 1px 1px);
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

#sk-container-id-8 div.sk-dashed-wrapped {
  border: 1px dashed var(--sklearn-color-line);
  margin: 0 0.4em 0.5em 0.4em;
  box-sizing: border-box;
  padding-bottom: 0.4em;
  background-color: var(--sklearn-color-background);
}

#sk-container-id-8 div.sk-container {
  /* jupyter's `normalize.less` sets `[hidden] { display: none; }`
     but bootstrap.min.css set `[hidden] { display: none !important; }`
     so we also need the `!important` here to be able to override the
     default hidden behavior on the sphinx rendered scikit-learn.org.
     See: https://github.com/scikit-learn/scikit-learn/issues/21755 */
  display: inline-block !important;
  position: relative;
}

#sk-container-id-8 div.sk-text-repr-fallback {
  display: none;
}

div.sk-parallel-item,
div.sk-serial,
div.sk-item {
  /* draw centered vertical line to link estimators */
  background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));
  background-size: 2px 100%;
  background-repeat: no-repeat;
  background-position: center center;
}

/* Parallel-specific style estimator block */

#sk-container-id-8 div.sk-parallel-item::after {
  content: "";
  width: 100%;
  border-bottom: 2px solid var(--sklearn-color-text-on-default-background);
  flex-grow: 1;
}

#sk-container-id-8 div.sk-parallel {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background-color: var(--sklearn-color-background);
  position: relative;
}

#sk-container-id-8 div.sk-parallel-item {
  display: flex;
  flex-direction: column;
}

#sk-container-id-8 div.sk-parallel-item:first-child::after {
  align-self: flex-end;
  width: 50%;
}

#sk-container-id-8 div.sk-parallel-item:last-child::after {
  align-self: flex-start;
  width: 50%;
}

#sk-container-id-8 div.sk-parallel-item:only-child::after {
  width: 0;
}

/* Serial-specific style estimator block */

#sk-container-id-8 div.sk-serial {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: var(--sklearn-color-background);
  padding-right: 1em;
  padding-left: 1em;
}


/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is
clickable and can be expanded/collapsed.
- Pipeline and ColumnTransformer use this feature and define the default style
- Estimators will overwrite some part of the style using the `sk-estimator` class
*/

/* Pipeline and ColumnTransformer style (default) */

#sk-container-id-8 div.sk-toggleable {
  /* Default theme specific background. It is overwritten whether we have a
  specific estimator or a Pipeline/ColumnTransformer */
  background-color: var(--sklearn-color-background);
}

/* Toggleable label */
#sk-container-id-8 label.sk-toggleable__label {
  cursor: pointer;
  display: flex;
  width: 100%;
  margin-bottom: 0;
  padding: 0.5em;
  box-sizing: border-box;
  text-align: center;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}

#sk-container-id-8 label.sk-toggleable__label .caption {
  font-size: 0.6rem;
  font-weight: lighter;
  color: var(--sklearn-color-text-muted);
}

#sk-container-id-8 label.sk-toggleable__label-arrow:before {
  /* Arrow on the left of the label */
  content: "▸";
  float: left;
  margin-right: 0.25em;
  color: var(--sklearn-color-icon);
}

#sk-container-id-8 label.sk-toggleable__label-arrow:hover:before {
  color: var(--sklearn-color-text);
}

/* Toggleable content - dropdown */

#sk-container-id-8 div.sk-toggleable__content {
  display: none;
  text-align: left;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-8 div.sk-toggleable__content.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-8 div.sk-toggleable__content pre {
  margin: 0.2em;
  border-radius: 0.25em;
  color: var(--sklearn-color-text);
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-8 div.sk-toggleable__content.fitted pre {
  /* unfitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

#sk-container-id-8 input.sk-toggleable__control:checked~div.sk-toggleable__content {
  /* Expand drop-down */
  display: block;
  width: 100%;
  overflow: visible;
}

#sk-container-id-8 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {
  content: "▾";
}

/* Pipeline/ColumnTransformer-specific style */

#sk-container-id-8 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-8 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator-specific style */

/* Colorize estimator box */
#sk-container-id-8 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-8 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

#sk-container-id-8 div.sk-label label.sk-toggleable__label,
#sk-container-id-8 div.sk-label label {
  /* The background is the default theme color */
  color: var(--sklearn-color-text-on-default-background);
}

/* On hover, darken the color of the background */
#sk-container-id-8 div.sk-label:hover label.sk-toggleable__label {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-unfitted-level-2);
}

/* Label box, darken color on hover, fitted */
#sk-container-id-8 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {
  color: var(--sklearn-color-text);
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Estimator label */

#sk-container-id-8 div.sk-label label {
  font-family: monospace;
  font-weight: bold;
  line-height: 1.2em;
}

#sk-container-id-8 div.sk-label-container {
  text-align: center;
}

/* Estimator-specific */
#sk-container-id-8 div.sk-estimator {
  font-family: monospace;
  border: 1px dotted var(--sklearn-color-border-box);
  border-radius: 0.25em;
  box-sizing: border-box;
  margin-bottom: 0.5em;
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-0);
}

#sk-container-id-8 div.sk-estimator.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
}

/* on hover */
#sk-container-id-8 div.sk-estimator:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-2);
}

#sk-container-id-8 div.sk-estimator.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-2);
}

/* Specification for estimator info (e.g. "i" and "?") */

/* Common style for "i" and "?" */

.sk-estimator-doc-link,
a:link.sk-estimator-doc-link,
a:visited.sk-estimator-doc-link {
  float: right;
  font-size: smaller;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1em;
  height: 1em;
  width: 1em;
  text-decoration: none !important;
  margin-left: 0.5em;
  text-align: center;
  /* unfitted */
  border: var(--sklearn-color-unfitted-level-3) 1pt solid;
  color: var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted,
a:link.sk-estimator-doc-link.fitted,
a:visited.sk-estimator-doc-link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3) 1pt solid;
  color: var(--sklearn-color-fitted-level-3);
}

/* On hover */
div.sk-estimator:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover,
div.sk-label-container:hover .sk-estimator-doc-link:hover,
.sk-estimator-doc-link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-unfitted-level-0);
  text-decoration: none;
}

div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover,
div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,
.sk-estimator-doc-link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
  border: var(--sklearn-color-fitted-level-0) 1pt solid;
  color: var(--sklearn-color-fitted-level-0);
  text-decoration: none;
}

/* Span, style for the box shown on hovering the info icon */
.sk-estimator-doc-link span {
  display: none;
  z-index: 9999;
  position: relative;
  font-weight: normal;
  right: .2ex;
  padding: .5ex;
  margin: .5ex;
  width: min-content;
  min-width: 20ex;
  max-width: 50ex;
  color: var(--sklearn-color-text);
  box-shadow: 2pt 2pt 4pt #999;
  /* unfitted */
  background: var(--sklearn-color-unfitted-level-0);
  border: .5pt solid var(--sklearn-color-unfitted-level-3);
}

.sk-estimator-doc-link.fitted span {
  /* fitted */
  background: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-3);
}

.sk-estimator-doc-link:hover span {
  display: block;
}

/* "?"-specific style due to the `<a>` HTML tag */

#sk-container-id-8 a.estimator_doc_link {
  float: right;
  font-size: 1rem;
  line-height: 1em;
  font-family: monospace;
  background-color: var(--sklearn-color-unfitted-level-0);
  border-radius: 1rem;
  height: 1rem;
  width: 1rem;
  text-decoration: none;
  /* unfitted */
  color: var(--sklearn-color-unfitted-level-1);
  border: var(--sklearn-color-unfitted-level-1) 1pt solid;
}

#sk-container-id-8 a.estimator_doc_link.fitted {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-0);
  border: var(--sklearn-color-fitted-level-1) 1pt solid;
  color: var(--sklearn-color-fitted-level-1);
}

/* On hover */
#sk-container-id-8 a.estimator_doc_link:hover {
  /* unfitted */
  background-color: var(--sklearn-color-unfitted-level-3);
  color: var(--sklearn-color-background);
  text-decoration: none;
}

#sk-container-id-8 a.estimator_doc_link.fitted:hover {
  /* fitted */
  background-color: var(--sklearn-color-fitted-level-3);
}

.estimator-table {
    font-family: monospace;
}

.estimator-table summary {
    padding: .5rem;
    cursor: pointer;
}

.estimator-table summary::marker {
    font-size: 0.7rem;
}

.estimator-table details[open] {
    padding-left: 0.1rem;
    padding-right: 0.1rem;
    padding-bottom: 0.3rem;
}

.estimator-table .parameters-table {
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: 0;
}

.estimator-table .parameters-table tr:nth-child(odd) {
    background-color: #fff;
}

.estimator-table .parameters-table tr:nth-child(even) {
    background-color: #f6f6f6;
}

.estimator-table .parameters-table tr:hover {
    background-color: #e0e0e0;
}

.estimator-table table td {
    border: 1px solid rgba(106, 105, 104, 0.232);
}

/*
    `table td`is set in notebook with right text-align.
    We need to overwrite it.
*/
.estimator-table table td.param {
    text-align: left;
    position: relative;
    padding: 0;
}

.user-set td {
    color:rgb(255, 94, 0);
    text-align: left !important;
}

.user-set td.value {
    color:rgb(255, 94, 0);
    background-color: transparent;
}

.default td {
    color: black;
    text-align: left !important;
}

.user-set td i,
.default td i {
    color: black;
}

/*
    Styles for parameter documentation links
    We need styling for visited so jupyter doesn't overwrite it
*/
a.param-doc-link,
a.param-doc-link:link,
a.param-doc-link:visited {
    text-decoration: underline dashed;
    text-underline-offset: .3em;
    color: inherit;
    display: block;
    padding: .5em;
}

/* "hack" to make the entire area of the cell containing the link clickable */
a.param-doc-link::before {
    position: absolute;
    content: "";
    inset: 0;
}

.param-doc-description {
    display: none;
    position: absolute;
    z-index: 9999;
    left: 0;
    padding: .5ex;
    margin-left: 1.5em;
    color: var(--sklearn-color-text);
    box-shadow: .3em .3em .4em #999;
    width: max-content;
    text-align: left;
    max-height: 10em;
    overflow-y: auto;

    /* unfitted */
    background: var(--sklearn-color-unfitted-level-0);
    border: thin solid var(--sklearn-color-unfitted-level-3);
}

/* Fitted state for parameter tooltips */
.fitted .param-doc-description {
    /* fitted */
    background: var(--sklearn-color-fitted-level-0);
    border: thin solid var(--sklearn-color-fitted-level-3);
}

.param-doc-link:hover .param-doc-description {
    display: block;
}

.copy-paste-icon {
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);
    background-repeat: no-repeat;
    background-size: 14px 14px;
    background-position: 0;
    display: inline-block;
    width: 14px;
    height: 14px;
    cursor: pointer;
}
</style><div id="sk-container-id-8" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>LogisticRegression(max_iter=200)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br>On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class="sk-container" hidden=""><div class="sk-item"><div class="sk-estimator fitted sk-toggleable"><input class="sk-toggleable__control sk-hidden--visually" id="sk-estimator-id-8" type="checkbox" checked=""><label for="sk-estimator-id-8" class="sk-toggleable__label fitted sk-toggleable__label-arrow"><div><div>LogisticRegression</div></div><div><a class="sk-estimator-doc-link fitted" rel="noreferrer" target="_blank" href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html">?<span>Documentation for LogisticRegression</span></a><span class="sk-estimator-doc-link fitted">i<span>Fitted</span></span></div></label><div class="sk-toggleable__content fitted" data-param-prefix="">
        <div class="estimator-table">
            <details>
                <summary>Parameters</summary>
                
<table class="parameters-table caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<tbody>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=penalty,-%7B%27l1%27%2C%20%27l2%27%2C%20%27elasticnet%27%2C%20None%7D%2C%20default%3D%27l2%27" class="param-doc-link" rel="noreferrer" target="_blank">penalty <span class="param-doc-description">penalty: {'l1', 'l2', 'elasticnet', None}, default='l2'<br>
<br>
Specify the norm of the penalty:<br>
<br>
- `None`: no penalty is added;<br>
- `'l2'`: add a L2 penalty term and it is the default choice;<br>
- `'l1'`: add a L1 penalty term;<br>
- `'elasticnet'`: both L1 and L2 penalty terms are added.<br>
<br>
.. warning::<br>
Some penalties may not work with some solvers. See the parameter<br>
`solver` below, to know the compatibility between the penalty and<br>
solver.<br>
<br>
.. versionadded:: 0.19<br>
l1 penalty with SAGA solver (allowing 'multinomial' + L1)<br>
<br>
.. deprecated:: 1.8<br>
`penalty` was deprecated in version 1.8 and will be removed in 1.10.<br>
Use `l1_ratio` instead. `l1_ratio=0` for `penalty='l2'`, `l1_ratio=1` for<br>
`penalty='l1'` and `l1_ratio` set to any float between 0 and 1 for<br>
`'penalty='elasticnet'`.</span></a></td>
<td class="value">'deprecated'</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=C,-float%2C%20default%3D1.0" class="param-doc-link" rel="noreferrer" target="_blank">C <span class="param-doc-description">C: float, default=1.0<br>
<br>
Inverse of regularization strength; must be a positive float.<br>
Like in support vector machines, smaller values specify stronger<br>
regularization. `C=np.inf` results in unpenalized logistic regression.<br>
For a visual example on the effect of tuning the `C` parameter<br>
with an L1 penalty, see:<br>
:ref:`sphx_glr_auto_examples_linear_model_plot_logistic_path.py`.</span></a></td>
<td class="value">1.0</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=l1_ratio,-float%2C%20default%3D0.0" class="param-doc-link" rel="noreferrer" target="_blank">l1_ratio <span class="param-doc-description">l1_ratio: float, default=0.0<br>
<br>
The Elastic-Net mixing parameter, with `0 &lt;= l1_ratio &lt;= 1`. Setting<br>
`l1_ratio=1` gives a pure L1-penalty, setting `l1_ratio=0` a pure L2-penalty.<br>
Any value between 0 and 1 gives an Elastic-Net penalty of the form<br>
`l1_ratio * L1 + (1 - l1_ratio) * L2`.<br>
<br>
.. warning::<br>
Certain values of `l1_ratio`, i.e. some penalties, may not work with some<br>
solvers. See the parameter `solver` below, to know the compatibility between<br>
the penalty and solver.<br>
<br>
.. versionchanged:: 1.8<br>
Default value changed from None to 0.0.<br>
<br>
.. deprecated:: 1.8<br>
`None` is deprecated and will be removed in version 1.10. Always use<br>
`l1_ratio` to specify the penalty type.</span></a></td>
<td class="value">0.0</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=dual,-bool%2C%20default%3DFalse" class="param-doc-link" rel="noreferrer" target="_blank">dual <span class="param-doc-description">dual: bool, default=False<br>
<br>
Dual (constrained) or primal (regularized, see also<br>
:ref:`this equation <regularized-logistic-loss>`) formulation. Dual formulation<br>
is only implemented for l2 penalty with liblinear solver. Prefer `dual=False`<br>
when n_samples &gt; n_features.</regularized-logistic-loss></span></a></td>
<td class="value">False</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=tol,-float%2C%20default%3D1e-4" class="param-doc-link" rel="noreferrer" target="_blank">tol <span class="param-doc-description">tol: float, default=1e-4<br>
<br>
Tolerance for stopping criteria.</span></a></td>
<td class="value">0.0001</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=fit_intercept,-bool%2C%20default%3DTrue" class="param-doc-link" rel="noreferrer" target="_blank">fit_intercept <span class="param-doc-description">fit_intercept: bool, default=True<br>
<br>
Specifies if a constant (a.k.a. bias or intercept) should be<br>
added to the decision function.</span></a></td>
<td class="value">True</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=intercept_scaling,-float%2C%20default%3D1" class="param-doc-link" rel="noreferrer" target="_blank">intercept_scaling <span class="param-doc-description">intercept_scaling: float, default=1<br>
<br>
Useful only when the solver `liblinear` is used<br>
and `self.fit_intercept` is set to `True`. In this case, `x` becomes<br>
`[x, self.intercept_scaling]`,<br>
i.e. a "synthetic" feature with constant value equal to<br>
`intercept_scaling` is appended to the instance vector.<br>
The intercept becomes<br>
``intercept_scaling * synthetic_feature_weight``.<br>
<br>
.. note::<br>
The synthetic feature weight is subject to L1 or L2<br>
regularization as all other features.<br>
To lessen the effect of regularization on synthetic feature weight<br>
(and therefore on the intercept) `intercept_scaling` has to be increased.</span></a></td>
<td class="value">1</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=class_weight,-dict%20or%20%27balanced%27%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">class_weight <span class="param-doc-description">class_weight: dict or 'balanced', default=None<br>
<br>
Weights associated with classes in the form ``{class_label: weight}``.<br>
If not given, all classes are supposed to have weight one.<br>
<br>
The "balanced" mode uses the values of y to automatically adjust<br>
weights inversely proportional to class frequencies in the input data<br>
as ``n_samples / (n_classes * np.bincount(y))``.<br>
<br>
Note that these weights will be multiplied with sample_weight (passed<br>
through the fit method) if sample_weight is specified.<br>
<br>
.. versionadded:: 0.17<br>
*class_weight='balanced'*</span></a></td>
<td class="value">None</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=random_state,-int%2C%20RandomState%20instance%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">random_state <span class="param-doc-description">random_state: int, RandomState instance, default=None<br>
<br>
Used when ``solver`` == 'sag', 'saga' or 'liblinear' to shuffle the<br>
data. See :term:`Glossary <random_state>` for details.</random_state></span></a></td>
<td class="value">None</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=solver,-%7B%27lbfgs%27%2C%20%27liblinear%27%2C%20%27newton-cg%27%2C%20%27newton-cholesky%27%2C%20%27sag%27%2C%20%27saga%27%7D%2C%20%20%20%20%20%20%20%20%20%20%20%20%20default%3D%27lbfgs%27" class="param-doc-link" rel="noreferrer" target="_blank">solver <span class="param-doc-description">solver: {'lbfgs', 'liblinear', 'newton-cg', 'newton-cholesky', 'sag', 'saga'}, default='lbfgs'<br>
<br>
Algorithm to use in the optimization problem. Default is 'lbfgs'.<br>
To choose a solver, you might want to consider the following aspects:<br>
<br>
- 'lbfgs' is a good default solver because it works reasonably well for a wide<br>
class of problems.<br>
- For :term:`multiclass` problems (`n_classes &gt;= 3`), all solvers except<br>
'liblinear' minimize the full multinomial loss, 'liblinear' will raise an<br>
error.<br>
- 'newton-cholesky' is a good choice for<br>
`n_samples` &gt;&gt; `n_features * n_classes`, especially with one-hot encoded<br>
categorical features with rare categories. Be aware that the memory usage<br>
of this solver has a quadratic dependency on `n_features * n_classes`<br>
because it explicitly computes the full Hessian matrix.<br>
- For small datasets, 'liblinear' is a good choice, whereas 'sag'<br>
and 'saga' are faster for large ones;<br>
- 'liblinear' can only handle binary classification by default. To apply a<br>
one-versus-rest scheme for the multiclass setting one can wrap it with the<br>
:class:`~sklearn.multiclass.OneVsRestClassifier`.<br>
<br>
.. warning::<br>
The choice of the algorithm depends on the penalty chosen (`l1_ratio=0`<br>
for L2-penalty, `l1_ratio=1` for L1-penalty and `0 &lt; l1_ratio &lt; 1` for<br>
Elastic-Net) and on (multinomial) multiclass support:<br>
<br>
================= ======================== ======================<br>
solver l1_ratio multinomial multiclass<br>
================= ======================== ======================<br>
'lbfgs' l1_ratio=0 yes<br>
'liblinear' l1_ratio=1 or l1_ratio=0 no<br>
'newton-cg' l1_ratio=0 yes<br>
'newton-cholesky' l1_ratio=0 yes<br>
'sag' l1_ratio=0 yes<br>
'saga' 0&lt;=l1_ratio&lt;=1 yes<br>
================= ======================== ======================<br>
<br>
.. note::<br>
'sag' and 'saga' fast convergence is only guaranteed on features<br>
with approximately the same scale. You can preprocess the data with<br>
a scaler from :mod:`sklearn.preprocessing`.<br>
<br>
.. seealso::<br>
Refer to the :ref:`User Guide <logistic_regression>` for more<br>
information regarding :class:`LogisticRegression` and more specifically the<br>
:ref:`Table <logistic_regression_solvers>`<br>
summarizing solver/penalty supports.<br>
<br>
.. versionadded:: 0.17<br>
Stochastic Average Gradient (SAG) descent solver. Multinomial support in<br>
version 0.18.<br>
.. versionadded:: 0.19<br>
SAGA solver.<br>
.. versionchanged:: 0.22<br>
The default solver changed from 'liblinear' to 'lbfgs' in 0.22.<br>
.. versionadded:: 1.2<br>
newton-cholesky solver. Multinomial support in version 1.6.</logistic_regression_solvers></logistic_regression></span></a></td>
<td class="value">'lbfgs'</td>
</tr>
<tr class="user-set odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=max_iter,-int%2C%20default%3D100" class="param-doc-link" rel="noreferrer" target="_blank">max_iter <span class="param-doc-description">max_iter: int, default=100<br>
<br>
Maximum number of iterations taken for the solvers to converge.</span></a></td>
<td class="value">200</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=verbose,-int%2C%20default%3D0" class="param-doc-link" rel="noreferrer" target="_blank">verbose <span class="param-doc-description">verbose: int, default=0<br>
<br>
For the liblinear and lbfgs solvers set verbose to any positive<br>
number for verbosity.</span></a></td>
<td class="value">0</td>
</tr>
<tr class="default odd">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=warm_start,-bool%2C%20default%3DFalse" class="param-doc-link" rel="noreferrer" target="_blank">warm_start <span class="param-doc-description">warm_start: bool, default=False<br>
<br>
When set to True, reuse the solution of the previous call to fit as<br>
initialization, otherwise, just erase the previous solution.<br>
Useless for liblinear solver. See :term:`the Glossary <warm_start>`.<br>
<br>
.. versionadded:: 0.17<br>
*warm_start* to support *lbfgs*, *newton-cg*, *sag*, *saga* solvers.</warm_start></span></a></td>
<td class="value">False</td>
</tr>
<tr class="default even">
<td><em></em></td>
<td class="param"><a href="https://scikit-learn.org/1.8/modules/generated/sklearn.linear_model.LogisticRegression.html#:~:text=n_jobs,-int%2C%20default%3DNone" class="param-doc-link" rel="noreferrer" target="_blank">n_jobs <span class="param-doc-description">n_jobs: int, default=None<br>
<br>
Does not have any effect.<br>
<br>
.. deprecated:: 1.8<br>
`n_jobs` is deprecated in version 1.8 and will be removed in 1.10.</span></a></td>
<td class="value">None</td>
</tr>
</tbody>
</table>

            </details>
        </div>
    </div></div></div></div></div><script>function copyToClipboard(text, element) {
    // Get the parameter prefix from the closest toggleable content
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;

    const originalStyle = element.style;
    const computedStyle = window.getComputedStyle(element);
    const originalWidth = computedStyle.width;
    const originalHTML = element.innerHTML.replace('Copied!', '');

    navigator.clipboard.writeText(fullParamName)
        .then(() => {
            element.style.width = originalWidth;
            element.style.color = 'green';
            element.innerHTML = "Copied!";

            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        })
        .catch(err => {
            console.error('Failed to copy:', err);
            element.style.color = 'red';
            element.innerHTML = "Failed!";
            setTimeout(() => {
                element.innerHTML = originalHTML;
                element.style = originalStyle;
            }, 2000);
        });
    return false;
}

document.querySelectorAll('.copy-paste-icon').forEach(function(element) {
    const toggleableContent = element.closest('.sk-toggleable__content');
    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';
    const paramName = element.parentElement.nextElementSibling
        .textContent.trim().split(' ')[0];
    const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;

    element.setAttribute('title', fullParamName);
});


/**
 * Adapted from Skrub
 * https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/skrub/_reporting/_data/templates/report.js#L789
 * @returns "light" or "dark"
 */
function detectTheme(element) {
    const body = document.querySelector('body');

    // Check VSCode theme
    const themeKindAttr = body.getAttribute('data-vscode-theme-kind');
    const themeNameAttr = body.getAttribute('data-vscode-theme-name');

    if (themeKindAttr && themeNameAttr) {
        const themeKind = themeKindAttr.toLowerCase();
        const themeName = themeNameAttr.toLowerCase();

        if (themeKind.includes("dark") || themeName.includes("dark")) {
            return "dark";
        }
        if (themeKind.includes("light") || themeName.includes("light")) {
            return "light";
        }
    }

    // Check Jupyter theme
    if (body.getAttribute('data-jp-theme-light') === 'false') {
        return 'dark';
    } else if (body.getAttribute('data-jp-theme-light') === 'true') {
        return 'light';
    }

    // Guess based on a parent element's color
    const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color');
    const match = color.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/i);
    if (match) {
        const [r, g, b] = [
            parseFloat(match[1]),
            parseFloat(match[2]),
            parseFloat(match[3])
        ];

        // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
        const luma = 0.299 * r + 0.587 * g + 0.114 * b;

        if (luma > 180) {
            // If the text is very bright we have a dark theme
            return 'dark';
        }
        if (luma < 75) {
            // If the text is very dark we have a light theme
            return 'light';
        }
        // Otherwise fall back to the next heuristic.
    }

    // Fallback to system preference
    return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}


function forceTheme(elementId) {
    const estimatorElement = document.querySelector(`#${elementId}`);
    if (estimatorElement === null) {
        console.error(`Element with id ${elementId} not found.`);
    } else {
        const theme = detectTheme(estimatorElement);
        estimatorElement.classList.add(theme);
    }
}

forceTheme('sk-container-id-8');</script>
</div>
</div>
<p>Erzeugen wir nun aus unserem Modell eine Vorhersage für die Testdaten:</p>
<div id="df569220" class="cell" data-execution_count="31">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb36-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vorhersage</span></span>
<span id="cb36-2">y_pred <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> logreg.predict(X_test)</span></code></pre></div></div>
</div>
<p>Schauen wir uns für die Testdaten einmal die echten und vorhergesagten Werte an:</p>
<div id="68ad73d0" class="cell" data-execution_count="32">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb37-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vergleich der Testdaten</span></span>
<span id="cb37-2">y_test</span>
<span id="cb37-3">y_pred</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="67">
<pre><code>array([0, 0, 2, 1, 1, 2, 2, 1, 2, 2, 2, 0, 2, 2, 2, 1, 2, 1, 0, 1, 1, 0,
       0, 1, 1, 2, 1, 2, 1, 0])</code></pre>
</div>
</div>
<p>Berechnen wir die üblichen Gütemaße:</p>
<div id="a3a22636" class="cell" data-execution_count="33">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb39-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Accuracy:"</span>, accuracy_score(y_test, y_pred))</span>
<span id="cb39-2"></span>
<span id="cb39-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Precision:"</span>, precision_score(y_test, y_pred, average<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'weighted'</span>))</span>
<span id="cb39-4"></span>
<span id="cb39-5"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Recall:"</span>, recall_score(y_test, y_pred, average<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'weighted'</span>))</span>
<span id="cb39-6"></span>
<span id="cb39-7"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"F1-Score:"</span>, f1_score(y_test, y_pred, average<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'weighted'</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Accuracy: 0.9333333333333333
Precision: 0.9454545454545454
Recall: 0.9333333333333333
F1-Score: 0.9341025641025641</code></pre>
</div>
</div>
<p>Etwas detailierter können wir uns das mit dem folgenden Befehl komplett ansehen:</p>
<div id="85f18d74" class="cell" data-execution_count="34">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb41-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(classification_report(y_test, y_pred, target_names<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>iris.target_names, digits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>              precision    recall  f1-score   support

      setosa      1.000     1.000     1.000         7
  versicolor      0.818     1.000     0.900         9
   virginica      1.000     0.857     0.923        14

    accuracy                          0.933        30
   macro avg      0.939     0.952     0.941        30
weighted avg      0.945     0.933     0.934        30
</code></pre>
</div>
</div>
<p>Wagen wir kurz einen Blick auf alle Daten (Test- wie Trainingsdaten):</p>
<div id="a38d1776" class="cell" data-execution_count="35">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb43-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(classification_report(y, logreg.predict(X), target_names<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>iris.target_names, digits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>              precision    recall  f1-score   support

      setosa      1.000     1.000     1.000        50
  versicolor      0.923     0.960     0.941        50
   virginica      0.958     0.920     0.939        50

    accuracy                          0.960       150
   macro avg      0.960     0.960     0.960       150
weighted avg      0.960     0.960     0.960       150
</code></pre>
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Fußnoten</h2>

<ol>
<li id="fn1"><p>vgl.: <a href="https://de.wikipedia.org/wiki/Schwertlilien-Datensatz" class="uri">https://de.wikipedia.org/wiki/Schwertlilien-Datensatz</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Statistik</category>
  <category>Lineare Regression</category>
  <category>Logistische Regression</category>
  <category>Python</category>
  <guid>https://www.sefiroth.de/posts/2026-05-30-lineare-und-logistische-regression-mit-python/</guid>
  <pubDate>Fri, 29 May 2026 22:00:00 GMT</pubDate>
</item>
<item>
  <title>NumPy und Pandas: Warum, wieso, weshalb?</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-03-27-numpy-und-pandas-warum-wieso-wesshalb/</link>
  <description><![CDATA[ 





<section id="numpy-und-pandas-warum-wieso-weshalb" class="level1">
<h1>NumPy und Pandas: Warum, wieso, weshalb?</h1>
<p>In der Welt der Datenanalyse und wissenschaftlichen Berechnung sind NumPy und Pandas zwei unverzichtbare Bibliotheken in Python. Aber warum sind sie so wichtig? In diesem Artikel werden wir die Gründe untersuchen, warum NumPy und Pandas in der Datenanalyse so weit verbreitet sind, welche Vorteile sie bieten und wie sie sich voneinander unterscheiden.</p>
<section id="warum-numpy" class="level2">
<h2 class="anchored" data-anchor-id="warum-numpy">Warum NumPy?</h2>
<p>NumPy, kurz für “<strong>Num</strong>erical <strong>Py</strong>thon”, ist eine Bibliothek, die effiziente Operationen auf großen, mehrdimensionalen Arrays und Matrizen ermöglicht. Hier sind einige Gründe, warum NumPy so beliebt ist:</p>
<ol type="1">
<li><p><strong>Leistung</strong>: NumPy ist in C und Fortran geschrieben, was es extrem schnell macht. Es bietet Funktionen, die auf Vektorisierung basieren, wodurch Operationen auf Arrays viel schneller ausgeführt werden können als mit herkömmlichen Python-Listen.</p></li>
<li><p><strong>Funktionalität</strong>: NumPy bietet eine breite Palette von Funktionen für mathem atische Operationen, lineare Algebra, Fourier-Transformationen und vieles mehr. Es ist die Grundlage für viele andere Bibliotheken wie SciPy, Matplotlib und Pandas.</p></li>
<li><p><strong>Kompatibilität</strong>: Viele andere Bibliotheken in der Datenwissenschaft und maschinellen Lernen basieren auf NumPy, was es zu einem unverzichtbaren Werkzeug für die Arbeit mit Daten macht.</p></li>
<li><p><strong>Einfachheit</strong>: NumPy bietet eine einfache und intuitive Syntax für die Arbeit mit Arrays, was es Anfängern leicht macht, sich in die Welt der Datenanalyse einzuarbeiten</p></li>
</ol>
<p><em>Kurz:</em></p>
<p><strong>“NumPy = schnelle Mathematik + feste Typen + große Reihungen” in Python</strong></p>
<section id="beispiel" class="level3">
<h3 class="anchored" data-anchor-id="beispiel">Beispiel</h3>
<p>Stellen wir uns vor, wir wollen 10 Millionen Zahlen in einer Python Liste speichern.</p>
<p>Eine Python Liste aber:</p>
<ul>
<li>Speichert die Werte irgendwo im Speicher und nicht unmittelbar hintereinander.</li>
<li>Speichert die Werte als Objekte, was zusätzlichen Speicherplatz benötigt.</li>
<li>Ist nicht für numerische Berechnungen optimiert, da jedes Objekt individuell behandelt werden muss.</li>
</ul>
<p>Stellen wir uns vor, wie wollen zu jeder Zahl 10 hinzuaddieren. Mit einer Python Liste müssten wir eine Schleife verwenden, um durch die Liste zu iterieren und die Addition für jedes Element durchzuführen, was sehr langsam sein kann.</p>
<div id="6a5483e6" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> time</span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen einer Liste mit 10 Million Zahlen</span></span>
<span id="cb1-3">my_list <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10_000_000</span>))</span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Startzeit</span></span>
<span id="cb1-5">start_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time()</span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Hinzufügen von 10 zu jedem Element in der Liste</span></span>
<span id="cb1-7"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(my_list)):</span>
<span id="cb1-8">    my_list[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Endzeit</span></span>
<span id="cb1-10">end_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time()</span>
<span id="cb1-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Zeit für die Addition in der Liste: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>end_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> start_time<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:0.4}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> Sekunden"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Zeit für die Addition in der Liste: 0.7197 Sekunden</code></pre>
</div>
</div>
<p>Die angegebe Laufzeit hängen natürlich von den Rechner und den Versionen der Software ab.</p>
<p>Der Grund wieso das alles so langsam ist, liegt unter anderem daran, dass die 10.000.000 Einträge in der Python Liste in der Schleife durchlaufen wird. Und das ist langsam, denn die ergentliche Liste ist eine Liste von Verweisen auf die in einem Objekt gespeicherten eigentlichen Werte. Python geht also (schnell) eine Liste von Referenzen durch, muss aber jedesmal (irgendwo) im Speicher den eigentlichen Werte suchen, dann anpassen und dann in der (Referenz-)Liste den nächsten suchen.</p>
<p>Die Lösung dieses Problems ist NumPy.</p>
<p>Mit NumPy können wir ein Array erstellen, das die Zahlen direkt hintereinander im Speicher speichert und die Werte als numerische Datentypen behandelt, da es davon ausgeht, dass diese alle vom selben Datentyp sind. (Python schaut erst in den Metadaten des Objekts nach, ob dem so ist. Das kostet auch Zeit.) Dadurch können wir die Addition von 10 zu jedem Element in einem einzigen Schritt durchführen, ohne eine Python-Schleife zu verwenden, was viel schneller ist.</p>
<p>Okay, wir durchlaufen schon eine Schleife, aber diese muss nicht nach dem eigentlichen Objekt mit dem Eintrag in Speicher suchen. Denn im Array sind alle Objekte vom selbern Datentyp und belegen immer den selber Speicherplatz und das hintereinander. Wir springen also direkt zum nächsten Eintrag, ändern und gehen weiter. Das ist deutlich schneller und ermöglicht das die Verarbeitung optimiert ist. NumPy nutzt auch Vektorisierung, um Operationen auf Arrays effizienter durchzuführen, indem es sie in C (oder Fortran) ausführt, anstatt in Python.</p>
<div id="3268c417" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> time</span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines NumPy-Arrays mit 10 Million Zahlen</span></span>
<span id="cb3-4">my_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.arange(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10_000_000</span>)</span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Startzeit</span></span>
<span id="cb3-6">start_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time()</span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Hinzufügen von 10 zu jedem Element im Array</span></span>
<span id="cb3-8">my_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb3-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Endzeit</span></span>
<span id="cb3-10">end_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time()</span>
<span id="cb3-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Zeit für die Addition im NumPy-Array: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>end_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> start_time<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:0.4}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> Sekunden."</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Zeit für die Addition im NumPy-Array: 0.00966 Sekunden.</code></pre>
</div>
</div>
<p>Auch hier hängt die angegebene Laufzeit vom Rechner und den Software Versionen ab. Aber die Tendenzen zeigen sich hier schon klar. NumPy ist deutlich schneller als reines Python.</p>
<p>Darum ist NumPy die Grundlage für die Pakete:</p>
<ul>
<li>Tensoflow</li>
<li>PyTorch</li>
<li>Scikit-learn</li>
<li>SciPy</li>
<li>JAX</li>
<li>u.v.m.</li>
</ul>
</section>
<section id="ein-paar-numpy-grundlagen" class="level3">
<h3 class="anchored" data-anchor-id="ein-paar-numpy-grundlagen">Ein paar NumPy Grundlagen</h3>
<section id="numpy-arrays-erstellen" class="level4">
<h4 class="anchored" data-anchor-id="numpy-arrays-erstellen">NumPy Arrays erstellen</h4>
<div id="79a794ba" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines 1D-Arrays</span></span>
<span id="cb5-3">array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb5-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(array_1d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1 2 3 4 5]</code></pre>
</div>
</div>
<div id="ca976fb9" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines 2D-Arrays</span></span>
<span id="cb7-2">array_2d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>], [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]])</span>
<span id="cb7-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(array_2d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[[1 2 3]
 [4 5 6]]</code></pre>
</div>
</div>
<div id="6c2c4576" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines Arrays mit Nullen</span></span>
<span id="cb9-2">zeros_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.zeros((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb9-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(zeros_array)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]</code></pre>
</div>
</div>
<div id="c06c45e7" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines Arrays mit Einsen</span></span>
<span id="cb11-2">ones_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.ones((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb11-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(ones_array)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[[1. 1. 1. 1.]
 [1. 1. 1. 1.]]</code></pre>
</div>
</div>
<div id="0ba87a70" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines Arrays mit einem bestimmten Wert</span></span>
<span id="cb13-2">full_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.full((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)</span>
<span id="cb13-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(full_array)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[[7 7 7]
 [7 7 7]]</code></pre>
</div>
</div>
<div id="6a8cc203" class="cell" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines Arrays mit zufälligen Werten</span></span>
<span id="cb15-2">random_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.rand(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb15-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(random_array)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[[0.04524801 0.17362701 0.55020998 0.56475387]
 [0.62126866 0.79769594 0.41116384 0.63088773]
 [0.80078245 0.9323055  0.79312686 0.02891873]
 [0.67272316 0.14979315 0.78068532 0.67047379]]</code></pre>
</div>
</div>
<div id="9035d3d6" class="cell" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines Arrays der ersten 10 natürlichen Zahlen</span></span>
<span id="cb17-2">arange_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.arange(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb17-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(arange_array)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[0 1 2 3 4 5 6 7 8 9]</code></pre>
</div>
</div>
<div id="7e17dcf3" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines Arrays mit fünf gleichmäßig verteilten Werten zwischen 0 und 1</span></span>
<span id="cb19-2">linspace_array <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb19-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(linspace_array)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[0.   0.25 0.5  0.75 1.  ]</code></pre>
</div>
</div>
</section>
<section id="gestalt-shape-größe-size-und-dimensionen-ndim-von-numpy-arrays" class="level4">
<h4 class="anchored" data-anchor-id="gestalt-shape-größe-size-und-dimensionen-ndim-von-numpy-arrays">Gestalt (shape), Größe (size) und Dimensionen (ndim) von NumPy Arrays</h4>
<div id="3b5d9395" class="cell" data-execution_count="11">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb21-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb21-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines 2D-Arrays</span></span>
<span id="cb21-3">array_2d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>], [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]])</span>
<span id="cb21-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Array:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Array:
 [[1 2 3]
 [4 5 6]]</code></pre>
</div>
</div>
<div id="48cf94b4" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb23-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Form des Arrays</span></span>
<span id="cb23-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Shape:"</span>, array_2d.shape)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Shape: (2, 3)</code></pre>
</div>
</div>
<div id="1079ac82" class="cell" data-execution_count="13">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb25-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Größe des Arrays</span></span>
<span id="cb25-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Size:"</span>, array_2d.size)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Size: 6</code></pre>
</div>
</div>
<div id="02d6173b" class="cell" data-execution_count="14">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb27-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzahl der Dimensionen</span></span>
<span id="cb27-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of dimensions:"</span>, array_2d.ndim)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Number of dimensions: 2</code></pre>
</div>
</div>
</section>
<section id="numpy-array-indexierung-und-slicing" class="level4">
<h4 class="anchored" data-anchor-id="numpy-array-indexierung-und-slicing">NumPy Array Indexierung und Slicing</h4>
<div id="a155919b" class="cell" data-execution_count="15">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb29-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb29-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines 2D-Arrays</span></span>
<span id="cb29-3">array_2d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>], [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]])</span>
<span id="cb29-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein 2D-Array:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,array_2d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein 2D-Array:
 [[1 2 3]
 [4 5 6]]</code></pre>
</div>
</div>
<div id="de65ab47" class="cell" data-execution_count="16">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb31-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zugriff auf ein Element</span></span>
<span id="cb31-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Element at (0, 1):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Element at (0, 1):
 2</code></pre>
</div>
</div>
<div id="a880be72" class="cell" data-execution_count="17">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb33-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zugriff auf eine Zeile</span></span>
<span id="cb33-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"First row:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>First row:
 [1 2 3]</code></pre>
</div>
</div>
<div id="fdb672a7" class="cell" data-execution_count="18">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb35-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zugriff auf eine Spalte</span></span>
<span id="cb35-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Second column:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d[:, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Second column:
 [2 5]</code></pre>
</div>
</div>
<div id="30f0c1d7" class="cell" data-execution_count="19">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb37-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Slicing eines Subarrays</span></span>
<span id="cb37-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subarray (first two rows and first two columns):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d[:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, :<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Subarray (first two rows and first two columns):
 [[1 2]
 [4 5]]</code></pre>
</div>
</div>
<div id="55fe4e91" class="cell" data-execution_count="20">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb39-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Slicing eines Submatrix</span></span>
<span id="cb39-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Submatrix (last row and last two columns):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>:])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Submatrix (last row and last two columns):
 [[5 6]]</code></pre>
</div>
</div>
<div id="e31dbf19" class="cell" data-execution_count="21">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb41-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb41-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines 1D-Arrays</span></span>
<span id="cb41-3">array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb41-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein 1D-Array:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein 1D-Array:
 [1 2 3 4 5]</code></pre>
</div>
</div>
<div id="1e24834d" class="cell" data-execution_count="22">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb43-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zugriff auf ein Element</span></span>
<span id="cb43-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Element at index 2:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Element at index 2:
 3</code></pre>
</div>
</div>
<div id="a815381f" class="cell" data-execution_count="23">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb45" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb45-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Slicing eines Subarrays</span></span>
<span id="cb45-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subarray (die ersten 3 Elemente):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d[:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Subarray (die ersten 3 Elemente):
 [1 2 3]</code></pre>
</div>
</div>
<div id="84b2db73" class="cell" data-execution_count="24">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb47" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb47-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Subarray (die Elemente an der 2. und 3. Stelle):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Subarray (die Elemente an der 2. und 3. Stelle):
 [3 4]</code></pre>
</div>
</div>
</section>
<section id="vektorisierte-operationen-auf-numpy-arrays" class="level4">
<h4 class="anchored" data-anchor-id="vektorisierte-operationen-auf-numpy-arrays">Vektorisierte Operationen auf NumPy Arrays</h4>
<div id="4f3cecd0" class="cell" data-execution_count="25">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb49" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb49-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb49-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines 1D-Arrays</span></span>
<span id="cb49-3">array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>])</span>
<span id="cb49-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein 1D-Array:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein 1D-Array:
 [1 2 3 4 5]</code></pre>
</div>
</div>
<div id="08e110c2" class="cell" data-execution_count="26">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb51" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb51-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vektorisierte Operationen</span></span>
<span id="cb51-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Array + 10:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Array + 10:
 [11 12 13 14 15]</code></pre>
</div>
</div>
<div id="125afa03" class="cell" data-execution_count="27">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb53" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb53-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Array * 2:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Array * 2:
 [ 2  4  6  8 10]</code></pre>
</div>
</div>
<div id="c959d406" class="cell" data-execution_count="28">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb55" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb55-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Array - 1:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Array - 1:
 [0 1 2 3 4]</code></pre>
</div>
</div>
<div id="30f7ca37" class="cell" data-execution_count="29">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb57" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb57-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Array / 2:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Array / 2:
 [0.5 1.  1.5 2.  2.5]</code></pre>
</div>
</div>
<div id="8d0fa6ea" class="cell" data-execution_count="30">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb59" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb59-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Wurzel aus einem Array:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, np.sqrt(array_1d))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Wurzel aus einem Array:
 [1.         1.41421356 1.73205081 2.         2.23606798]</code></pre>
</div>
</div>
<div id="8cc46432" class="cell" data-execution_count="31">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb61" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb61-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb61-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen zweier 1D-Arrays</span></span>
<span id="cb61-3">a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>])</span>
<span id="cb61-4">b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span></code></pre></div></div>
</div>
<div id="1aef1059" class="cell" data-execution_count="32">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb62" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb62-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Array a:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, a)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Array a:
 [ 1  2  3  4  5  6  7  8  9 10]</code></pre>
</div>
</div>
<div id="84a70563" class="cell" data-execution_count="33">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb64" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb64-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Array b:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, b)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Array b:
 [10  9  8  7  6  5  4  3  2  1]</code></pre>
</div>
</div>
<div id="6250b03b" class="cell" data-execution_count="34">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb66" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb66-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vektorisierte Operationen zwischen Arrays</span></span>
<span id="cb66-2">a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="34">
<pre><code>array([11, 11, 11, 11, 11, 11, 11, 11, 11, 11])</code></pre>
</div>
</div>
<div id="04c9ae4f" class="cell" data-execution_count="35">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb68" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb68-1">a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> b</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="35">
<pre><code>array([10, 18, 24, 28, 30, 30, 28, 24, 18, 10])</code></pre>
</div>
</div>
<div id="74b1fd49" class="cell" data-execution_count="36">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb70" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb70-1">a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="36">
<pre><code>array([-9, -7, -5, -3, -1,  1,  3,  5,  7,  9])</code></pre>
</div>
</div>
<div id="ff86d22c" class="cell" data-execution_count="37">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb72" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb72-1">a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> b</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="37">
<pre><code>array([ 0.1       ,  0.22222222,  0.375     ,  0.57142857,  0.83333333,
        1.2       ,  1.75      ,  2.66666667,  4.5       , 10.        ])</code></pre>
</div>
</div>
</section>
<section id="warum-ist-numpy-so-schnell" class="level4">
<h4 class="anchored" data-anchor-id="warum-ist-numpy-so-schnell">Warum ist NumPy so schnell?</h4>
<p>Intern werden optimierte C- oder Fortran-Code ausgeführt, der direkt auf die Daten im Speicher zugreift. Dies ermöglicht es NumPy, Operationen auf großen Arrays viel schneller durchzuführen als herkömmliche Python-Listen, die in einer Schleife verarbeitet werden müssen.</p>
<p>Deshalb werden im ML und DL die meisten Operationen auf NumPy Arrays ausgeführt. Dinge wie “scaling” und Matrix-Operationen werden so sehr viel schneller als im reinen Python.</p>
</section>
<section id="reshaping-umorganisieren-von-numpy-arrays" class="level4">
<h4 class="anchored" data-anchor-id="reshaping-umorganisieren-von-numpy-arrays">Reshaping (umorganisieren von NumPy Arrays)</h4>
<div id="69ae48da" class="cell" data-execution_count="38">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb74" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb74-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb74-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines 1D-Arrays mit 12 Elementen</span></span>
<span id="cb74-3">array_1d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.arange(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb74-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein 1D-Array:"</span>, array_1d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein 1D-Array: [ 1  2  3  4  5  6  7  8  9 10 11 12]</code></pre>
</div>
</div>
<div id="dd191d64" class="cell" data-execution_count="39">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb76" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb76-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reshaping in ein 2D-Array mit 3 Zeilen und 4</span></span>
<span id="cb76-2">array_2d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> array_1d.reshape(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb76-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reshaped Array (3x4):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Reshaped Array (3x4):
 [[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]]</code></pre>
</div>
</div>
<div id="6d149705" class="cell" data-execution_count="40">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb78" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb78-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reshaping in ein 2D-Array mit 4 Zeilen und 3</span></span>
<span id="cb78-2">array_2d_4x3 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> array_1d.reshape(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb78-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reshaped Array (4x3):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_2d_4x3)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Reshaped Array (4x3):
 [[ 1  2  3]
 [ 4  5  6]
 [ 7  8  9]
 [10 11 12]]</code></pre>
</div>
</div>
<div id="f627afce" class="cell" data-execution_count="41">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb80" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb80-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reshaping in ein 3D-Array mit 2 Blöcken, 2 Zeilen und 3 Spalten</span></span>
<span id="cb80-2">array_3d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> array_1d.reshape(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb80-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reshaped Array (2x2x3):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, array_3d)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Reshaped Array (2x2x3):
 [[[ 1  2  3]
  [ 4  5  6]]

 [[ 7  8  9]
  [10 11 12]]]</code></pre>
</div>
</div>
<p>Nahezu alle ML und DL modelle nutzen das Reshaping von Arrays, um die Daten in die richtige Form zu bringen, damit sie von den Modellen verarbeitet werden können. Zum Beispiel müssen Bilder oft in 4D-Arrays umgeformt werden, bevor sie in ein Convolutional Neural Network (CNN) eingespeist werden können.</p>
<p>Jedoch wird dabei niemals die Daten ansich verändert, sondern nur die Art und Weise, wie sie organisiert und interpretiert werden. Das Reshaping ermöglicht es, die Daten in einer Form zu präsentieren, die für die Verarbeitung durch ML-Modelle optimal ist, ohne die zugrunde liegenden Werte zu verändern.</p>
<p>Natürlich geht das nur, wenn die Anzahl der Elemente im ursprünglichen Array mit der Anzahl der Elemente im neuen Array übereinstimmt. Das bedeutet, dass die Gesamtzahl der Elemente vor und nach dem Reshaping gleich sein muss, damit die Daten korrekt umorganisiert werden können.</p>
<p>Das wird oft in der Praxis genutzt in der Vorverarbeitung von Daten (pre-processing), um sicherzustellen, dass die Daten die richtige Form haben, bevor sie in ein ML-Modell eingespeist werden.</p>
</section>
</section>
</section>
<section id="warum-pandas" class="level2">
<h2 class="anchored" data-anchor-id="warum-pandas">Warum Pandas?</h2>
<p>Pandas ist eine Bibliothek, die speziell für die Datenanalyse und -manipulation entwickelt wurde. Der Name leitet sich vom englischen “<strong>pan</strong>el <strong>da</strong>ta<strong>s</strong>”, eine ökonometrischen Bezeichnung für Datentabellen, ab. Hier sind einige Gründe, warum Pandas so wichtig ist:</p>
<ol type="1">
<li><p><strong>Datenstrukturen</strong>: Pandas bietet zwei Hauptdatenstrukturen, den DataFrame und die Series, die es ermöglichen, Daten in tabellarischer Form zu organisieren und zu manipulieren. Diese Strukturen sind besonders nützlich für die Arbeit mit heterogenen Daten.</p></li>
<li><p><strong>Datenmanipulation</strong>: Pandas bietet eine Vielzahl von Funktionen für die Datenmanipulation, einschließlich Filtern, Gruppieren, Pivot-Tabellen und mehr. Es ermöglicht es Benutzern, komplexe Datenoperationen mit Leichtigkeit durchzuführen.</p></li>
<li><p><strong>Datenbereinigung</strong>: Pandas bietet leistungsstarke Werkzeuge zur Bereinigung von Daten, einschließlich Funktionen zum Umgang mit fehlenden Werten, Duplikaten und Inkonstanzen in den Daten.</p></li>
<li><p><strong>Integration</strong>: Pandas lässt sich nahtlos mit anderen Bibliotheken wie NumPy, Matplotlib und Scikit-learn integrieren, was es zu einem unverzichtbaren Werkzeug für die Datenanalyse macht.</p></li>
</ol>
<p><em>Kurz:</em></p>
<p><strong>“Pandas = Tabellenkalkulation + SQL + NumPy” in Python</strong></p>
<section id="beispiel-1" class="level3">
<h3 class="anchored" data-anchor-id="beispiel-1">Beispiel</h3>
<p>NumPy ist wundervoll für mathematische Probleme, aber die Daten in der realen Welt sind oft unstrukturiert und heterogen. Hier kommt Pandas ins Spiel, um diese Daten in eine strukturierte Form zu bringen, die leichter zu analysieren ist.</p>
<p>Es gibt zwei grundlegende Datenstrukturen in Pandas: Series und DataFrame.</p>
<ul>
<li><p>Eine Series ist eine eindimensionale, beschriftete Datenstruktur, die eine Liste von Werten enthält. Sie kann als eine Art erweiterte Liste betrachtet werden, die zusätzlich zu den Werten auch Indizes hat.</p></li>
<li><p>Ein DataFrame ist eine zweidimensionale, tabellarische Datenstruktur, die aus mehreren Series besteht. Es ist vergleichbar mit einer Tabelle in einer Datenbank oder einem Arbeitsblatt in Excel, wobei Zeilen und Spalten beschriftet sind.</p></li>
</ul>
<div id="ec6ab478" class="cell" data-execution_count="42">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb82" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb82-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb82-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen einer Series</span></span>
<span id="cb82-3">my_series <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.Series([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>], index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'a'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'b'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'c'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'d'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'e'</span>])</span>
<span id="cb82-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Eine Series:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_series)</span>
<span id="cb82-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines DataFrames</span></span>
<span id="cb82-6">my_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb82-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alice'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Bob'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Charlie'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'David'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Eve'</span>],</span>
<span id="cb82-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>: [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>],</span>
<span id="cb82-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'New York'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Los Angeles'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Chicago'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Houston'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Phoenix'</span>]</span>
<span id="cb82-10">})</span>
<span id="cb82-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein DataFrame:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Eine Series:
 a    10
b    20
c    30
d    40
e    50
dtype: int64
Ein DataFrame:
       Name  Alter        Stadt
0    Alice     25     New York
1      Bob     30  Los Angeles
2  Charlie     35      Chicago
3    David     40      Houston
4      Eve     45      Phoenix</code></pre>
</div>
</div>
<section id="anschauen-der-daten-in-einem-dataframe" class="level4">
<h4 class="anchored" data-anchor-id="anschauen-der-daten-in-einem-dataframe">Anschauen der Daten in einem DataFrame</h4>
<div id="8300e42f" class="cell" data-execution_count="43">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb84" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb84-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb84-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines DataFrames</span></span>
<span id="cb84-3">my_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb84-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alice'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Bob'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Charlie'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'David'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Eve'</span>],</span>
<span id="cb84-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>: [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>],</span>
<span id="cb84-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'New York'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Los Angeles'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Chicago'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Houston'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Phoenix'</span>]</span>
<span id="cb84-7">})</span>
<span id="cb84-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein DataFrame:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe)</span>
<span id="cb84-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzeigen der ersten 3 Zeilen</span></span>
<span id="cb84-10"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Die ersten 3 Zeilen:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe.head(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb84-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzeigen der letzten 2 Zeilen</span></span>
<span id="cb84-12"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Die letzten 2 Zeilen:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe.tail(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb84-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzeigen der Spaltennamen</span></span>
<span id="cb84-14"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spaltennamen:"</span>, my_dataframe.columns)</span>
<span id="cb84-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzeigen der Datenarten jeder Spalte</span></span>
<span id="cb84-16"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Datenarten:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe.dtypes)</span>
<span id="cb84-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzeigen der Anzahl der Zeilen und Spalten</span></span>
<span id="cb84-18"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Anzahl der Zeilen und Spalten:"</span>, my_dataframe.shape)</span>
<span id="cb84-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzeigen von statistischen Zusammenfassungen der numerischen Spalten</span></span>
<span id="cb84-20"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statistische Zusammenfassung:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe.describe())</span>
<span id="cb84-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzeigen der Informationen über den DataFrame </span></span>
<span id="cb84-22"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Informationen:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe.info())</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein DataFrame:
       Name  Alter        Stadt
0    Alice     25     New York
1      Bob     30  Los Angeles
2  Charlie     35      Chicago
3    David     40      Houston
4      Eve     45      Phoenix
Die ersten 3 Zeilen:
       Name  Alter        Stadt
0    Alice     25     New York
1      Bob     30  Los Angeles
2  Charlie     35      Chicago
Die letzten 2 Zeilen:
     Name  Alter    Stadt
3  David     40  Houston
4    Eve     45  Phoenix
Spaltennamen: Index(['Name', 'Alter', 'Stadt'], dtype='str')
Datenarten:
 Name       str
Alter    int64
Stadt      str
dtype: object
Anzahl der Zeilen und Spalten: (5, 3)
Statistische Zusammenfassung:
            Alter
count   5.000000
mean   35.000000
std     7.905694
min    25.000000
25%    30.000000
50%    35.000000
75%    40.000000
max    45.000000
&lt;class 'pandas.DataFrame'&gt;
RangeIndex: 5 entries, 0 to 4
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype
---  ------  --------------  -----
 0   Name    5 non-null      str  
 1   Alter   5 non-null      int64
 2   Stadt   5 non-null      str  
dtypes: int64(1), str(2)
memory usage: 252.0 bytes
Informationen:
 None</code></pre>
</div>
</div>
</section>
</section>
<section id="datenselektierung-mit-pandas" class="level3">
<h3 class="anchored" data-anchor-id="datenselektierung-mit-pandas">Datenselektierung mit Pandas</h3>
<p>Pandas bietet verschiedene Möglichkeiten, um Daten aus einem DataFrame auszuwählen, einschließlich der Verwendung von Spaltennamen, Zeilenindizes und Bedingungen. Hier sind einige Beispiele:</p>
<div id="2790fed2" class="cell" data-execution_count="44">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb86" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb86-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb86-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines DataFrames</span></span>
<span id="cb86-3">my_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb86-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alice'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Bob'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Charlie'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'David'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Eve'</span>],</span>
<span id="cb86-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>: [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>],</span>
<span id="cb86-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'New York'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Los Angeles'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Chicago'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Houston'</span>,</span>
<span id="cb86-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Phoenix'</span>]</span>
<span id="cb86-8">})</span>
<span id="cb86-9"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein DataFrame:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe)</span>
<span id="cb86-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Auswahl einer Spalte</span></span>
<span id="cb86-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spalte 'Name':</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>])</span>
<span id="cb86-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Auswahl mehrerer Spalten</span></span>
<span id="cb86-13"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spalten 'Name' und 'Alter':</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>]])</span>
<span id="cb86-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Auswahl einer Zeile basierend auf dem Index</span></span>
<span id="cb86-15"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Zeile mit Index 2:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe.loc[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb86-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Auswahl von Zeilen basierend auf ihrer Position</span></span>
<span id="cb86-17"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Die ersten 3 Zeilen:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe.iloc[:<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])</span>
<span id="cb86-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Auswahl von Zeilen basierend auf einer Bedingung</span></span>
<span id="cb86-19"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Zeilen, in denen das Alter größer als 30 ist:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe[my_dataframe[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>])</span>
<span id="cb86-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Auswahl von Zeilen basierend auf einer Bedingung</span></span>
<span id="cb86-21"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Zeilen, in denen das Alter größer als 30 und kleiner gleich 40 ist:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe[(my_dataframe[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> (my_dataframe[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein DataFrame:
       Name  Alter        Stadt
0    Alice     25     New York
1      Bob     30  Los Angeles
2  Charlie     35      Chicago
3    David     40      Houston
4      Eve     45      Phoenix
Spalte 'Name':
 0      Alice
1        Bob
2    Charlie
3      David
4        Eve
Name: Name, dtype: str
Spalten 'Name' und 'Alter':
       Name  Alter
0    Alice     25
1      Bob     30
2  Charlie     35
3    David     40
4      Eve     45
Zeile mit Index 2:
 Name     Charlie
Alter         35
Stadt    Chicago
Name: 2, dtype: object
Die ersten 3 Zeilen:
       Name  Alter        Stadt
0    Alice     25     New York
1      Bob     30  Los Angeles
2  Charlie     35      Chicago
Zeilen, in denen das Alter größer als 30 ist:
       Name  Alter    Stadt
2  Charlie     35  Chicago
3    David     40  Houston
4      Eve     45  Phoenix
Zeilen, in denen das Alter größer als 30 und kleiner gleich 40 ist:
       Name  Alter    Stadt
2  Charlie     35  Chicago
3    David     40  Houston</code></pre>
</div>
</div>
</section>
<section id="datenmanipulation-mit-pandas" class="level3">
<h3 class="anchored" data-anchor-id="datenmanipulation-mit-pandas">Datenmanipulation mit Pandas</h3>
<p>Pandas bietet eine Vielzahl von Funktionen für die Datenmanipulation, einschließlich Filtern, Gruppieren, Pivot-Tabellen und mehr. Hier sind einige Beispiele:</p>
<div id="87b04a59" class="cell" data-execution_count="45">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb88" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb88-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb88-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines DataFrames</span></span>
<span id="cb88-3">my_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb88-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alice'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Bob'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Charlie'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'David'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Eve'</span>],</span>
<span id="cb88-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>: [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>],</span>
<span id="cb88-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'New York'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Los Angeles'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Chicago'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Houston'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Phoenix'</span>]</span>
<span id="cb88-7">})</span>
<span id="cb88-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein DataFrame:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe)</span>
<span id="cb88-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Filtern von Zeilen basierend auf einer Bedingung</span></span>
<span id="cb88-10">filtered_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> my_dataframe[my_dataframe[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>]</span>
<span id="cb88-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gefilterter DataFrame (Alter &gt; 30):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, filtered_df)</span>
<span id="cb88-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Gruppieren von Daten und Berechnen von Durchschnittsalter pro Stadt</span></span>
<span id="cb88-13">grouped_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> my_dataframe.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>)[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>].mean()</span>
<span id="cb88-14"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Durchschnittsalter pro Stadt:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, grouped_df)</span>
<span id="cb88-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen einer Pivot-Tabelle</span></span>
<span id="cb88-16">pivot_table <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> my_dataframe.pivot_table(values<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>, index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>, aggfunc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mean'</span>)</span>
<span id="cb88-17"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pivot-Tabelle (Durchschnittsalter pro Stadt):</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, pivot_table)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein DataFrame:
       Name  Alter        Stadt
0    Alice     25     New York
1      Bob     30  Los Angeles
2  Charlie     35      Chicago
3    David     40      Houston
4      Eve     45      Phoenix
Gefilterter DataFrame (Alter &gt; 30):
       Name  Alter    Stadt
2  Charlie     35  Chicago
3    David     40  Houston
4      Eve     45  Phoenix
Durchschnittsalter pro Stadt:
 Stadt
Chicago        35.0
Houston        40.0
Los Angeles    30.0
New York       25.0
Phoenix        45.0
Name: Alter, dtype: float64
Pivot-Tabelle (Durchschnittsalter pro Stadt):
              Alter
Stadt             
Chicago       35.0
Houston       40.0
Los Angeles   30.0
New York      25.0
Phoenix       45.0</code></pre>
</div>
</div>
</section>
<section id="hinzufügen-von-daten-zu-einem-dataframe" class="level3">
<h3 class="anchored" data-anchor-id="hinzufügen-von-daten-zu-einem-dataframe">Hinzufügen von Daten zu einem DataFrame</h3>
<div id="c9bb5a64" class="cell" data-execution_count="46">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb90" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb90-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb90-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Erstellen eines DataFrames</span></span>
<span id="cb90-3">my_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({</span>
<span id="cb90-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alice'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Bob'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Charlie'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'David'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Eve'</span>],</span>
<span id="cb90-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>: [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>],</span>
<span id="cb90-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>: [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'New York'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Los Angeles'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Chicago'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Houston'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Phoenix'</span>]</span>
<span id="cb90-7">})</span>
<span id="cb90-8"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ein DataFrame:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe)</span>
<span id="cb90-9"></span>
<span id="cb90-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Hinzufügen einer neuen Spalte</span></span>
<span id="cb90-11">my_dataframe[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Beruf'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Ingenieur'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Arzt'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Lehrer'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Künstler'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Anwalt'</span>]</span>
<span id="cb90-12"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DataFrame mit neuer Spalte 'Beruf':</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe)</span>
<span id="cb90-13"></span>
<span id="cb90-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Hinzufügen einer neuen Zeile</span></span>
<span id="cb90-15">new_row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.Series({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Name'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Frank'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Alter'</span>: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Stadt'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Miami'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Beruf'</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Architekt'</span>})</span>
<span id="cb90-16">my_dataframe <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.concat([my_dataframe, new_row.to_frame().T], ignore_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb90-17"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DataFrame mit neuer Zeile:</span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, my_dataframe)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Ein DataFrame:
       Name  Alter        Stadt
0    Alice     25     New York
1      Bob     30  Los Angeles
2  Charlie     35      Chicago
3    David     40      Houston
4      Eve     45      Phoenix
DataFrame mit neuer Spalte 'Beruf':
       Name  Alter        Stadt      Beruf
0    Alice     25     New York  Ingenieur
1      Bob     30  Los Angeles       Arzt
2  Charlie     35      Chicago     Lehrer
3    David     40      Houston   Künstler
4      Eve     45      Phoenix     Anwalt
DataFrame mit neuer Zeile:
       Name Alter        Stadt      Beruf
0    Alice    25     New York  Ingenieur
1      Bob    30  Los Angeles       Arzt
2  Charlie    35      Chicago     Lehrer
3    David    40      Houston   Künstler
4      Eve    45      Phoenix     Anwalt
5    Frank    50        Miami  Architekt</code></pre>
</div>
</div>
</section>
</section>
<section id="fazit" class="level2">
<h2 class="anchored" data-anchor-id="fazit">Fazit</h2>
<p>NumPy und Pandas sind zwei der wichtigsten Bibliotheken in der Python-Datenanalyse. NumPy bietet eine leistungsstarke Grundlage für die Arbeit mit Arrays und mathematischen Operationen, während Pandas speziell für die Datenmanipulation und -analyse entwickelt wurde. Beide Bibliotheken ergänzen sich hervorragend und sind unverzichtbar für jeden, der in der Welt der Datenanalyse tätig ist.</p>


</section>
</section>

 ]]></description>
  <category>Python</category>
  <category>NumPy</category>
  <category>Pandas</category>
  <guid>https://www.sefiroth.de/posts/2026-03-27-numpy-und-pandas-warum-wieso-wesshalb/</guid>
  <pubDate>Thu, 26 Mar 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Einfach ein paar gute Seite zum Thema RaspberryPi Pico</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-02-20-einfach-eine-gute-seite-zum-thema-raspberrypi/</link>
  <description><![CDATA[ 





<section id="einfach-ein-paar-gute-seite-zum-thema-raspberrypi-pico" class="level1">
<h1>Einfach ein paar gute Seite zum Thema RaspberryPi Pico</h1>
<p>Ich habe auf den Seiten von LHlab Wiki <a href="https://lhlab.wiki/wiki/Kategorie:RaspberryPiPico">hier</a> ein paar Seiten zum Thema RaspberryPi Pico gefunden die ich für recht interessant halte.</p>
<p>Für die ersten Schritte mit dem RaspberryPi Pico könnte die Seite <a href="https://www.elektronik-kompendium.de/sites/raspberry-pi/2612191.htm">https://www.elektronik-kompendium.de/sites/raspberry-pi/2612191.htm</a> sehr hilfreich sein.</p>
<p>Informationen zu den Anschlüssen des RaspberryPi Pico finden wir auf der Seite <a href="https://www.elektronik-kompendium.de/sites/raspberry-pi/2611031.htm">https://www.elektronik-kompendium.de/sites/raspberry-pi/2611031.htm</a>.</p>
<p>Eine guter Belegungsplan der GPIO Pins des RaspberryPi Pico findet sich auf der Seite <a href="https://www.elektronik-kompendium.de/sites/raspberry-pi/2611051.htm">https://www.elektronik-kompendium.de/sites/raspberry-pi/2611051.htm</a>.</p>
<p>Informationen zum Schlafmodues des RaspberryPi Pico findet sich auf der Seite <a href="https://www.elektronik-kompendium.de/sites/raspberry-pi/2802131.htm">https://www.elektronik-kompendium.de/sites/raspberry-pi/2802131.htm</a>.</p>
<section id="section" class="level2">
<h2 class="anchored" data-anchor-id="section"></h2>
<p>Unter <a href="https://raw.githubusercontent.com/alaub81/rpi_pico_scripts/main/config_sample.py">https://raw.githubusercontent.com/alaub81/rpi_pico_scripts/main/config_sample.py</a> gibt es eine Beispielkonfiguration für die Nutzung von MicroPython auf dem RaspberryPi Pico. Das könnte für Einsteiger sehr hilfreich sein, um schnell loszulegen und die ersten Schritte mit dem Pico zu machen.</p>
<p><a href="https://raw.githubusercontent.com/alaub81/rpi_pico_scripts/main/wificonnection.py">https://raw.githubusercontent.com/alaub81/rpi_pico_scripts/main/wificonnection.py</a></p>
</section>
<section id="raspberry-pi-os-download" class="level2">
<h2 class="anchored" data-anchor-id="raspberry-pi-os-download">Raspberry Pi OS download</h2>
<p><a href="https://www.raspberrypi.com/software/operating-systems/">https://www.raspberrypi.com/software/operating-systems/</a></p>


</section>
</section>

 ]]></description>
  <category>RasperryPi</category>
  <category>RaspberryPi Pico</category>
  <guid>https://www.sefiroth.de/posts/2026-02-20-einfach-eine-gute-seite-zum-thema-raspberrypi/</guid>
  <pubDate>Thu, 19 Feb 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Eine interessante trigonometrische Identität mit weitreichender Wirkung</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-02-09-eine-trigonometrisch-identitaet-mit-weitreichender-wirkung/</link>
  <description><![CDATA[ 





<section id="eine-interessante-trigonometrische-identität-mit-weitreichender-wirkung" class="level1">
<h1>Eine interessante trigonometrische Identität mit weitreichender Wirkung</h1>
<p>Die folgende trigonometrische Identität ist nicht nur eine mathematische Kuriosität, sondern hat auch weitreichende Auswirkungen in verschiedenen Bereichen der Mathematik und Physik:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20a%20%5Csin(x)%20+%20b%20%5Ccos(x)%20=%20%5Csqrt%7Ba%5E2%20+%20b%5E2%7D%20%5Ccdot%20%5Csin%5Cleft(x%20+%20%5Carctan%5Cleft(%5Cfrac%7Bb%7D%7Ba%7D%5Cright)%5Cright)%0A"></p>
<p>Diese Identität zeigt, dass eine lineare Kombination von Sinus- und Kosinusfunktionen in eine einzelne Sinusfunktion umgewandelt werden kann, die um einen bestimmten Winkel verschoben ist. Hier sind einige wichtige Punkte zu dieser Identität:</p>
<ol type="1">
<li><p><strong>Vereinfachung von Ausdrücken</strong>: Diese Identität ermöglicht es, komplexe trigonometrische Ausdrücke zu vereinfachen, indem sie in eine einzige Sinusfunktion umgewandelt werden.</p></li>
<li><p><strong>Anwendungen in der Physik</strong>: In der Physik, insbesondere in der Schwingungslehre und der Signalverarbeitung, wird diese Identität verwendet, um die Amplitude und Phase von Schwingungen zu bestimmen.</p></li>
<li><p><strong>Lösung von Gleichungen</strong>: Diese Identität kann auch bei der Lösung von trigonometrischen Gleichungen helfen, indem sie die Anzahl der Terme reduziert und die Gleichung leichter lösbar macht.</p></li>
<li><p><strong>Fourier-Analyse</strong>: In der Fourier-Analyse wird diese Identität verwendet, um die Fourier-Koeffizienten zu berechnen und die Frequenz und Phase von Signalen zu bestimmen.</p></li>
<li><p><strong>Laplace-Transformation</strong>: In der Laplace-Transformation wird diese Identität verwendet, um die Transformation von Funktionen zu vereinfachen und die Berechnung von Inversen zu erleichtern.</p></li>
</ol>
<p>Insgesamt ist diese trigonometrische Identität ein mächtiges Werkzeug, das in vielen Bereichen der Mathematik und Physik Anwendung findet und dazu beiträgt, komplexe Probleme zu lösen und das Verständnis von Schwingungen und Signalen zu vertiefen.</p>
<p>Schauen wir uns einmal die reale Fourier-Transformation an, um zu sehen, wie diese Identität in der Praxis angewendet wird. Die Fourier-Transformation eines Signals <img src="https://latex.codecogs.com/png.latex?f(t)"> ist definiert als: <img src="https://latex.codecogs.com/png.latex?%0AF(%5Comega)%20=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f(t)%20e%5E%7B-i%20%5Comega%20t%7D%20dt%0A"> Wenn wir das Signal <img src="https://latex.codecogs.com/png.latex?f(t)"> als eine lineare Kombination von Sinus- und Kosinusfunktionen darstellen, können wir die obige Identität verwenden, um die Fourier-Koeffizienten zu berechnen und die Frequenz und Phase des Signals zu bestimmen. Dies ist besonders nützlich in der Signalverarbeitung, wo es wichtig ist, die Eigenschaften von Signalen zu analysieren und zu verstehen.</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20F(%5Comega)%20=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20(a%20%5Csin(t)%20+%20b%20%5Ccos(t))%20e%5E%7B-i%20%5Comega%20t%7D%20dt%0A"></p>
<p>Durch die Anwendung der Identität können wir diesen Ausdruck vereinfachen und die Fourier-Koeffizienten berechnen, was uns wichtige Informationen über das Signal liefert, wie z.B. seine Frequenzkomponenten und Phasenverschiebungen. Dies zeigt, wie eine scheinbar einfache trigonometrische Identität in der Praxis eine wichtige Rolle spielt und weitreichende Auswirkungen hat.</p>
<p>Die Fourier-Reihenentwicklung eines Signals <img src="https://latex.codecogs.com/png.latex?f(t)"> kann auch durch die Anwendung dieser Identität vereinfacht werden. Wenn wir das Signal als eine Summe von Sinus- und Kosinusfunktionen darstellen, können wir die Identität verwenden, um die Koeffizienten der Fourier-Reihe zu berechnen und die Frequenz und Phase der einzelnen Komponenten zu bestimmen. Dies ist besonders nützlich in der Analyse von periodischen Signalen, wo es wichtig ist, die Eigenschaften der einzelnen Frequenzkomponenten zu verstehen.</p>
<p><img src="https://latex.codecogs.com/png.latex?%20%20%0A%20%20f(t)%20=%20%5Cfrac%7Ba_0%7D%7B2%7D%20+%20%5Csum_%7Bn=1%7D%5E%7B%5Cinfty%7D%20(a_n%20%5Ccos(nt)%20+%20b_n%20%5Csin(nt))%20%20%0A"></p>
<p>Durch die Anwendung der Identität können wir die Koeffizienten <img src="https://latex.codecogs.com/png.latex?a_n"> und <img src="https://latex.codecogs.com/png.latex?b_n"> berechnen und die Frequenz und Phase der einzelnen Komponenten der Fourier-Reihe bestimmen, was uns wichtige Informationen über das Signal liefert. Dies zeigt, wie eine einfache trigonometrische Identität in der Praxis eine wichtige Rolle spielt und weitreichende Auswirkungen hat.</p>
<p>Wir können die Fourier-Reihe nun nur mit Sinus (oder nur mit Kosinus) schreiben: <img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cbegin%7Balign*%7D%0A%20%20f(t)%20&amp;=%20%5Cfrac%7Ba_0%7D%7B2%7D%20+%20%5Csum_%7Bn=1%7D%5E%7B%5Cinfty%7D%20%5Csqrt%7Ba_n%5E2%20+%20b_n%5E2%7D%20%5Ccdot%20%5Csin%5Cleft(nt%20+%20%5Carctan%5Cleft(%5Cfrac%7Bb_n%7D%7Ba_n%7D%5Cright)%5Cright)%20%5C%5C%0A%20%20%20%20%20%20&amp;=%20%5Cfrac%7Ba_0%7D%7B2%7D%20+%20%5Csum_%7Bn=1%7D%5E%7B%5Cinfty%7D%20%5Csqrt%7Ba_n%5E2%20+%20b_n%5E2%7D%20%5Ccdot%20%5Ccos%5Cleft(nt%20-%20%5Carctan%5Cleft(%5Cfrac%7Bb_n%7D%7Ba_n%7D%5Cright)%5Cright)%0A%20%20%5Cend%7Balign*%7D%0A"> Setzen wir <img src="https://latex.codecogs.com/png.latex?A_n%20=%20%5Csqrt%7Ba_n%5E2%20+%20b_n%5E2%7D"> und <img src="https://latex.codecogs.com/png.latex?%5Cphi_n%20=%20%5Carctan%5Cleft(%5Cfrac%7Bb_n%7D%7Ba_n%7D%5Cright)">, so können wir die Fourier-Reihe in der folgenden Form schreiben: <img src="https://latex.codecogs.com/png.latex?%20%20%0A%20%20f(t)%20=%20%5Cfrac%7Ba_0%7D%7B2%7D%20+%20%5Csum_%7Bn=1%7D%5E%7B%5Cinfty%7D%20A_n%20%5Ccdot%20%5Csin(nt%20+%20%5Cphi_n)%0A"></p>
<p>oder <img src="https://latex.codecogs.com/png.latex?%0A%20%20f(t)%20=%20%5Cfrac%7Ba_0%7D%7B2%7D%20+%20%5Csum_%7Bn=1%7D%5E%7B%5Cinfty%7D%20A_n%20%5Ccdot%20%5Ccos(nt%20-%20%5Cphi_n)%0A"> Diese Form der Fourier-Reihe zeigt, dass jedes Signal als eine Summe von Sinus- oder Kosinusfunktionen dargestellt werden kann, wobei die Amplitude <img src="https://latex.codecogs.com/png.latex?A_n"> und die Phase <img src="https://latex.codecogs.com/png.latex?%5Cphi_n"> der einzelnen Komponenten durch die Koeffizienten der ursprünglichen Fourier-Reihe bestimmt werden. Dies ist ein weiteres Beispiel dafür, wie eine einfache trigonometrische Identität in der Praxis eine wichtige Rolle spielt und weitreichende Auswirkungen hat.</p>


</section>

 ]]></description>
  <category>Laplace</category>
  <category>Mathematik</category>
  <guid>https://www.sefiroth.de/posts/2026-02-09-eine-trigonometrisch-identitaet-mit-weitreichender-wirkung/</guid>
  <pubDate>Sun, 08 Feb 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Wie mensch manchmal ohne de L’Hospital auskommt</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-02-05-wie-mensch-manchmal-ohne-de-lhospital-auskommt/</link>
  <description><![CDATA[ 





<section id="wie-mensch-manchmal-ohne-de-lhospital-auskommt" class="level1">
<h1>Wie mensch manchmal ohne de L’Hospital auskommt</h1>
<p>Brauchen wir um das folgende Problem zu lösen immer die Regel von de L’Hospital?</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Clim%5Climits_%7Bx%20%5Cto%201%7D%20%5Cfrac%7Bx%5E%7B%5Cfrac%7B1%7D%7B3%7D%7D-1%7D%7Bx%5E%7B%5Cfrac%7B1%7D%7B2%7D%7D-1%7D%0A"></p>
<p>Die Antwort ist ganz klar: <strong>Nein</strong>.</p>
<p>Manchmal, so wie in diesem Fall, reicht eine geschickte Substitution.</p>
<p>Ersetzen wir nämlich <img src="https://latex.codecogs.com/png.latex?x%5E%7B%5Cfrac%7B1%7D%7B6%7D%7D"> durch <img src="https://latex.codecogs.com/png.latex?t">, so beobachten wir: <img src="https://latex.codecogs.com/png.latex?%0A%20%20t%5E2%20=%20%5Cleft(x%5E%7B%5Cfrac%7B1%7D%7B6%7D%7D%5Cright)%5E2%0A%20%20%20%20%20%20=%20x%5E%7B%5Cfrac%7B1%7D%7B3%7D%7D%0A%20%20%5Cquad%20%5Ctext%7Bbzw.%7D%20%5Cquad%0A%20%20t%5E3%20=%20%5Cleft(x%5E%7B%5Cfrac%7B1%7D%7B6%7D%7D%5Cright)%5E3%0A%20%20%20%20%20%20=%20x%5E%7B%5Cfrac%7B1%7D%7B2%7D%7D%0A"></p>
<p>Ersetzen wir das nun in unserer Ursprünglichen Aufgabe so erhalten wir:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Clim%5Climits_%7Bt%20%5Cto%201%7D%20%5Cfrac%7Bt%5E2-1%7D%7Bt%5E3-1%7D%0A"> Sowohl der Zähler, als auch der Nenner lassen sich nun wie folgt umformulieren: <img src="https://latex.codecogs.com/png.latex?%0A%20%20t%5E2%20-%201%20=%20(t-1)%20(t+1)%0A"> <img src="https://latex.codecogs.com/png.latex?%0A%20%20t%5E3%20-%201%20=%20(t-1)%5Cleft(t%5E2+t+1%5Cright)%0A"></p>
<p>Der Bruch lässt sich somit umformen zu:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cfrac%7Bt%5E2-1%7D%7Bt%5E3-1%7D%20=%20%5Cfrac%7B(t-1)(t+1)%7D%7B(t-1)%5Cleft(t%5E2+t+1%5Cright)%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20=%20%5Cfrac%7Bt+1%7D%7Bt%5E2+t+1%7D%0A"> Und in die rechte Seite können wir <img src="https://latex.codecogs.com/png.latex?t=1"> ohne Probleme einsetzen und erhalten:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%20%5Clim%5Climits_%7Bx%20%5Cto%201%7D%20%5Cfrac%7Bx%5E%7B%5Cfrac%7B1%7D%7B3%7D%7D-1%7D%7Bx%5E%7B%5Cfrac%7B1%7D%7B2%7D%7D-1%7D%0A=%20%5Clim%5Climits_%7Bt%20%5Cto%201%7D%20%5Cfrac%7Bt%5E2-1%7D%7Bt%5E3-1%7D%0A=%20%5Clim%5Climits_%7Bt%20%5Cto%201%7D%20%5Cfrac%7Bt+1%7D%7Bt%5E2+t+1%7D%0A=%20%5Cfrac%7B1+1%7D%7B1%5E2+1+1%7D%0A=%20%5Cfrac%7B2%7D%7B3%7D%0A"></p>
<p>Die Idee ist klar. Da die Laufvariable gegen eine Nullstelle von Zähler und Nenner geht, müssen wir diese Nullstelle oben wie unten auskammern und wegkürzen. Um das zu erreichen muss unsere Substitution passen.</p>
<p>Im Hinterkopf haben wir dabei die Binomischen Formeln, insbesondere die 3. Binomische Formel: <img src="https://latex.codecogs.com/png.latex?%0A%20%20x%5E2-y%5E2%20=%20(x-y)(x+y)%0A"> Wir nutzen hier aber auch die Verallgemeinerung dieser Formel: <img src="https://latex.codecogs.com/png.latex?%0A%20%20x%5E3-y%5E3%20=%20(x-y)%5Cleft(x%5E2+xy+y%5E2%5Cright)%0A%20%20%5Cquad%5Ctext%7B%20und%20%7D%5Cquad%0A%20%20x%5E4-y%5E4%20=%20(x-y)%5Cleft(x%5E3+x%5E2y+xy%5E2+y%5E3%5Cright)%0A"> Oder für noch größere Exponenten: <img src="https://latex.codecogs.com/png.latex?%0A%20%20x%5En-y%5En%20=%20(x-y)%20%5Ccdot%5Cleft(%5Csum%5Climits_%7Bk=0%7D%5E%7Bn-1%7Dx%5Eky%5E%7Bn-k%7D%5Cright)%0A"></p>


</section>

 ]]></description>
  <category>de L&#39;Hospital</category>
  <category>Binomische Formeln</category>
  <category>Mathematik</category>
  <guid>https://www.sefiroth.de/posts/2026-02-05-wie-mensch-manchmal-ohne-de-lhospital-auskommt/</guid>
  <pubDate>Wed, 04 Feb 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Ein Überblick über gängige Aktivierungsfunktionen</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-05-02-ueberblick-ueber-aktikierungsfunktionen/</link>
  <description><![CDATA[ 





<section id="aktivierungsfunktionen" class="level1">
<h1>Aktivierungsfunktionen</h1>
<p>Beim Aufbau der neuronalen Netzwerke werden Aktivierungsfunktionen eingesetzt, um die Ausgabe der Neuronen zu steuern.</p>
<p>Dabei werden Aktivierungsfunktionen verwendet, um nichtlineare Beziehungen in den Daten zu erfassen.</p>
<p>Die Eingänge eines Neutron werden dabei über die Aktivierungsfunktion mit dem Ausgang verknüpft. Die Aktivierungsfunktion steuert dabei, wie sehr das Neuron aktiviert wird, das heißt, wie stark (bzw. ob überhaupt) Werte weitergeleitet werden.</p>
<p>Die bekanntesten Aktivierungsfunktionen sind:</p>
<ul>
<li><p>ReLU - <strong>Re</strong>ctified <strong>L</strong>inear <strong>U</strong>nit</p></li>
<li><p>Leaky ReLU - Leaky <strong>Re</strong>ctified <strong>L</strong>inear <strong>U</strong>nit</p></li>
<li><p>Tanh - Tangenz Hyperbolicus</p></li>
<li><p>Sigmoid - Logistische Funktion</p></li>
</ul>
<!--
- Softmax
-->
<p>Schauen wir uns diese Funktionen einmal kurz an.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">show_function <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(fkt) {</span>
<span id="cb1-2">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb1-3">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fkt</span>(x)</span>
<span id="cb1-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(x, y)</span>
<span id="cb1-5">}</span></code></pre></div></div>
</div>
<section id="relu---rectified-linear-unit" class="level2">
<h2 class="anchored" data-anchor-id="relu---rectified-linear-unit">ReLU - <strong>Re</strong>ctified <strong>L</strong>inear <strong>U</strong>nit</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">relu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb2-3">}</span>
<span id="cb2-4"></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">show_function</span>(relu)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-02-ueberblick-ueber-aktikierungsfunktionen/index_files/figure-html/unnamed-chunk-2-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="leaky-relu-leaky-rectified-linear-unit" class="level2">
<h2 class="anchored" data-anchor-id="leaky-relu-leaky-rectified-linear-unit">Leaky ReLU / Leaky <strong>Re</strong>ctified <strong>L</strong>inear <strong>U</strong>nit</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">leakyrelu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>) {</span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(x, alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x)</span>
<span id="cb3-3">}</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">show_function</span>(leakyrelu)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-02-ueberblick-ueber-aktikierungsfunktionen/index_files/figure-html/unnamed-chunk-3-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="tanh---tangenz-hyperbolicus" class="level2">
<h2 class="anchored" data-anchor-id="tanh---tangenz-hyperbolicus">Tanh - Tangenz Hyperbolicus</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">tanh <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb4-2">  p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(x)</span>
<span id="cb4-3">  n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>p         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># = exp(-x)</span></span>
<span id="cb4-4">  (p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>n)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>p)</span>
<span id="cb4-5">}</span>
<span id="cb4-6"></span>
<span id="cb4-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">show_function</span>(tanh)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-02-ueberblick-ueber-aktikierungsfunktionen/index_files/figure-html/unnamed-chunk-4-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="sigmoid---logistische-funktion" class="level2">
<h2 class="anchored" data-anchor-id="sigmoid---logistische-funktion">Sigmoid - Logistische Funktion</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">sigmonid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb5-2">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x))</span>
<span id="cb5-3">}</span>
<span id="cb5-4"></span>
<span id="cb5-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">show_function</span>(sigmonid)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-05-02-ueberblick-ueber-aktikierungsfunktionen/index_files/figure-html/unnamed-chunk-5-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<!--
## Softmax


::: {.cell}

```{.r .cell-code}
softmax <- function(x,i) {
  n <- sum(exp(x))
  pmax(x, 0)
}

show_function(relu)
```

::: {.cell-output-display}
![](index_files/figure-html/unnamed-chunk-6-1.png){width=672}
:::
:::


-->


</section>
</section>

 ]]></description>
  <category>KI</category>
  <category>Aktivierungsfunktion</category>
  <category>ReLU</category>
  <category>Sigmonide</category>
  <category>LeakyReLU</category>
  <category>softmax</category>
  <category>Mathematik</category>
  <guid>https://www.sefiroth.de/posts/2026-05-02-ueberblick-ueber-aktikierungsfunktionen/</guid>
  <pubDate>Wed, 04 Feb 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Warum Exponentiation und Logarithmen in der Statistik wichtig sind.</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/</link>
  <description><![CDATA[ 





<section id="warum-exponentiation-und-logarithmen-in-der-statistik-wichtig-sind" class="level1">
<h1>Warum Exponentiation und Logarithmen in der Statistik wichtig sind</h1>
<p>Die Exponentiation und der Logarithmus sind wichtig in der Statistik, weil sie helfen, komplexe Zusammenhänge zu verstehen und zu modellieren. Hier sind einige Gründe, warum sie so wichtig sind:</p>
<ol type="1">
<li><p><strong>Daten Transformation</strong>: Viele statistische Modelle setzen voraus, dass die Daten normalverteilt sind. Durch die Anwendung von Logarithmen können schiefe Verteilungen in eine normalverteilte Form transformiert werden, was die Analyse erleichtert.</p></li>
<li><p><strong>Multiplikative Beziehungen</strong>: In vielen Fällen sind die Beziehungen zwischen Variablen multiplikativ statt additiv. Logarithmen ermöglichen es, diese Beziehungen in eine additive Form zu überführen, was die Interpretation und Modellierung vereinfacht.</p></li>
<li><p><strong>Wachstumsprozesse</strong>: Exponentielle Funktionen werden häufig verwendet, um Wachstumsprozesse zu modellieren, wie z.B. Bevölkerungswachstum oder Zinseszinsen. Logarithmen helfen dabei, diese Prozesse zu analysieren und zu verstehen.</p></li>
<li><p><strong>Linearisierung</strong>: Viele nicht-lineare Modelle können durch die Anwendung von Logarithmen linearisiert werden, was die Anwendung von linearen Regressionsmethoden ermöglicht.</p></li>
<li><p><strong>Skalierung</strong>: Logarithmische Skalen werden oft verwendet, um Daten darzustellen, die über mehrere Größenordnungen variieren, wie z.B. in der Finanzanalyse oder bei Messungen von Erdbebenstärken. Insgesamt sind Exponentiation und Logarithmen unverzichtbare Werkzeuge in der Statistik, die helfen, Daten zu transformieren, Beziehungen zu modellieren und komplexe Phänomene zu verstehen.</p></li>
</ol>
<section id="datentransformation-und-linearisierung-mit-exponentiation-und-logarithmes" class="level2">
<h2 class="anchored" data-anchor-id="datentransformation-und-linearisierung-mit-exponentiation-und-logarithmes">Datentransformation und Linearisierung mit Exponentiation und Logarithmes</h2>
<section id="beispiel-1-daten-transformation-mit-logarithmen" class="level3">
<h3 class="anchored" data-anchor-id="beispiel-1-daten-transformation-mit-logarithmen">Beispiel 1 – Daten Transformation mit Logarithmen</h3>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false" href="">Python</a></li></ul>
<div class="tab-content">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Beispiel in R: Log-Transformation einer schiefen Verteilung</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb1-5">data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rexp</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Exponentielle Verteilung</span></span>
<span id="cb1-6">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> data)</span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightblue"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Original Data"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Value"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-1-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">df_log <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(data))  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log-Transformation</span></span>
<span id="cb2-2"></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_log) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgreen"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log-Transformed Data"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log(Value)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-1-2.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb3-3"></span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Beispiel in Python: Log-Transformation einer schiefen Verteilung</span></span>
<span id="cb3-5"></span>
<span id="cb3-6">np.random.seed(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb3-7"></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Exponentielle Verteilung</span></span>
<span id="cb3-9">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.exponential(scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb3-10">plt.hist(data, bins<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'lightblue'</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb3-11">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Original Data'</span>)</span>
<span id="cb3-12">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Value'</span>)</span>
<span id="cb3-13">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-2-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">plt.clf()</span>
<span id="cb4-2"></span>
<span id="cb4-3">log_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(data)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log-Transformation</span></span>
<span id="cb4-4">plt.hist(log_data, bins<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'lightgreen'</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb4-5">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log-Transformed Data'</span>)</span>
<span id="cb4-6">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log(Value)'</span>)</span>
<span id="cb4-7">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-2-2.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"></span>
<span id="cb5-2">plt.clf()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-2-3.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
<section id="beispiel-2-linearisierung-mit-logarithmen" class="level2">
<h2 class="anchored" data-anchor-id="beispiel-2-linearisierung-mit-logarithmen">Beispiel 2 – Linearisierung mit Logarithmen</h2>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-2-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-1" aria-controls="tabset-2-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-2-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-2" aria-controls="tabset-2-2" aria-selected="false" href="">Python</a></li></ul>
<div class="tab-content">
<div id="tabset-2-1" class="tab-pane active" aria-labelledby="tabset-2-1-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb6-2"></span>
<span id="cb6-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Beispiel in R: Linearisierung einer exponentiellen Beziehung</span></span>
<span id="cb6-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb6-5"></span>
<span id="cb6-6">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb6-7">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),</span>
<span id="cb6-8">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Exponentielle Beziehung mit Rauschen</span></span>
<span id="cb6-9">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)</span>
<span id="cb6-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Exponentielle Beziehung"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-3-7.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">log_y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(y)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log-Transformation von Y</span></span>
<span id="cb7-2">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> log_y)</span>
<span id="cb7-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Linearisierte Beziehung"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log(Y)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-3-8.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-2-2" class="tab-pane" aria-labelledby="tabset-2-2-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb8-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb8-3"></span>
<span id="cb8-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Beispiel in Python: Linearisierung einer exponentiellen Beziehung</span></span>
<span id="cb8-5">np.random.seed(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb8-6"></span>
<span id="cb8-7">x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.arange(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb8-8">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> np.exp(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> np.random.normal(</span>
<span id="cb8-9">    <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(x) </span>
<span id="cb8-10">    )</span>
<span id="cb8-11">plt.scatter(x, y, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>)</span>
<span id="cb8-12">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Exponentielle Beziehung'</span>)</span>
<span id="cb8-13">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'X'</span>)</span>
<span id="cb8-14">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Y'</span>)</span>
<span id="cb8-15">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-4-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1">plt.clf()</span>
<span id="cb9-2"></span>
<span id="cb9-3">log_y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(y)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log-Transformation von Y</span></span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>&lt;string&gt;:2: RuntimeWarning: invalid value encountered in log</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">plt.scatter(x, log_y, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb11-2">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Linearisierte Beziehung'</span>)</span>
<span id="cb11-3">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'X'</span>)</span>
<span id="cb11-4">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log(Y)'</span>)</span>
<span id="cb11-5">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-4-2.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"></span>
<span id="cb12-2">plt.clf()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-4-3.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="multiplikative-beziehungen" class="level2">
<h2 class="anchored" data-anchor-id="multiplikative-beziehungen">Multiplikative Beziehungen</h2>
<p>Logarithmen sind besonders nützlich, um multiplikative Beziehungen zwischen Variablen zu modellieren. Wenn die Beziehung zwischen zwei Variablen durch eine Multiplikation beschrieben wird, kann die Anwendung des Logarithmus diese Beziehung in eine additive Form überführen, was die Analyse und Interpretation erleichtert. <img src="https://latex.codecogs.com/png.latex?%0A%20%20y%20=%20a%20%5Ccdot%20x_1%5E%7Bb_1%7D%20%5Ccdot%20x_2%5E%7Bb_2%7D%20%5Ccdots%20x_n%5E%7Bb_n%7D%0A"> Durch die Anwendung des Logarithmus auf beide Seiten der Gleichung erhalten wir: <img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Clog(y)%20=%20%5Clog(a)%20+%20b_1%20%5Ccdot%20%5Clog(x_1)%20+%20b_2%20%5Ccdot%20%5Clog(x_2)%20+%0A%20%20%20%20%20%20%20%20%20%20%20%20%5Ccdots%20+%20b_n%20%5Ccdot%20%5Clog(x_n)%0A"> Diese Transformation ermöglicht es, die multiplikative Beziehung als lineare Kombination der logarithmierten Variablen darzustellen, was die Anwendung von linearen Regressionsmethoden erleichtert.</p>
<p>In der Statistik und Datenanalyse wird diese Technik häufig verwendet, um Modelle zu erstellen, die besser zu den Daten passen und leichter zu interpretieren sind.</p>
<p>Zum Beispiel bei der log-likelihood-Funktion in der Maximum-Likelihood-Schätzung oder bei der Analyse von Wachstumsprozessen, bei denen die Wachstumsraten oft als multiplikative Effekte modelliert werden.</p>
<p>Wenn Statisiker log-likelihood-Funktionen verwenden, dann u.a. aus diesen Gründen:</p>
<p><strong>Monotonie:</strong> Logarithmen sind streng monoton wachsend, was bedeutet, dass die Maximierung der log-likelihood-Funktion äquivalent zur Maximierung der ursprünglichen likelihood-Funktion ist. Dies erleichtert die Optimierung erheblich.</p>
<p><strong>Produkte wandeln sich zu Summen:</strong> Für unabhängige Beobachtungen gilt</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20L(%5Ctheta)%20=%20%5Cprod_%7Bi=1%7D%5E%7Bn%7D%20f(x_i%20%5Cmid%20%5Ctheta),%0A"></p>
<p>welche mit dem Logarithmus zu</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Clog%20L(%5Ctheta)%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20%5Clog%20f(x_i%20%5Cmid%20%5Ctheta)%0A"> wird.</p>
<p>Dies vereinfacht die Berechnungen und reduziert numerische Instabilitäten, die bei der Arbeit mit sehr kleinen Wahrscheinlichkeiten auftreten können.</p>
<p><strong>Anti-Symmetrie:</strong> Beim vergleich zweier Modelle <img src="https://latex.codecogs.com/png.latex?M_1"> und <img src="https://latex.codecogs.com/png.latex?M_2"> mit Likelihoods <img src="https://latex.codecogs.com/png.latex?L_1"> und <img src="https://latex.codecogs.com/png.latex?L_2"> ist der Log-Likelihood-Ratio</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%20%20%5Clog%5Cleft(%5Cfrac%7BL_1%7D%7BL_2%7D%5Cright)%20&amp;=%20%5Clog(L_1)%20-%20%5Clog(L_2)%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;=%20-%20%5Clog(L_2)%20+%20%5Clog(L_1)%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;=%20-%5Cleft(%5Clog(L_2)%20-%20%5Clog(L_1)%5Cright)%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;=%20-%20%5Clog%5Cleft(%5Cfrac%7BL_2%7D%7BL_1%7D%5Cright).%0A%5Cend%7Baligned%7D%0A"></p>
<p>Das bedeutet, dass der Log-Likelihood-Ratio anti-symmetrisch ist, was bei der Interpretation von Modellen hilfreich sein kann.</p>
<p>So ist die Evidenz für Modell <img src="https://latex.codecogs.com/png.latex?M_1"> gegenüber Modell <img src="https://latex.codecogs.com/png.latex?M_2"> genau das negative der Evidenz für Modell <img src="https://latex.codecogs.com/png.latex?M_2"> gegenüber Modell <img src="https://latex.codecogs.com/png.latex?M_1">.</p>
<section id="beispiel-3-multiplikative-beziehungen-mit-logarithmen" class="level3">
<h3 class="anchored" data-anchor-id="beispiel-3-multiplikative-beziehungen-mit-logarithmen">Beispiel 3 – Multiplikative Beziehungen mit Logarithmen</h3>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-3-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-1" aria-controls="tabset-3-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-3-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-2" aria-controls="tabset-3-2" aria-selected="false" href="">Python</a></li></ul>
<div class="tab-content">
<div id="tabset-3-1" class="tab-pane active" aria-labelledby="tabset-3-1-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb13-2"></span>
<span id="cb13-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Beispiel in R: Multiplikative Beziehung</span></span>
<span id="cb13-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb13-5">x1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb13-6">x2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb13-7">y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb13-8">                 , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Multiplikative Beziehung mit Rauschen</span></span>
<span id="cb13-9">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> x1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x2 =</span> x2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)</span>
<span id="cb13-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Multiplikative Beziehung"</span>, </span>
<span id="cb13-13">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X1"</span>, </span>
<span id="cb13-14">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-5-7.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">log_y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(y)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log-Transformation von Y</span></span>
<span id="cb14-2">log_x1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(x1)</span>
<span id="cb14-3">log_x2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(x2)</span>
<span id="cb14-4">df_log <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> log_x1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x2 =</span> log_x2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> log_y)</span>
<span id="cb14-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_log) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Additive Beziehung nach Log-Transformation"</span>, </span>
<span id="cb14-8">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log(X1)"</span>, </span>
<span id="cb14-9">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log(Y)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-5-8.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-3-2" class="tab-pane" aria-labelledby="tabset-3-2-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb15-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb15-3"></span>
<span id="cb15-4">np.random.seed(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)</span>
<span id="cb15-5">x1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.uniform(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb15-6">x2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.uniform(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb15-7"></span>
<span id="cb15-8">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> np.random.normal(</span>
<span id="cb15-9">    <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Multiplikative Beziehung mit Rauschen</span></span>
<span id="cb15-10">    </span>
<span id="cb15-11">plt.scatter(x1, y, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'blue'</span>)</span>
<span id="cb15-12">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Multiplikative Beziehung'</span>)</span>
<span id="cb15-13">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'X1'</span>)</span>
<span id="cb15-14">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Y'</span>)</span>
<span id="cb15-15">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-6-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb16-1">plt.clf()</span>
<span id="cb16-2">log_y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(y)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log-Transformation von Y</span></span>
<span id="cb16-3">log_x1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(x1)</span>
<span id="cb16-4">log_x2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(x2)</span>
<span id="cb16-5">plt.scatter(log_x1, log_y, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'red'</span>)</span>
<span id="cb16-6">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Additive Beziehung nach Log-Transformation'</span>)</span>
<span id="cb16-7">plt.xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log(X1)'</span>)</span>
<span id="cb16-8">plt.ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Log(Y)'</span>)</span>
<span id="cb16-9">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-6-2.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1">plt.clf()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/index_files/figure-html/unnamed-chunk-6-3.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
<section id="fazit" class="level2">
<h2 class="anchored" data-anchor-id="fazit">Fazit</h2>
<p>Exponentiation und Logarithmen sind mächtige Werkzeuge in der Statistik, die es ermöglichen, Daten zu transformieren, Beziehungen zu modellieren und komplexe Phänomene zu verstehen. Durch die Anwendung dieser mathematischen Konzepte können Statistiker und Datenwissenschaftler tiefere Einblicke in ihre Daten gewinnen und präzisere Modelle erstellen.</p>


</section>
</section>

 ]]></description>
  <category>Statistik</category>
  <category>Logarithmen</category>
  <category>Exponentiation</category>
  <category>Likelihood</category>
  <category>Log-Likelihood</category>
  <guid>https://www.sefiroth.de/posts/2026-02-04-warum-exponentiation-und-logarithmen-wichtig-sind-in-der-statistik/</guid>
  <pubDate>Tue, 03 Feb 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>kitty: Der schnelle, feature-reiche, GPU-basierte Terminal-Emulator</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-01-30-kitty-der_schnelle_gpu_basierte_terminal_emulator/</link>
  <description><![CDATA[ 





<section id="einführung" class="level2">
<h2 class="anchored" data-anchor-id="einführung">Einführung</h2>
<p>In der Welt der Terminal-Emulatoren gibt es viele Optionen, aber nur wenige bieten die Kombination aus Geschwindigkeit, Funktionsreichtum und moderner Technologie wie <strong>kitty</strong>.</p>
</section>
<section id="was-ist-kitty" class="level2">
<h2 class="anchored" data-anchor-id="was-ist-kitty">Was ist kitty?</h2>
<p>Kitty ist ein moderner, GPU-basierter Terminal-Emulator, der auf Leistung und Benutzerfreundlichkeit ausgelegt ist. Es nutzt die Grafikprozessoren (GPUs) moderner Computer, um eine flüssige und schnelle Darstellung von Text und Grafiken zu gewährleisten. Dies macht kitty besonders geeignet für Entwickler, die viel Zeit im Terminal verbringen.</p>
</section>
<section id="installation" class="level2">
<h2 class="anchored" data-anchor-id="installation">Installation</h2>
<p>Die Installation von kitty ist einfach und kann auf verschiedenen Betriebssystemen durchgeführt werden. Hier sind die grundlegenden Schritte für die Installation auf Linux und macOS:</p>
<p><strong>Linux/macOS</strong>: - Laden Sie das Installationsskript herunter und führen Sie es aus:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"> <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">curl</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-L</span> https://sw.kovidgoyal.net/kitty/installer.sh <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sh</span> /dev/stdin</span></code></pre></div></div>
<ul>
<li>Fügen Sie kitty zu Ihrem PATH hinzu, indem Sie die folgende Zeile zu Ihrer <code>.bashrc</code> oder <code>.zshrc</code> hinzufügen:</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">export</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">PATH</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$HOME</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/.local/kitty/bin:</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$PATH</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</section>
<section id="hauptmerkmale-von-kitty" class="level2">
<h2 class="anchored" data-anchor-id="hauptmerkmale-von-kitty">Hauptmerkmale von kitty</h2>
<p>Kitty bietet eine Vielzahl von Funktionen, die es von anderen Terminal-Emulatoren abheben:</p>
<ol type="1">
<li><p><strong>GPU-Beschleunigung</strong>: Durch die Nutzung der GPU für die Textdarstellung bietet kitty eine außergewöhnliche Leistung, insbesondere bei der Anzeige von großen Textmengen oder komplexen Grafiken.</p></li>
<li><p><strong>Tabs und Fenster</strong>: Kitty unterstützt mehrere Tabs und Fenster, sodass Sie Ihre Arbeitsumgebung effizient organisieren können.</p></li>
<li><p><strong>Grafikunterstützung</strong>: Kitty kann Bilder direkt im Terminal anzeigen, was es ideal für Entwickler macht, die mit Grafiken arbeiten.</p></li>
<li><p><strong>Anpassbare Tastenkombinationen</strong>: Sie können Ihre eigenen Tastenkombinationen definieren, um Ihre Produktivität zu steigern.</p></li>
<li><p><strong>Remote-Verbindungen</strong>: Kitty unterstützt SSH und andere Remote-Protokolle, sodass Sie nahtlos auf entfernte Systeme zugreifen können.</p></li>
<li><p><strong>Leistungsstarke Konfiguration</strong>: Kitty bietet eine umfangreiche Konfigurationsdatei, mit der Sie das Verhalten und Aussehen des Terminals an Ihre Bedürfnisse anpassen können.</p></li>
</ol>
</section>
<section id="warum-kitty-verwenden" class="level2">
<h2 class="anchored" data-anchor-id="warum-kitty-verwenden">Warum kitty verwenden?</h2>
<p>Es gibt mehrere Gründe, warum Sie kitty als Ihren bevorzugten Terminal-Emulator in Betracht ziehen sollten:</p>
<ul>
<li><p><strong>Leistung</strong>: Die GPU-Beschleunigung sorgt für eine reibungslose und schnelle Benutzererfahrung.</p></li>
<li><p><strong>Funktionsreichtum</strong>: Mit einer Vielzahl von Funktionen und Anpassungsmöglichkeiten bietet kitty eine flexible Arbeitsumgebung.</p></li>
<li><p><strong>Aktive Entwicklung</strong>: Kitty wird aktiv weiterentwickelt, was bedeutet, dass Sie regelmäßig neue Funktionen und Verbesserungen erhalten.</p></li>
<li><p><strong>Open Source</strong>: Kitty ist Open Source, was bedeutet, dass Sie den Quellcode einsehen und anpassen können.</p></li>
</ul>
</section>
<section id="fazit" class="level2">
<h2 class="anchored" data-anchor-id="fazit">Fazit</h2>
<p>Kitty ist ein leistungsstarker und funktionsreicher Terminal-Emulator, der sich durch seine GPU-Beschleunigung und Anpassungsfähigkeit auszeichnet. Egal, ob Sie ein Entwickler sind, der viel Zeit im Terminal verbringt, oder einfach nur einen schnellen und zuverlässigen Terminal-Emulator suchen, kitty ist definitiv eine Überlegung wert.</p>
<p>Link: <a href="https://sw.kovidgoyal.net/kitty/">Offizielle kitty-Website</a></p>


</section>

 ]]></description>
  <category>terminal-emulator</category>
  <category>kitty</category>
  <category>gpu</category>
  <guid>https://www.sefiroth.de/posts/2026-01-30-kitty-der_schnelle_gpu_basierte_terminal_emulator/</guid>
  <pubDate>Thu, 29 Jan 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>B-Bäume und mehr: Ein Vergleich von Python-Implementierungen</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2026-01-04-B-Baeume-und-mehr/</link>
  <description><![CDATA[ 





<section id="einführung" class="level2">
<h2 class="anchored" data-anchor-id="einführung">Einführung</h2>
<p>B-Bäume sind eine Art von selbstbalancierenden Suchbäumen, die in Datenbanken und Dateisystemen weit verbreitet sind. In diesem Beitrag werde ich verschiedene Python-Implementierungen von B-Bäumen vergleichen und ihre Vor- und Nachteile diskutieren.</p>
</section>
<section id="implementierungen-im-vergleich" class="level2">
<h2 class="anchored" data-anchor-id="implementierungen-im-vergleich">Implementierungen im Vergleich</h2>
<ol type="1">
<li><strong>bintrees</strong>: Diese Bibliothek bietet eine einfache Implementierung von B-Bäumen und anderen Baumstrukturen. Sie ist leicht zu verwenden und gut dokumentiert, aber möglicherweise nicht die leistungsfähigste Option für große Datenmengen.</li>
<li><strong>bplustree</strong>: Diese Bibliothek implementiert B+-Bäume, eine Variante von B-Bäumen, die für Datenbankanwendungen optimiert ist. Sie bietet gute Leistung und Skalierbarkeit, erfordert jedoch ein tieferes Verständnis der B+-Baum-Struktur.</li>
<li><strong>pybloom-live</strong>: Obwohl hauptsächlich für Bloom-Filter gedacht, enthält diese Bibliothek auch eine B-Baum-Implementierung. Sie ist nützlich für Anwendungen, die sowohl Bäume als auch probabilistische Datenstrukturen benötigen.</li>
<li><strong>btree</strong>: Diese Implementierung ist in der Standardbibliothek von Python enthalten und bietet grundlegende B-Baum-Funktionalitäten. Sie ist einfach zu verwenden, aber möglicherweise nicht so leistungsfähig wie spezialisierte Bibliotheken.</li>
</ol>
</section>
<section id="leistungstest" class="level2">
<h2 class="anchored" data-anchor-id="leistungstest">Leistungstest</h2>
<p>Um die Leistung der verschiedenen Implementierungen zu vergleichen, habe ich einen einfachen Test durchgeführt, bei dem ich eine große Anzahl von Einfügungen und Suchvorgängen durchgeführt habe. Hier sind die Ergebnisse:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> time</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> bintrees <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> FastRBTree</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> bplustree <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> BPlusTree</span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Testdaten</span></span>
<span id="cb1-5">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100000</span>))</span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bintrees Test</span></span>
<span id="cb1-7">bintree <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> FastRBTree()</span>
<span id="cb1-8">start_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time()</span>
<span id="cb1-9"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> item <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> data:</span>
<span id="cb1-10">    bintree.insert(item, item)</span>
<span id="cb1-11">bintree_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> start_time</span>
<span id="cb1-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bplustree Test</span></span>
<span id="cb1-13">bplustree <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> BPlusTree(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bplustree.db'</span>, order<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>)</span>
<span id="cb1-14">start_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time()</span>
<span id="cb1-15"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> item <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> data:</span>
<span id="cb1-16">    bplustree.insert(item, item)</span>
<span id="cb1-17">bplustree_time <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> time.time() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> start_time</span>
<span id="cb1-18"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"bintrees Einfügezeit: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>bintree_time<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> Sekunden"</span>)</span>
<span id="cb1-19"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"bplustree Einfügezeit: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>bplustree_time<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;"> Sekunden"</span>)</span></code></pre></div></div>
<p>Die Ergebnisse zeigten, dass <code>bplustree</code> bei großen Datenmengen eine bessere Leistung erzielte, insbesondere bei Suchvorgängen, während <code>bintrees</code> für kleinere Datensätze ausreichend war.</p>
</section>
<section id="fazit" class="level2">
<h2 class="anchored" data-anchor-id="fazit">Fazit</h2>
<p>Die Wahl der richtigen B-Baum-Implementierung hängt stark von den spezifischen Anforderungen Ihres Projekkts ab. Für einfache Anwendungen kann <code>bintrees</code> ausreichend sein, während <code>bplustree</code> besser für komplexe Datenbankanwendungen geeignet ist. Es lohnt sich, die verschiedenen Optionen zu testen, um die beste Leistung für Ihre spezifischen Anwendungsfälle zu erzielen. Unabhängig von der gewählten Implementierung bieten B-Bäume eine effiziente Möglichkeit, große Datenmengen zu verwalten und zu durchsuchen. Ich hoffe, dieser Vergleich hilft Ihnen bei der Auswahl der richtigen B-Baum-Implementierung für Ihre Python-Projekte! Happy Coding! 🚀</p>


</section>

 ]]></description>
  <category>Python</category>
  <guid>https://www.sefiroth.de/posts/2026-01-04-B-Baeume-und-mehr/</guid>
  <pubDate>Sat, 03 Jan 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Das Lotto-Abbildungsproblem</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2025-12-22-Das-Lotto-Abbildungs-Problem/</link>
  <description><![CDATA[ 





<section id="die-beschreibung" class="level1">
<h1>Die Beschreibung</h1>
<p>Jeder, der Kombinatorik oder Wahrscheinlichkeitsrechnung studiert hat, kennt das klassische Lotto-Problem: Aus einer Menge von 49 Zahlen werden 6 Zahlen ohne Zurücklegen gezogen. Wie viele verschiedene Kombinationen sind möglich?</p>
<p>Die Antwort ist bekanntlich: <img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cbinom%7B49%7D%7B6%7D%20=%20%5Cfrac%7B49!%7D%7B6!(49-6)!%7D%20=%2013%5C,983%5C,816%0A"></p>
<p>Aber viele sehen nicht, dass dies auch bedeutet, dass jedes Ziehungsergebnis ein-ein-deutig auf die Zahlen <img src="https://latex.codecogs.com/png.latex?1"> bis <img src="https://latex.codecogs.com/png.latex?13%5C,983%5C,816"> abbildet. Genauer, es gibt (mindestens) eine Abbilung aus <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D%20=%20%5C%7B1,%202,%20%5Cldots,%2049%5C%7D"> in <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D%20=%20%5C%7Bq,%201,%202,%20%5Cldots,%2013%5C,983%5C,816%5C%7D">, so dass jede 6-elementige Teilmenge von <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D"> auf ein eindeutiges Element von <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D"> abgebildet wird.</p>
</section>
<section id="die-frage" class="level1">
<h1>Die Frage</h1>
<p><strong>Wie sieht so eine Abbildung aus und vorallem wie lautet die Umkehrabbildung?</strong></p>
</section>
<section id="eine-mögliche-lösung" class="level1">
<h1>Eine mögliche Lösung</h1>
<p>Wir können die Abbildung konstruieren, indem wir die 6 gezogenen Zahlen sortieren und dann eine lexikographische Ordnung verwenden, um jede Kombination zu nummerieren. Angenommen, die gezogenen Zahlen sind <img src="https://latex.codecogs.com/png.latex?a_1%20%3C%20a_2%20%3C%20a_3%20%3C%20a_4%20%3C%20a_5%20%3C%20a_6">. Dann können wir die Abbildung <img src="https://latex.codecogs.com/png.latex?f:%20%5Cmathcal%7BL%7D%5E6%20%5Cto%20%5Cmathcal%7BM%7D"> wie folgt definieren:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Af(a_1,%20a_2,%20a_3,%20a_4,%20a_5,%20a_6)%20=%20%5Csum_%7Bi=1%7D%5E%7B6%7D%20%5Cbinom%7Ba_i%20-%201%7D%7Bi%7D%0A"></p>
<p>Hierbei ist <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7Bn%7D%7Bk%7D"> der Binomialkoeffizient, der die Anzahl der Möglichkeiten angibt, <img src="https://latex.codecogs.com/png.latex?k"> Elemente aus einer Menge von <img src="https://latex.codecogs.com/png.latex?n"> Elementen auszuwählen.</p>
<p>Diese Abbildung ist eindeutig, da jede Kombination von 6 Zahlen eine eindeutige Summe von Binomialkoeffizienten ergibt.</p>
<p>Die Umkehrabbildung <img src="https://latex.codecogs.com/png.latex?f%5E%7B-1%7D:%20%5Cmathcal%7BM%7D%20%5Cto%20%5Cmathcal%7BL%7D%5E6"> kann durch eine iterative Methode konstruiert werden, bei der wir die größte Zahl <img src="https://latex.codecogs.com/png.latex?a_6"> bestimmen, die noch in die Summe passt, dann <img src="https://latex.codecogs.com/png.latex?a_5">, und so weiter, bis wir alle 6 Zahlen gefunden haben.</p>
<p>Hier ist ein Beispiel für die Umkehrabbildung:</p>
<ol type="1">
<li><p>Setze <img src="https://latex.codecogs.com/png.latex?n%20=%20f(a_1,%20a_2,%20a_3,%20a_4,%20a_5,%20a_6)">.</p></li>
<li><p>Für <img src="https://latex.codecogs.com/png.latex?i"> von 6 bis 1:</p>
<ul>
<li><p>Finde die größte Zahl <img src="https://latex.codecogs.com/png.latex?a_i"> such that <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7Ba_i%20-%201%7D%7Bi%7D%20%5Cleq%20n">.</p></li>
<li><p>Setze <img src="https://latex.codecogs.com/png.latex?n%20=%20n%20-%20%5Cbinom%7Ba_i%20-%201%7D%7Bi%7D">.</p></li>
</ul></li>
<li><p>Gib die Zahlen <img src="https://latex.codecogs.com/png.latex?a_1,%20a_2,%20a_3,%20a_4,%20a_5,%20a_6"> zurück.</p></li>
</ol>
<p>Diese Methode garantiert, dass wir die ursprünglichen gezogenen Zahlen zurückerhalten, da wir die gleiche Logik wie in der Vorwärtsabbildung verwenden, aber in umgekehrter Reihenfolge.</p>
</section>
<section id="fazit" class="level1">
<h1>Fazit</h1>
<p>Die Abbildung des Lotto-Problems zeigt, wie kombinatorische Konzepte verwendet werden können, um eindeutige Zuordnungen zwischen Mengen zu erstellen. Diese Art von Abbildungen ist nicht nur in der Mathematik interessant, sondern findet auch Anwendungen in Bereichen wie Kryptographie und Datenkompression.</p>
</section>
<section id="implementierung-in-r-und-python" class="level1">
<h1>Implementierung in R und Python</h1>
<div class="tabset-margin-container"></div><div class="panel-tabset" data-group="language">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false" href="">Python</a></li></ul>
<div class="tab-content" data-group="language">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># R-Code zur Berechnung der Abbildung und Umkehrabbildung</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gmp)</span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Funktion zur Berechnung der Abbildung</span></span>
<span id="cb1-5">lotto_abbildung <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(a) {</span>
<span id="cb1-6">  t <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(a))</span>
<span id="cb1-7">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(t) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any</span>(t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any</span>(t <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>)) {</span>
<span id="cb1-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Eingabe muss 6 eindeutige Zahlen zwischen 1 und 49 sein."</span>)</span>
<span id="cb1-9">  }</span>
<span id="cb1-10">  l <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chooseZ</span>(a[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, i), </span>
<span id="cb1-11">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">USE.NAMES =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>l[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> l[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> l[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> l[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> l[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> l[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]])</span>
<span id="cb1-13">}</span>
<span id="cb1-14"></span>
<span id="cb1-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Funktion zur Berechnung der Umkehrabbildung</span></span>
<span id="cb1-16">lotto_umkehrabbildung <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n) {</span>
<span id="cb1-17">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chooseZ</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)) {</span>
<span id="cb1-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Eingabe muss zwischen 1 und 13.983.816 liegen."</span>)</span>
<span id="cb1-19">  }</span>
<span id="cb1-20">  a <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">integer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)</span>
<span id="cb1-21">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) {</span>
<span id="cb1-22">    a[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chooseZ</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>, i) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> n))</span>
<span id="cb1-23">    n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chooseZ</span>(a[i] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, i)</span>
<span id="cb1-24">  }</span>
<span id="cb1-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(a)</span>
<span id="cb1-26">}</span></code></pre></div></div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Python-Code zur Berechnung der Abbildung und Umkehrabbildung</span></span>
<span id="cb2-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> math <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> comb</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Funktion zur Berechnung der Abbildung</span></span>
<span id="cb2-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> lotto_abbildung(a):</span>
<span id="cb2-6">    a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sorted</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(a))</span>
<span id="cb2-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">any</span>(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> a):</span>
<span id="cb2-8">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">raise</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">ValueError</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Eingabe muss 6 eindeutige Zahlen zwischen 1 und 49 sein."</span>)</span>
<span id="cb2-9">    l <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [comb(a[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)]</span>
<span id="cb2-10">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(l)</span>
<span id="cb2-11"></span>
<span id="cb2-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Funktion zur Berechnung der Umkehrabbildung</span></span>
<span id="cb2-13"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> lotto_umkehrabbildung(n):</span>
<span id="cb2-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> comb(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>):</span>
<span id="cb2-15">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">raise</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">ValueError</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Eingabe muss zwischen 0 und 13.983.816 liegen."</span>)</span>
<span id="cb2-16">    a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span></span>
<span id="cb2-17">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>):</span>
<span id="cb2-18">        tmp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>(k <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> k <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> comb(k, i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> n)</span>
<span id="cb2-19">        a[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> tmp</span>
<span id="cb2-20">        n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-=</span> comb(tmp, i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-21">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> a</span></code></pre></div></div>
</div>
</div>
</div>
</div>
</section>
<section id="beispiel" class="level1">
<h1>Beispiel</h1>
<div class="tabset-margin-container"></div><div class="panel-tabset" data-group="language">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-2-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-1" aria-controls="tabset-2-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-2-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-2" aria-controls="tabset-2-2" aria-selected="false" href="">Python</a></li></ul>
<div class="tab-content" data-group="language">
<div id="tabset-2-1" class="tab-pane active" aria-labelledby="tabset-2-1-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">gezogene_zahlen <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">23</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">34</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>)</span>
<span id="cb3-2">abbildung <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lotto_abbildung</span>(gezogene_zahlen)</span>
<span id="cb3-3">umkehrabbildung <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lotto_umkehrabbildung</span>(abbildung)</span></code></pre></div></div>
</div>
</div>
<div id="tabset-2-2" class="tab-pane" aria-labelledby="tabset-2-2-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">gezogene_zahlen <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">23</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">34</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>]</span>
<span id="cb4-2">abbildung <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> lotto_abbildung(gezogene_zahlen)</span>
<span id="cb4-3">umkehrabbildung <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> lotto_umkehrabbildung(abbildung)</span></code></pre></div></div>
</div>
</div>
</div>
</div>
<p>Die Ausgabe zeigt die eindeutige Nummer der gezogenen Zahlen und die zurückgewonnenen Zahlen</p>
<div class="tabset-margin-container"></div><div class="panel-tabset" data-group="language">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-3-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-1" aria-controls="tabset-3-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-3-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-2" aria-controls="tabset-3-2" aria-selected="false" href="">Python</a></li></ul>
<div class="tab-content" data-group="language">
<div id="tabset-3-1" class="tab-pane active" aria-labelledby="tabset-3-1-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Ausgabe</span></span>
<span id="cb5-2">abbildung  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Eindeutige Nummer</span></span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Big Integer ('bigz') :
[1] 13400040</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">umkehrabbildung  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zurückgewonnene Zahlen</span></span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1]  5 12 23 34 45 49</code></pre>
</div>
</div>
</div>
<div id="tabset-3-2" class="tab-pane" aria-labelledby="tabset-3-2-tab">
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Ausgabe</span></span>
<span id="cb9-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(abbildung)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Eindeutige Nummer</span></span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>13400040</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(umkehrabbildung)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zurückgewonnene Zahlen</span></span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[5, 12, 23, 34, 45, 49]</code></pre>
</div>
</div>
</div>
</div>
</div>
<p>Die Ausgabe zeigt die eindeutige Nummer der gezogenen Zahlen und die zurückgewonnenen Zahlen.</p>
<p>Die Frage bleibt, geht es auch ohne (extra) Scheifen bei der Suche nach dem nächsten <img src="https://latex.codecogs.com/png.latex?a_i"> in der Umkehrabbildung?</p>
</section>
<section id="referenzen" class="level1">
<h1>Referenzen</h1>
<ul>
<li><a href="https://de.wikipedia.org/wiki/Lotto_(Spiel%20)">Wikipedia: Lotto (Spiel)</a></li>
<li><a href="https://de.wikipedia.org/wiki/Binomialkoeffizient">Wikipedia: Binomialkoeffizient</a></li>
<li><a href="https://www.mathe-online.at/materialien/mathematik/kombinatorik-und-wahrscheinlichkeitsrechnung/">Kombinatorik und Wahrscheinlichkeitsrechnung</a></li>
</ul>


</section>

 ]]></description>
  <category>Quarto</category>
  <category>Python</category>
  <category>R</category>
  <guid>https://www.sefiroth.de/posts/2025-12-22-Das-Lotto-Abbildungs-Problem/</guid>
  <pubDate>Sun, 21 Dec 2025 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Quarto-Dokumente mit WebP anstatt PNG Bilddateien erstellen</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2025-12-03-Quarto-Dokumente-mit-webp-anstatt-png/</link>
  <description><![CDATA[ 





<section id="webp-statt-png" class="level1">
<h1>WebP statt PNG?</h1>
<p>Ich bin über die Quarto-Extension von Klaus Brunner mit dem Namen <a href="https://github.com/klausbrunner/convert-to-webp">Convert PNG to WebP (Quarto Extension)</a> gestolpert und nutze diesen nun regelmässig.</p>
<p>Dafür habe ich auf meinem Mac via HomeBrew die Application “webp” installiert.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> brew <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install</span> webp</span></code></pre></div></div>
<p>Dadurch habe ich das Programm <code>cwebp</code> installiert. Es dient zum umwandeln von PNG in webp Dateien. Zum Testen nutze ich den Befehl:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> cwebp <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">-version</span></span></code></pre></div></div>
<p>Aktuell bekomme ich damit die Ausgabe:</p>
<pre><code>1.6.0
libsharpyuv: 0.4.2</code></pre>
<p>Das Programm ersetzt die erzeugten Bild-Ausgaben, welche normalerweise im PNG-Format erzeugt werden, durch Neue im WebP-Format.</p>
<p>Die KI sagt:</p>
<blockquote class="blockquote">
<p>WebP ist ein modernes Bildformat von Google, das eine effizientere Komprimierung als herkömmliche Formate wie JPEG und PNG ermöglicht, um Bilder im Web kleiner zu machen und Ladezeiten zu beschleunigen. Es unterstützt sowohl verlustfreie als auch verlustbehaftete Komprimierung sowie Transparenz und Animationen, ähnlich wie PNG und GIF. WebP wird von den meisten modernen Browsern unterstützt, aber für ältere Browser ist es ratsam, eine alternative Bildversion bereitzustellen</p>
</blockquote>
<section id="installation-im-quarto-projekt" class="level2">
<h2 class="anchored" data-anchor-id="installation-im-quarto-projekt">Installation im Quarto-Projekt</h2>
<p>Um sofort bei der Erstellung von Dokumenten, wie zum Beispiel diese Blog-Einträge, mit Quarto webp zu nutzen, installiert mensch einfach im Quarto-Projekt mittels:</p>
<pre class="bas"><code>&gt; quarto add klausbrunner/convert-to-webp</code></pre>
<p>Danach in der Datei <code>_quarto.yml</code> noch die folgenden Zeilen hinzufügen:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode yml code-with-copy"><code class="sourceCode yaml"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filters</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb5-2"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> convert-to-webp</span></span>
<span id="cb5-3"></span>
<span id="cb5-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">webp-delete-originals</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">false</span></span>
<span id="cb5-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">webp-disable</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">false</span></span></code></pre></div></div>
<p>Jetzt wird nach jedem ‘rendern’ eines Dokuments die erzeugten PNG-Dateien in WebP-Dateien übersetzt und im HTML-Code entsprechend ersetzt.</p>


</section>
</section>

 ]]></description>
  <category>Quarto</category>
  <guid>https://www.sefiroth.de/posts/2025-12-03-Quarto-Dokumente-mit-webp-anstatt-png/</guid>
  <pubDate>Tue, 02 Dec 2025 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Brotli statt Gzip auf dem Server konfigurieren</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2025-08-09-brotli-statt-gzip-konfigurieren/</link>
  <description><![CDATA[ 





<section id="wie-mensch-einen-webserver-davon-überzeugt-brotli-zu-nutzen" class="level1">
<h1>Wie mensch einen Webserver davon überzeugt Brotli zu nutzen</h1>
<p>Ich habe meinen Webserver von gzip auf brotli umgerüstet. Dachte ich jeden falls, aber alle Test mit</p>
<pre><code>&gt; curl -I -H 'Accept-Encoding: br' https://sefiroth.de</code></pre>
<p>schlugen fehl. Nach langer Suche im Internet habe ich herausgefunden, dass zwar die Datei <code>brotli.load</code> in den Verzeichnissen <code>/etc/apache2/mods-enable</code> und <code>/etc/apache2/mods-available</code> existieren, nicht aber die Datei <code>brotli.conf</code>, mit welcher die ganzen Einstellungen gemacht werden.</p>
<p>Fügt mensch nun in diese Datei den Inhalt</p>
<pre><code>&lt;IfModule mod_brotli.c&gt;
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript app
lication/javascript application/x-javascript application/json application/xml
    BrotliCompressionQuality 6
&lt;/IfModule&gt;</code></pre>
<p>ein und startet danach den apache-Server neu, so läuft <em>brotli</em> endlich auch auf dem Server!</p>


</section>

 ]]></description>
  <category>Apache</category>
  <category>Webserver</category>
  <category>Nginx</category>
  <guid>https://www.sefiroth.de/posts/2025-08-09-brotli-statt-gzip-konfigurieren/</guid>
  <pubDate>Fri, 08 Aug 2025 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Wie mensch eine Datenbank auf einem RASPBERRY Pi Zero installiert</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2025-08-09-wie-mensch-eine-datenbank-auf-einen-raspberry-zero-installiert/</link>
  <description><![CDATA[ 





<section id="einrichten-des-raspberry-zero" class="level2">
<h2 class="anchored" data-anchor-id="einrichten-des-raspberry-zero">Einrichten des Raspberry Zero</h2>
<section id="schrit-1-neues-betriebssystem-installieren" class="level3">
<h3 class="anchored" data-anchor-id="schrit-1-neues-betriebssystem-installieren">Schrit 1: Neues Betriebssystem installieren</h3>
<p>Am besten mit dem Raspberry Pi Installer von hier: <a href="https://www.raspberrypi.com/software/" class="uri">https://www.raspberrypi.com/software/</a></p>
<p>Für einen Raspberry Zero: <em>Raspberry Pi OS (32-bit) Lite</em></p>
<p>Für einen Raspberry Zero 2 W: <em>Raspberry Pi OS (64-bit) Lite</em></p>
<p><strong>Wichtig</strong> MIT SSH konfigurieren!</p>
</section>
<section id="schrit-2-ein-link-zum-display" class="level3">
<h3 class="anchored" data-anchor-id="schrit-2-ein-link-zum-display">Schrit 2: Ein Link zum Display</h3>
<p>Auf dem RaspberryPI Zero ist ein Waveshare 2-13inch-e-Paper HAT installiert. Alles Wichtige dazu findet sich unter: <a href="https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_Manual#Working_With_Raspberry_Pi" class="uri">https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_Manual#Working_With_Raspberry_Pi</a></p>
<p>Damit das Display richtig funktioniert sollte man in der <code>config.txt</code> die folgende Zeile anpassen:</p>
<pre><code>dtparam=spi=on</code></pre>
</section>
<section id="schritt-3-den-raspberry-pi-im-netz-suchen-und-finden" class="level3">
<h3 class="anchored" data-anchor-id="schritt-3-den-raspberry-pi-im-netz-suchen-und-finden">Schritt 3: Den Raspberry Pi im Netz suchen und finden</h3>
<p>Es gibt viele Weg die zum Ziel führen (können).</p>
<p>Zum Beispiel mit dem Befehl <code>nmap</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> nmap <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">-sn</span> 192.168.2.0/24</span></code></pre></div></div>
<p>Oder einfach den Hostnamen “raspberrpi.local” nutzen.</p>
<p>Man kann sich somit ggf. mittels ssh und dem folgenden Kommando anmelden:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> ssh <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">norman@raspberrypi.local</span></span></code></pre></div></div>
<p>Ebenso kann <a href="http://connect.raspberrypi.com">R PI Connect</a> benutzt werden, wenn man es vorher eingerichtet hat.</p>
</section>
<section id="schritt-4-startup-display-installieren" class="level3">
<h3 class="anchored" data-anchor-id="schritt-4-startup-display-installieren">Schritt 4: Startup-Display installieren</h3>
<p>Ich habe bei GitHub ein kleines Programm geschrieben, welches die aktuelle IP Address (IP4 und IP6 sowie die aktuelle Uhrzeit) auf dem Display ausgibt.</p>
<p>Es ist unter <a href="https://github.com/NMarkgraf/pi-startup-display" class="uri">https://github.com/NMarkgraf/pi-startup-display</a> zu finden und wird einfach in das Hauptverzeichnis des Nutzers “norman” unter “/home/norman” per</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> git <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">clone</span> https://github.com/NMarkgraf/pi-startup-display </span></code></pre></div></div>
<p>installiert.</p>
<p>Später kann dann im Verzeichnis <code>pi-startup-display</code> einfach das aktuelle Release von GutHUb durch den folgenden Befehl geladen werden:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> git <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">pull</span></span></code></pre></div></div>
<p>Damit dieses Skript nach jedem Neustart automatisch (einmal) gestartet wird bin ich nach dem Beispiel von <a href="https://webnist.de/automatisches-starten-eines-python-skripts-auf-dem-raspberry-pi-mit-systemd/" class="uri">https://webnist.de/automatisches-starten-eines-python-skripts-auf-dem-raspberry-pi-mit-systemd/</a> vorgegangen.</p>
<p>Aber ich habe die service Datei “/etc/systemd/system/startup-display.service” wie folgt angepasst:</p>
<pre><code>[Unit]
Description=startup-display
After=network.target
 
[Service]
ExecStart=/usr/bin/python3 -u /home/norman/pi-startup-display/start-display.py 
WorkingDirectory=/home/norman/pi-startup-display/
#StandardOutput=inherit
StandardOutput=file:/tmp/start-display.log
#StandardError=inherit
StandardError=file:/tmp/start-display-error.log
#Restart=always
Restart=on-failture
RestartSec=60
User=norman
 
[Install]
WantedBy=multi-user.target</code></pre>
<p>Zum anlegen habe ich den Editor “nano” genutzt und die Datei gleich mit angelegt.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb7-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nano</span> /etc/systemd/system/startup-display.service</span></code></pre></div></div>
<p>Die geänderte Datei muss nun initialisiert werden mit:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb8-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">systemctl</span> daemon-reload</span>
<span id="cb8-2"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">systemctl</span> enable startup-display.service</span></code></pre></div></div>
<p>Dann können wir alles, zum Testen, von Hand starten:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb9-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">systemctl</span> start startup-display.service</span></code></pre></div></div>
<p>Ob alles zu unserer Zufriedenheit funktioniert können wir mit der Status-Anzeige mit dem folgenden Befehl prüfen:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb10-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">systemctl</span> status startup-display.service</span></code></pre></div></div>
<p>Und natürlich ggf. auch stoppen:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb11-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">systemctl</span> stop startup-display.service</span></code></pre></div></div>
</section>
</section>
<section id="postgresql-installieren" class="level2">
<h2 class="anchored" data-anchor-id="postgresql-installieren">PostgreSQL installieren</h2>
<p>Ich gehe wie folgt vor:</p>
<section id="schritt-1-installieren-von-postgresql" class="level3">
<h3 class="anchored" data-anchor-id="schritt-1-installieren-von-postgresql">Schritt 1: Installieren von PostgreSQL</h3>
<p>Da es ein deb Paket gibt, nehme ich den leichten Weg:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb12-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">apt</span> install postgresql</span></code></pre></div></div>
</section>
<section id="schritt-2-wechseln-auf-nutzerin-postgres" class="level3">
<h3 class="anchored" data-anchor-id="schritt-2-wechseln-auf-nutzerin-postgres">Schritt 2: Wechseln auf Nutzer:in “postgres”</h3>
<p>Wir kommunizieren mit PostgreSQL durch den Benutzer “postgres”, in den wir uns verwandelt:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb13-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">su</span> postgres</span></code></pre></div></div>
</section>
<section id="schritt-3-herunterladen-der-demo-daten-entpacken-und-installieren" class="level3">
<h3 class="anchored" data-anchor-id="schritt-3-herunterladen-der-demo-daten-entpacken-und-installieren">Schritt 3: Herunterladen der Demo-Daten, entpacken und installieren</h3>
<p>Die erste Demo-Daten erhalten wir durch:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb14-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> curl <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">-L</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-O</span> https://github.com/lerocha/netflixdb/releases/download/v1.0.16/netflixdb-postgres.zip</span>
<span id="cb14-2"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> unzip <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">netflixdb-postgres.zip</span></span></code></pre></div></div>
<p>Da Daten können wir dann in die Datenbank “netfix” einfügren:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb15-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> sudo <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">su</span> postgres</span>
<span id="cb15-2"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> psql <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">-d</span> netflix</span>
<span id="cb15-3"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\i</span> <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">/home/norman/netflixdb-postgres.sql</span></span></code></pre></div></div>
<p>Jetzt ist die Datenbank “netflix” in PostgreSQL installiert.</p>
<p>Und wir können diese nun mit den folgenden Parametern ansprechen:</p>
<pre><code>  ip:       ???? 
  port:     5342
  user:     postgres
  password: postgresdemo 
  dbname:   netflix</code></pre>
</section>
<section id="schritt-4-adminerneo-installieren" class="level3">
<h3 class="anchored" data-anchor-id="schritt-4-adminerneo-installieren">Schritt 4: AdminerNEO installieren</h3>
<p>AdminerNEO ist ein Webtool für die Verwaltung von PostgreSQL.</p>
<p>Wir installieren die aktuelle Version von der Website: <a href="https://www.adminneo.org/download" class="uri">https://www.adminneo.org/download</a></p>


</section>
</section>

 ]]></description>
  <category>RaspberryPi</category>
  <category>Datenbank</category>
  <guid>https://www.sefiroth.de/posts/2025-08-09-wie-mensch-eine-datenbank-auf-einen-raspberry-zero-installiert/</guid>
  <pubDate>Fri, 08 Aug 2025 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Beweisverfahren in der Mathematik</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2025-07-27-Beweisverfahren/</link>
  <description><![CDATA[ 





<section id="allgemeine-beweistechniken" class="level2">
<h2 class="anchored" data-anchor-id="allgemeine-beweistechniken">Allgemeine Beweistechniken</h2>
<section id="beweis-durch-einschüchterung" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-einschüchterung">Beweis durch Einschüchterung</h3>
<p>Trivial!</p>
</section>
<section id="beweis-durch-umständliche-notation" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-umständliche-notation">Beweis durch umständliche Notation</h3>
<p>Der Satz folgt sofort aus dem Fakt</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cleft%7C%0A%20%20%20%20%5Coplus_%7Bk%20%5Cin%20S%7D%0A%20%20%20%20%20%20%5Cleft(%0A%20%20%20%20%20%20%20%5Cmathfrak%7BK%7D%5E%7B%5Cmathbb%7BF%7D%5E%5Calpha(i)%7D%20%20%0A%20%20%20%20%20%20%5Cright)_%7Bi%20%5Cin%20%5Cmathcal%7BU%7D_k%7D%0A%20%20%5Cright%7C%0A%20%20%5Cpreceq%20%5Caleph_1%0A%20%20%5Ctext%7B%20wenn%20%7D%0A%20%20%5Cleft%5B%0A%20%20%20%20%5Cmathfrak%7BH%7D_%5Cmathcal%7BW%7D%0A%20%20%5Cright%5D%20%20%20%20%20%0A%20%20%5Ccap%20%5Cmathbb%7BF%7D%5E%5Calpha(%5Cmathbb%7BN%7D)%20%5Cneq%20%5Cemptyset.%0A"></p>
</section>
<section id="beweis-durch-unzugreifbare-literatur" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-unzugreifbare-literatur">Beweis durch unzugreifbare Literatur</h3>
<p>Der Satz ist ein einfaches Korrollat eines Ergebnis bewiesen in einer handgeschriebenen Anmerkung ausgehändigt in einer Vorlesung bei der Jugoslawischen Mathematischen Gesellschaft 1973.</p>
</section>
<section id="beweis-durch-geisterhafte-zitate" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-geisterhafte-zitate">Beweis durch geisterhafte Zitate</h3>
<p>Der Beweis kann auf Seite 478 gefunden werden, in einem Buch, welches nur 396 Seiten hat.</p>
</section>
<section id="beweis-durch-circularer-argumentation" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-circularer-argumentation">Beweis durch circularer Argumentation</h3>
<p>Proposition 5.18 in [BL] ist ein einfaches Korollar zm Satz 7.18 in [C], welches wiederum auf Korollar 2.14 in [K] basiert. Dieses wiederum wird unter Bezugnahme auf Proposition 5.18 in [BL] hergeleitet.</p>
</section>
<section id="beweis-durch-autorität" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-autorität">Beweis durch Autorität</h3>
<p>Mein guter Kollege Andrew meinte, er glaube, er hätte dafür vor ein paar Jahren einen Beweis finden können …</p>
</section>
<section id="beweis-durch-internet-referenz" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-internet-referenz">Beweis durch Internet Referenz</h3>
<p>Für Interessierte ist das Ergebnis auf der Webseite zu diesem Buch zu sehen. – Die es leider nicht mehr gibt.</p>
</section>
<section id="beweis-durch-vermeidung" class="level3">
<h3 class="anchored" data-anchor-id="beweis-durch-vermeidung">Beweis durch Vermeidung</h3>
<p>Kapitel 3: Der Beweis hierfür wird erst in Kapitel 7 erbracht, wenn wir die Theorie weiterentwickelt haben.</p>
<p>Kapitel 7: Der Einfachheit halber beweisen wir dies nur für den Fall z = 0. Der allgemeine Fall wird jedoch in Anhang C behandelt.</p>
<p>Anhang C: Der formale Beweis geht über den Rahmen dieses Buches hinaus, aber unsere Intuition sagt uns natürlich, dass dies wahr ist.</p>


</section>
</section>

 ]]></description>
  <category>Mathematik</category>
  <guid>https://www.sefiroth.de/posts/2025-07-27-Beweisverfahren/</guid>
  <pubDate>Sat, 26 Jul 2025 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Willkommen in meinem Blog</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/Willkommen/</link>
  <description><![CDATA[ 





<p>Das ist mein erster Blog-Eintrag! Ich werde nun hoffentlich (langsam) meinen Blog von Hugo aus Quarto umstellen. Ich arbeite viel mit R und eine extra Sprache nur für den Blog ist mir einfach auf Dauer zu umständlich. Aber mal sehen, wann ich Zeit finde dieses Projekt umzustezen.</p>



 ]]></description>
  <category>news</category>
  <guid>https://www.sefiroth.de/posts/Willkommen/</guid>
  <pubDate>Fri, 18 Jul 2025 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Grafiken nebeneinander setzen mit ggplot2 oder ggformula</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2021-12-27-grafiken-nebeneinander-setzen-mit-ggplot2-oder-ggformula/</link>
  <description><![CDATA[ 





<section id="wie-menschen-grafiken-von-ggplot2-oder-ggformula-nebeneinander-setzten-kann" class="level2">
<h2 class="anchored" data-anchor-id="wie-menschen-grafiken-von-ggplot2-oder-ggformula-nebeneinander-setzten-kann">Wie menschen Grafiken von ggplot2 oder ggformula nebeneinander setzten kann</h2>
<p>Ab und zu möchte mensch zwei (oder mehr) Grafiken neben- oder übereinander setzen.</p>
<p>Hier ein kurzes Beispiel, wie das gelingen kann. Zunächst bereiten wir alles vor, in dem wir die Pakete laden und die Daten freigeben.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mosaic)</span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ggf. einmal vorher den Befehl:</span></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># install.packages("gridExtra")</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ausführen oder das Paket "gridExtra" installieren.</span></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gridExtra)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(iris)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Datensatz bereitstellen</span></span></code></pre></div></div>
</div>
<p>Dann erstellen nun vier Plots und speichern diese in vier Variablen:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Ersten Plot erstellen</span></span>
<span id="cb2-2">plot1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_point</span>(Sepal.Length <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Sepal.Width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> iris)</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zweiten Plot erstellen</span></span>
<span id="cb2-5">plot2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_point</span>(Petal.Length <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Petal.Width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> iris)</span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Dritten Plot erstellen</span></span>
<span id="cb2-8">plot3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_point</span>(Sepal.Length <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Petal.Width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> iris)</span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vierten Plot erstellen</span></span>
<span id="cb2-11">plot4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_point</span>(Petal.Length <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Sepal.Width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> iris)</span></code></pre></div></div>
</div>
<p>Nun arrangieren wir die Plots entsprechend:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zwei Plots nebeneinander in einer Zeile: </span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grid.arrange</span>(plot1, plot2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-12-27-grafiken-nebeneinander-setzen-mit-ggplot2-oder-ggformula/index_files/figure-html/unnamed-chunk-4-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zwei Plots untereinander in einer Spalte</span></span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grid.arrange</span>(plot1, plot2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-12-27-grafiken-nebeneinander-setzen-mit-ggplot2-oder-ggformula/index_files/figure-html/unnamed-chunk-5-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vier Plots in einer Matrix:</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grid.arrange</span>(plot1, plot2, plot3, plot4, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) </span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-12-27-grafiken-nebeneinander-setzen-mit-ggplot2-oder-ggformula/index_files/figure-html/unnamed-chunk-6-1.webp" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>Statistik</category>
  <guid>https://www.sefiroth.de/posts/2021-12-27-grafiken-nebeneinander-setzen-mit-ggplot2-oder-ggformula/</guid>
  <pubDate>Sun, 26 Dec 2021 23:00:00 GMT</pubDate>
</item>
<item>
  <title>CSV Dateien bearbeiten mit Miller</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/csv-dateien-bearbeiten-mit-miller/</link>
  <description><![CDATA[ 





<p>Miller beschreibt sich selbst folgendermaßen:</p>
<blockquote class="blockquote">
<p>Miller is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON. You get to work with your data using named fields, without needing to count positional column indices.</p>
</blockquote>
<p>Miller kombiniert die Funktionalität von awk, sed und cut und eignet sich besonders für feldbasierte Datenmanipulation.</p>
<section id="beispiel-1-erstellung-einer-markdown-tabelle" class="level3">
<h3 class="anchored" data-anchor-id="beispiel-1-erstellung-einer-markdown-tabelle">Beispiel 1: Erstellung einer Markdown-Tabelle</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> mlr <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">--icsv</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--fs</span> semicolon <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--otsv</span> cat tips.csv <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb1-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'s/,/./g'</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">mlr</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--itsv</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--omd</span> cat</span></code></pre></div></div>
<p>Mit diesem Befehl wird eine durch Semikolon getrennte CSV-Datei in eine durch Tabulator getrennte TSV-Datei umgewandelt, anschließend werden alle Kommata durch Punkte ersetzt und schließlich wird daraus eine Markdown-Tabelle erzeugt.</p>
</section>
<section id="beispiel-2-gerahmte-darstellung" class="level3">
<h3 class="anchored" data-anchor-id="beispiel-2-gerahmte-darstellung">Beispiel 2: Gerahmte Darstellung</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> mlr <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">--icsv</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--fs</span> semicolon <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--otsv</span> cat tips.csv <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'s/,/./g'</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="ex" style="color: null;
background-color: null;
font-style: inherit;">mlr</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--itsv</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--opprint</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--barred</span> cat</span></code></pre></div></div>
<p>Mit diesem Befehl wird ebenfalls eine durch Semikolon getrennte CSV-Datei in eine durch Tabulator getrennte TSV-Datei umgewandelt, alle Kommata werden durch Punkte ersetzt und am Ende wird eine eingerahmte Tabelle erzeugt.</p>


</section>

 ]]></description>
  <category>Allgemeines</category>
  <category>Miller</category>
  <category>CSV</category>
  <category>Datenjudo</category>
  <category>Datenformate</category>
  <guid>https://www.sefiroth.de/posts/csv-dateien-bearbeiten-mit-miller/</guid>
  <pubDate>Thu, 26 Aug 2021 22:00:00 GMT</pubDate>
</item>
<item>
  <title>Datenjudo für Fragebögen</title>
  <dc:creator>Norman Markgraf</dc:creator>
  <link>https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/</link>
  <description><![CDATA[ 





<p>Ab und zu bekomme ich die Frage, wie man einen Fragebogen mit Likert-Scalen-Items auswerten kann.</p>
<p>Dazu kann etwas gezieltes Datenjudo helfen. Wir schauen uns das folgende generierte Mini-Beispiel an:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(mosaic)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Basis Paket</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tibble)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Eine modernere Variante der data.frames!</span></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2009</span>)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reproduzierbarkeit</span></span>
<span id="cb1-4"></span>
<span id="cb1-5">N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Anzahl der Testzeileneinträge in den "testdaten"!</span></span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Wir wollen eine Likert-Scale </span></span>
<span id="cb1-8">minLikert <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bis</span></span>
<span id="cb1-9">maxLikert <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># erstellen.</span></span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zum späteren Umrechnen der inversen Items:</span></span>
<span id="cb1-12">maxInvItem <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> maxLikert <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-13"></span>
<span id="cb1-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Wir bauen uns eine Testumfrage mit zwei Itemserien </span></span>
<span id="cb1-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># (AS1-AS6 und BS1-BS6) und N Beobachtungen.</span></span>
<span id="cb1-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Die Items AS3, AS4  und BS1 und BS5 sind dabei </span></span>
<span id="cb1-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># inverse Items, welche später umgerechnet werden:</span></span>
<span id="cb1-18">testdaten <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb1-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ID =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>N,</span>
<span id="cb1-20">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># AS1-AS6 bilden ein Itemset:</span></span>
<span id="cb1-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS3 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS4 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS5 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS6 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-27">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># BS1-BS5 bilden ein Itemset:</span></span>
<span id="cb1-28">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS3 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS4 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS5 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(minLikert<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxLikert, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb1-33">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Geschlecht als sex mit (1 für Frauen und 2 für Männer)</span></span>
<span id="cb1-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-35">)</span>
<span id="cb1-36"></span>
<span id="cb1-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Orinal testdaten einmal ausgeben:</span></span>
<span id="cb1-38"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(testdaten)</span>
<span id="cb1-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; # A tibble: 6 × 13</span></span>
<span id="cb1-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      ID   AS1   AS2   AS3   AS4   AS5   AS6   BS1   BS2   BS3   BS4   BS5   sex</span></span>
<span id="cb1-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt;</span></span>
<span id="cb1-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1     1     4     4     1     1     2     4     5     5     3     2     3     2</span></span>
<span id="cb1-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2     2     2     1     2     2     5     6     4     5     2     2     6     1</span></span>
<span id="cb1-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 3     3     4     4     6     3     3     4     3     3     4     1     5     1</span></span>
<span id="cb1-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 4     4     2     6     1     4     5     4     6     4     5     1     3     1</span></span>
<span id="cb1-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 5     5     3     1     3     5     5     6     6     1     2     6     5     1</span></span>
<span id="cb1-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 6     6     6     4     1     3     6     6     4     6     5     3     3     1</span></span></code></pre></div></div>
</div>
<p>Die Spalten AS3, AS4 und BS1, BS5 waren inverse Items, die wir noch umrechnen müssen:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inverse Item umrechnen:</span></span>
<span id="cb2-2">testdaten <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb2-4">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS3 =</span> maxInvItem <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> AS3,</span>
<span id="cb2-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS4 =</span> maxInvItem <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> AS4,</span>
<span id="cb2-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS1 =</span> maxInvItem <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> BS1,</span>
<span id="cb2-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS5 =</span> maxInvItem <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> BS5</span>
<span id="cb2-8">    ) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> testdaten_korrigiert </span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Die Daten mit den umgerechnetern inversen Items:</span></span>
<span id="cb2-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(testdaten_korrigiert)</span>
<span id="cb2-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; # A tibble: 6 × 13</span></span>
<span id="cb2-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      ID   AS1   AS2   AS3   AS4   AS5   AS6   BS1   BS2   BS3   BS4   BS5   sex</span></span>
<span id="cb2-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;int&gt;</span></span>
<span id="cb2-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1     1     4     4     6     6     2     4     2     5     3     2     4     2</span></span>
<span id="cb2-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2     2     2     1     5     5     5     6     3     5     2     2     1     1</span></span>
<span id="cb2-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 3     3     4     4     1     4     3     4     4     3     4     1     2     1</span></span>
<span id="cb2-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 4     4     2     6     6     3     5     4     1     4     5     1     4     1</span></span>
<span id="cb2-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 5     5     3     1     4     2     5     6     1     1     2     6     2     1</span></span>
<span id="cb2-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 6     6     6     4     6     4     6     6     3     6     5     3     4     1</span></span></code></pre></div></div>
</div>
<p>Die jeweiligen Itemsets werden nun zur einem Wert (Gesamtscore) zusammengefasst, in dem wir jeweils den Mittelwert von <code>AS1</code>-<code>AS6</code> und <code>BS1</code>-<code>BS5</code> bildenund in <code>AS</code> bzw. <code>BS</code> speichern:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Wir fassen nun die AS1-AS6 und die BS1-BS5 zusammen </span></span>
<span id="cb3-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># und bilden die jeweiligen Mittelwerte:</span></span>
<span id="cb3-3">testdaten_korrigiert <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(ID, sex) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Damit wird für jede Zeile die Zusammenfassung gemacht!</span></span>
<span id="cb3-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb3-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">AS =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(AS1, AS2, AS3, AS4, AS5, AS6)),</span>
<span id="cb3-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">BS =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(BS1, BS2, BS3, BS4, BS5))</span>
<span id="cb3-8">    ) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> testdaten_sum</span>
<span id="cb3-9"></span>
<span id="cb3-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Ausgabe der Mittelwerte der AS und BS</span></span>
<span id="cb3-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(testdaten_sum)</span>
<span id="cb3-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; # A tibble: 6 × 4</span></span>
<span id="cb3-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; # Groups:   ID [6]</span></span>
<span id="cb3-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      ID   sex    AS    BS</span></span>
<span id="cb3-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   &lt;int&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt;</span></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1     1     2  4.33   3.2</span></span>
<span id="cb3-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2     2     1  4      2.6</span></span>
<span id="cb3-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 3     3     1  3.33   2.8</span></span>
<span id="cb3-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 4     4     1  4.33   3  </span></span>
<span id="cb3-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 5     5     1  3.5    2.4</span></span>
<span id="cb3-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 6     6     1  5.33   4.2</span></span></code></pre></div></div>
</div>
<p>Die Datentabelle <code>testdaten_sum</code> enthält nun die Spalten <code>AS</code> und <code>BS</code> mit den entsprechenden Mittelwerten der einzelnen Items <code>AS1</code>-<code>AS6</code> sowieso <code>BS1</code>- <code>BS5</code>.</p>
<p>Wir wollen nun die Ergebnisse als Boxplots anzeigen lassen. Dafür benennen wir die Geschlechter von 1,2 auf “Frau”, “Mann” um:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">testdaten_sum <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sex =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(sex, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb4-3">                             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Frau"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mann"</span>))</span>
<span id="cb4-4">    ) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> testdaten_sex </span></code></pre></div></div>
</div>
<p>Nun können wir die Boxplots erstellen:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Darstellung der Ergebnisse als Boxplot AS ~ sex:</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_boxplot</span>(AS <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> sex, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> testdaten_sex) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_labs</span>(</span>
<span id="cb5-4">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Boxplot von AS nach Geschlechtern"</span>,</span>
<span id="cb5-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Geschlechter"</span>,</span>
<span id="cb5-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Item AS"</span></span>
<span id="cb5-7">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_refine</span>(</span>
<span id="cb5-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(</span>
<span id="cb5-10">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, </span>
<span id="cb5-11">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb5-12">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Gibt den Bereich von 2.5 bis 4.5 aus!</span></span>
<span id="cb5-13">    )  </span>
<span id="cb5-14">  )</span>
<span id="cb5-15"></span>
<span id="cb5-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Darstellung der Ergebnisse als Boxplot BS ~ sex:</span></span>
<span id="cb5-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_boxplot</span>(BS <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> sex, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> testdaten_sex) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_labs</span>(</span>
<span id="cb5-19">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Boxplot von BS nach Geschlechtern"</span>,</span>
<span id="cb5-20">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Geschlechter"</span>,</span>
<span id="cb5-21">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Item BS"</span></span>
<span id="cb5-22">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gf_refine</span>(</span>
<span id="cb5-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(</span>
<span id="cb5-25">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, </span>
<span id="cb5-26">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb5-27">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Gibt den ganzen Bereich von 1 bis 6 aus!</span></span>
<span id="cb5-28">    )  </span>
<span id="cb5-29">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/index_files/figure-html/unnamed-chunk-5-1.webp" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/index_files/figure-html/unnamed-chunk-5-2.webp" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
</div>
<p>Die Kennzahlen dazu erhalten wir mit <code>favstats</code>. Dabei wählen wir die ersten sechs Einträge (Variabelbezeichnung und Q0 bis Q4) aus:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">favstats</span>(AS <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> sex, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> testdaten_sex)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]</span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    sex      min       Q1   median       Q3      max</span></span>
<span id="cb6-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1 Frau 2.166667 3.333333 3.666667 4.166667 5.333333</span></span>
<span id="cb6-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2 Mann 3.666667 4.000000 4.333333 4.333333 4.500000</span></span>
<span id="cb6-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">favstats</span>(BS <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> sex, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> testdaten_sex)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]</span>
<span id="cb6-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    sex min  Q1 median  Q3 max</span></span>
<span id="cb6-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1 Frau 2.4 2.8    3.4 4.2 4.6</span></span>
<span id="cb6-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2 Mann 2.6 3.2    3.3 3.8 4.2</span></span></code></pre></div></div>
</div>
<p>Unter der Verwendung des Pakets <code>likert</code> (https://github.com/jbryer/likert) können wir die Ausgaben auch noch etwas schöner gestalten:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(likert)</span>
<span id="cb7-2"></span>
<span id="cb7-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Wir wählen nur den Itemset BS aus und speichern in in items2:</span></span>
<span id="cb7-4">testdaten_korrigiert <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(</span>
<span id="cb7-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">starts_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BS"</span>)</span>
<span id="cb7-7">  ) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> items2</span>
<span id="cb7-8"></span>
<span id="cb7-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Leider mag likert tibbels nicht so gerne, daher:</span></span>
<span id="cb7-10">items2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>(items2)</span>
<span id="cb7-11"></span>
<span id="cb7-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Wir geben den Items noch ein paar Buzzwords:</span></span>
<span id="cb7-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(items2) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Gesundheit"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Familie"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Geld"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Freunde"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Langes Leben"</span>)</span>
<span id="cb7-14"></span>
<span id="cb7-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Vorbereitung:</span></span>
<span id="cb7-16">l2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">likert</span>(items2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nlevels =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb7-17"></span>
<span id="cb7-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Zusammenfassung</span></span>
<span id="cb7-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(l2)</span>
<span id="cb7-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;           Item      low   neutral     high     mean       sd</span></span>
<span id="cb7-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 3         Geld 28.57143 23.809524 47.61905 3.380952 1.359272</span></span>
<span id="cb7-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 5 Langes Leben 57.14286  4.761905 38.09524 2.619048 1.532194</span></span>
<span id="cb7-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1   Gesundheit 38.09524 28.571429 33.33333 2.857143 1.492840</span></span>
<span id="cb7-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2      Familie 38.09524 28.571429 33.33333 2.952381 1.499206</span></span>
<span id="cb7-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 4      Freunde 42.85714 23.809524 33.33333 2.857143 1.236354</span></span>
<span id="cb7-26"></span>
<span id="cb7-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Graphische Ausgaben:</span></span>
<span id="cb7-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(l2)</span>
<span id="cb7-29"></span>
<span id="cb7-30"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(l2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bar"</span>)</span>
<span id="cb7-31"></span>
<span id="cb7-32"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(l2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"heat"</span>)</span>
<span id="cb7-33"></span>
<span id="cb7-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(l2,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"density"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/index_files/figure-html/unnamed-chunk-7-1.webp" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/index_files/figure-html/unnamed-chunk-7-2.webp" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/index_files/figure-html/unnamed-chunk-7-3.webp" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/index_files/figure-html/unnamed-chunk-7-4.webp" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
</div>
<p>Voilà!</p>



 ]]></description>
  <category>Statistik</category>
  <guid>https://www.sefiroth.de/posts/2021-06-27-datenjudo-fuer-frageboegen/</guid>
  <pubDate>Sat, 26 Jun 2021 22:00:00 GMT</pubDate>
</item>
</channel>
</rss>
