{ "cells": [ { "cell_type": "raw", "metadata": {}, "source": [ "---\n", "title: Visualising the Iris dataset with Seaborn\n", "lang: en\n", "author: AM\n", "format:\n", " html:\n", " code-fold: false\n", "---" ], "id": "cfbc628f" }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load packages" ], "id": "3ebfb078" }, { "cell_type": "code", "execution_count": 38, "outputs": [], "source": [ "import seaborn as sns\n", "import pandas as pd\n", "from matplotlib import pyplot as plt\n", "from sklearn.datasets import load_iris" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "# Load Iris from sklearn and rename columns as in the exercise notebook\n", "URL for sklearn load_iris: [load_iris documentation](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html)\n", "More info for sklearn load_iris: [load_iris metadata](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html)" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "metadata": {}, "source": [ "# Dictionary with column renaming\n", "renaming_dict = {\n", " \"sepal length (cm)\": \"SepalLengthCm\",\n", " \"sepal width (cm)\": \"SepalWidthCm\",\n", " \"petal length (cm)\": \"PetalLengthCm\",\n", " \"petal width (cm)\": \"PetalWidthCm\",\n", "}\n", "\n", "# Check load_iris documentation\n", "iris_df, iris_y = load_iris(return_X_y=True, as_frame=True)\n", "iris_df = iris_df.rename(columns=renaming_dict)" ], "id": "0327aa15", "execution_count": 39, "outputs": [] }, { "cell_type": "markdown", "source": [ "# Remap class names from integers to strings" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "markdown", "source": [ "Pandas Series map documentation: [pandas.Series.map](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.map.html)" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": 40, "outputs": [ { "data": { "text/plain": " SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species\n0 5.1 3.5 1.4 0.2 Iris-setosa\n1 4.9 3.0 1.4 0.2 Iris-setosa\n2 4.7 3.2 1.3 0.2 Iris-setosa\n3 4.6 3.1 1.5 0.2 Iris-setosa\n4 5.0 3.6 1.4 0.2 Iris-setosa\n.. ... ... ... ... ...\n145 6.7 3.0 5.2 2.3 Iris-virginica\n146 6.3 2.5 5.0 1.9 Iris-virginica\n147 6.5 3.0 5.2 2.0 Iris-virginica\n148 6.2 3.4 5.4 2.3 Iris-virginica\n149 5.9 3.0 5.1 1.8 Iris-virginica\n\n[150 rows x 5 columns]", "text/html": "
\n | SepalLengthCm | \nSepalWidthCm | \nPetalLengthCm | \nPetalWidthCm | \nSpecies | \n
---|---|---|---|---|---|
0 | \n5.1 | \n3.5 | \n1.4 | \n0.2 | \nIris-setosa | \n
1 | \n4.9 | \n3.0 | \n1.4 | \n0.2 | \nIris-setosa | \n
2 | \n4.7 | \n3.2 | \n1.3 | \n0.2 | \nIris-setosa | \n
3 | \n4.6 | \n3.1 | \n1.5 | \n0.2 | \nIris-setosa | \n
4 | \n5.0 | \n3.6 | \n1.4 | \n0.2 | \nIris-setosa | \n
... | \n... | \n... | \n... | \n... | \n... | \n
145 | \n6.7 | \n3.0 | \n5.2 | \n2.3 | \nIris-virginica | \n
146 | \n6.3 | \n2.5 | \n5.0 | \n1.9 | \nIris-virginica | \n
147 | \n6.5 | \n3.0 | \n5.2 | \n2.0 | \nIris-virginica | \n
148 | \n6.2 | \n3.4 | \n5.4 | \n2.3 | \nIris-virginica | \n
149 | \n5.9 | \n3.0 | \n5.1 | \n1.8 | \nIris-virginica | \n
150 rows × 5 columns
\n