{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ein Einfacher Classifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from pandas import Series, DataFrame"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Zunächst laden wir den Iris Datensatz und wählen aus den Iris-Daten lediglich die Klassen `virginica` und `versicolor` aus."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iris = pd.read_csv('data/iris.csv')\n",
    "iris = iris[iris['species'] != 'setosa']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Die folgende Zelle definiert die Funktion `_predict(row)`, die eine Vorhersage auf einer einzelnen Zeile berechnet.\n",
    "\n",
    "Die Funktion `simple_predict` berechnet die Vorhersagen auf einem DataFrame und liefert ein Series Objekt mit den Vorhersagen zurück, dass den gleiche Index nutzt wie der ursprüngliche Datensatz."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def _predict(row):\n",
    "    if row[\"petal_width\"] >= 1.75:\n",
    "        return \"virginica\"\n",
    "    else:\n",
    "        return \"versicolor\"\n",
    "    \n",
    "def simple_predict(X):\n",
    "    return Series([_predict(x) for i,x in X.iterrows()], index=X.index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Vorhersagen Berechnen\n",
    "\n",
    "Als nächstes berechnen wir die Vorhersage auf den Iris-Daten mit unsere `simple_predict` Funktion:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_hat = simple_predict(iris)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Fehler Bestimmen\n",
    "\n",
    "Jetzt sind Sie am Zug!\n",
    "\n",
    "Wie groß ist der relative Fehler von unserem *Simple Classifier* auf dem Iris Datensatz."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
