{ "cells": [ { "cell_type": "markdown", "id": "30b22730", "metadata": {}, "source": [ "# Clutering Evalutation\n", "\n", "\n", "Today, we will learn how to evaluate if a clustering model was effective or not. In the process, we will also learn how to determine if we have the right number of clusters." ] }, { "cell_type": "code", "execution_count": 1, "id": "76bf2492", "metadata": {}, "outputs": [], "source": [ "import seaborn as sns\n", "from sklearn import datasets\n", "from sklearn.cluster import KMeans\n", "from sklearn import metrics\n", "import pandas as pd" ] }, { "cell_type": "markdown", "id": "2ed28959", "metadata": {}, "source": [ "Extract out the features to `iris_X`" ] }, { "cell_type": "code", "execution_count": 2, "id": "4dfc2b76", "metadata": {}, "outputs": [], "source": [ "iris_df = sns.load_dataset('iris')\n", "iris_X = iris_df.drop(columns=['species'])" ] }, { "cell_type": "markdown", "id": "5743a6da", "metadata": {}, "source": [ "First we will fit the model with the correct number of clusters." ] }, { "cell_type": "code", "execution_count": 3, "id": "f9845d3c", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/sklearn/cluster/_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning\n", " warnings.warn(\n" ] }, { "data": { "text/html": [ "
KMeans(n_clusters=3)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
KMeans(n_clusters=3)
KMeans(n_clusters=4)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
KMeans(n_clusters=4)