\documentclass{beamer}
% \documentclass[handout]{beamer}

\usetheme{dcc}

\usepackage[utf8]{inputenc}
\usepackage[american]{babel}

\newcommand{\ie}{i.\,e.}
\newcommand{\Ie}{I.\,e.}
\newcommand{\eg}{e.\,g.}
\newcommand{\Eg}{E.\,g.}

\title{Mineração de Dados Aplicada}
\subtitle{Clustering}

\author{Loïc Cerf}

\date{May 7th 2025}

\institute
{
  \scriptsize
  DCC -- ICEx -- UFMG
  \bigskip\\
  \includegraphics[width=.334113288\linewidth]{images/dcc}\hfill\includegraphics[width=.5\linewidth]{images/ufmg}
}

\subject{Clustering}

\keywords{clustering, hierarchical clustering, k-means, EM, fuzzy
  c-means, DBSCAN, spectral clustering}

\hypersetup{pdfpagemode=FullScreen}

\AtBeginSection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}[plain]
  \titlepage
\end{frame}

\begin{frame}
  \frametitle{Example of application}
  \begin{exampleblock}{Student profiles}
    Given the marks students received for different courses, group the
    students so that two students in a same group received about the
    same marks for each course and two students in different groups
    have different profiles.
  \end{exampleblock}
\end{frame}

\begin{frame}
  \frametitle{Outline}
  \tableofcontents
\end{frame}

\section{Definition}

\begin{frame}
  \frametitle{An optimization problem}
  \begin{definition}
    Partitioning the objects \only<1>{into clusters so that each
      cluster contains \emph{similar} objects and objects in different
      clusters are \emph{dissimilar}}\only<2->{so that the
      \emph{intra-cluster similarities} are maximized and the
      \emph{inter-cluster similarities} are minimized}.
  \end{definition}

  \vfill

  \only<-2>
  {
    Input:\\
    \begin{displaymath}
      \begin{array}{c|cccc}
        & a_1 & a_2 & \dots & a_n\\
        \hline
        o_1 & d_{1, 1} & d_{1, 2} & \dots & d_{1, n}\\
        o_2 & d_{2, 1} & d_{2, 2} & \dots & d_{2, n}\\
        \vdots & \vdots & \vdots & \ddots & \vdots\\
        o_m & d_{m, 1} & d_{m, 2} & \dots & d_{m, n}
      \end{array}
    \end{displaymath}
  }\only<3>
  {
    Output:\\
    \begin{displaymath}
      \begin{array}{c|ccccc}
        & a_1 & a_2 & \dots & a_n & \alert{\text{cluster}}\\
        \hline
        o_1 & d_{1, 1} & d_{1, 2} & \dots & d_{1, n} & \alert{c_1}\\
        o_2 & d_{2, 1} & d_{2, 2} & \dots & d_{2, n} & \alert{c_2}\\
        \vdots & \vdots & \vdots & \ddots & \vdots & \vdots\\
        o_m & d_{m, 1} & d_{m, 2} & \dots & d_{m, n} & \alert{c_m}
      \end{array}
    \end{displaymath}
  }
\end{frame}

\begin{frame}
  \frametitle{Illustration}
  Clustering objects, described with two attributes of the interval
  type, using the Euclidean distance.

  \vfill

  \begin{columns}
    \begin{column}{.33\linewidth}
      \begin{displaymath}
        \begin{array}{c|cc}
          & x & y\\
          \hline
          \only<3->{\color{yellow}} o_1 & 91 & 70\\
          \only<3->{\color{yellow}} o_2 & 129 & 91\\
          \only<3->{\color{red}} o_3 & 359 & 243\\
          \only<3->{\color{red}} o_4 & 322 & 254\\
          \only<3->{\color{yellow}} o_5 & 100 & 104\\
          \only<3->{\color{blue}} o_6 & 464 & 113\\
          \only<3->{\color{red}} o_7 & 342 & 297\\
          \only<3->{\color{blue}} o_8 & 410 & 65\\
          \only<3->{\color{red}} o_9 & 334 & 329\\
          \vdots & \vdots & \vdots
        \end{array}
      \end{displaymath}
    \end{column}
    \begin{column}{.66\linewidth}
      \only<2>{\includegraphics[width=\linewidth]{img/clustering_small_bw}}\only<3>{\includegraphics[width=\linewidth]{img/clustering_small}}\only<4>{\includegraphics[width=\linewidth]{img/clustering}}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Inductive database formalism}
  Querying \only<1>{patterns}\only<2->{\alert{a clustering}}:

  \begin{displaymath}
    \{X \in P \mid \mathcal{Q}(X, \mathcal{D})\}
  \end{displaymath}
  where:
  \begin{itemize}
  \item $\mathcal{D}$ is \only<-2>{the dataset}\only<3->{\alert<3>{a
        set of objects $\mathcal{O}$ together with a similarity
        measure}},
  \item $P$ is \only<-3>{the pattern
      space}\only<4->{\alert<4>{$\{(C_1, \dots, C_k) \in
        (2^{\mathcal{O}})^k \mid \begin{cases}
          \forall \ell \in \{1, \dots, k\}, C_{\ell} \neq \emptyset\\
          \forall m \neq \ell, C_{\ell} \cap C_m \neq \emptyset\\
          \cup_{\ell = 1}^k C_{\ell} = \mathcal{O}
        \end{cases}\}$}},
  \item $\mathcal{Q}$ is \only<-4>{an inductive
      query}\only<5->{\alert<5>{the simultaneous maximization of the
        intra-cluster similarities and minimization of the
        inter-cluster similarities, a trade-off}}.
  \end{itemize}

  \vfill

  \uncover<6>{Variants exist, \eg, allowing some overlapping of the
    clusters.}
\end{frame}

\begin{frame}
  \frametitle{Inexactness}
  Every object influences the clustering and the number of ways to
  partition $|\mathcal{O}|$ objects in $k \in \mathbb{N}$ clusters is
  huge: $O\left(\frac{k^{|\mathcal{O}|}}{k!}\right)$.

  \vfill
  \pause

  That is why clustering is usually solved in an \emph{inexact} way.

  \vfill
  \pause

  \emph{Domain decomposition} consists of using a cheap clustering
  method to get coarse clusters that other clustering algorithms can
  independently process in a second step.
\end{frame}

\section{Classical algorithms}

\begin{frame}
  \frametitle{Hierarchical agglomeration: illustration}
  (Agglomerative) hierarchical clustering of objects described with
  two attributes of the interval type, using the Euclidean distance.

  \vfill

  \begin{columns}
    \begin{column}{.33\linewidth}
      \begin{displaymath}
        \begin{array}{c|cc}
          & x & y\\
          \hline
          o_1 & 91 & 70\\
          o_2 & 129 & 91\\
          o_3 & 359 & 243\\
          o_4 & 322 & 254\\
          o_5 & 100 & 104\\
          o_6 & 464 & 113\\
          o_7 & 342 & 297\\
          o_8 & 410 & 65\\
          o_9 & 334 & 329\\
          \vdots & \vdots & \vdots
        \end{array}
      \end{displaymath}
    \end{column}
    \begin{column}{.66\linewidth}
      \includegraphics[width=\linewidth]{img/clustering_bw}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Dendrogram}
  \begin{center}
    \includegraphics[width=\linewidth]{img/dendrogram}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Distance}
  \begin{center}
    \includegraphics[width=\linewidth]{img/HC_distance}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Hierarchical agglomeration: algorithm}
  A \alert<4>{greedy} algorithm:
  \begin{enumerate}[<+->]
  \item Initialize the clusters with the individual objects;
  \item At each iteration, \alert<5>{agglomerate} the two
    \alert<6,7>{closest} clusters;
  \item Stop when the \alert<8,9>{desired number of clusters} is
    reached.
  \end{enumerate}

  \vfill

  \begin{itemize}
  \item \uncover<4->{\alert<4>{No guarantee whatsoever on the
        optimality of the solution};}
  \item \uncover<5->{\alert<5>{The clusters are hierarchically
        organized};}
  \item \uncover<6->{\alert<6,10>{Choice of a similarity between
        clusters (\emph{sets} of objects)};}
  \item \uncover<7->{\alert<7,10>{Quadratic or cubic time complexity
        in the number of objects};}
  \item \uncover<8->{\alert<8>{The process should stop before
        agglomerating dissimilar clusters (but the number of clusters
        can be determined \emph{a posteriori})};}
  \item \uncover<9->{\alert<9>{Outlier detection (single-object
        cluster far away from other clusters)}.}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Linkage criteria}
  The similarity between two clusters can be defined as:
  \begin{description}[<+->]
  \item[Complete linkage] the lowest similarity between any pair of
    objects taken from the two clusters;
  \item[Single linkage] the highest similarity between any pair of
    objects taken from the two clusters;
  \item[Group average linkage] the average similarity over all pairs
    of objects taken from the two clusters.
  \end{description}
  to provide:
  \begin{description}
  \item[Complete linkage] spherical clusters of approximately equal
    diameters (clustering computed in $O(|\mathcal{O}|^2)$ time);
    \uncover<2->{\item[Single linkage] ``chains'' of similar objects
      (clustering computed in $O(|\mathcal{O}|^2)$ time);}
    \uncover<3>{\item[Group average linkage] the most natural linkage
      (clustering computed in $O(|\mathcal{O}|^{\alert{3}})$ time).}
  \end{description}
\end{frame}

\begin{frame}
  \frametitle{Divisive hierarchical clustering}
  All objects are initially in one single cluster.  Every cluster is
  recursively split into two until every object is alone in a cluster.

  \vfill
  \pause

  Finding the best split takes exponential time.  That is why a split
  is usually find in an approximate way, \eg, using $2$-means.
\end{frame}

\begin{frame}
  \frametitle{$k$-means: illustration}
  (Using the Euclidean distance,) $3$-means clustering of objects
  described with two attributes of the interval type.

  \vfill

  \begin{columns}
    \begin{column}{.33\linewidth}
      \begin{displaymath}
        \begin{array}{c|cc}
          & x & y\\
          \hline
          o_1 & 91 & 70\\
          o_2 & 129 & 91\\
          o_3 & 359 & 243\\
          o_4 & 322 & 254\\
          o_5 & 100 & 104\\
          o_6 & 464 & 113\\
          o_7 & 342 & 297\\
          o_8 & 410 & 65\\
          o_9 & 334 & 329\\
          \vdots & \vdots & \vdots
        \end{array}
      \end{displaymath}
    \end{column}
    \begin{column}{.66\linewidth}
      \includegraphics[width=\linewidth]{img/clustering_bw}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{$k$-means: algorithm}
  Seeking the centers of \alert<5>{$k$ clusters} by
  \alert<6>{expectation-maximization}:
  \begin{enumerate}[<+->]
  \item Randomly choose $k$ centers $\mu_1$, \dots, $\mu_k$ in the
    object space;
  \item Until convergence or a specified maximal number of iterations:
  \item[E] \alert<7-9>{Assign each object to the cluster $C_{\ell}$
      with the closest center $\mu_{\ell}$};
  \item[M] \alert<7-9>{Update the center $\mu_{\ell}$ of each cluster
      to the mean of the objects assigned to it}.
  \end{enumerate}

  \vfill

  \begin{itemize}
  \item \uncover<5->{\alert<5,10>{The number $k$ of clusters must be
        guessed beforehand};}
  \item \uncover<6->{\alert<6>{\emph{Locally} minimizes
        $\sum_{\ell = 1}^k \sum_{o \in C_{\ell}} \|o -
        \mu_{\ell}\|^2$};}
  \item \uncover<7->{\alert<7>{Spherical clusters of approximately
        equal diameters};}
  \item \uncover<8->{\alert<8>{Linear time complexity in the number of
        objects, attributes, clusters and iterations (small in
        practice)};}
  \item \uncover<9->{\alert<9>{Sensitive to outliers, which should be
        removed beforehand}.}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{The elbow method}
  Plot in function of $k$ a measure of the quality of the clustering,
  \eg, $\sum_{\ell = 1}^k \sum_{o \in C_{\ell}} \|o - \mu_{\ell}\|^2$
  that $k$-means locally minimizes. Choose $k$ after a large drop.

  \vfill
  \pause

  More principled methods exist, \eg, finding the best trade-off
  between quality and compression.

  \vfill
  \pause

  No such method is implemented in KNIME. If the time complexity of a
  hierarchical agglomeration (using a complete linkage for
  similarly-shaped clusters) is not prohibitive, the number of
  clusters can be chosen from the dendrogram.  Outliers can be
  identified (and removed) in this way too.
\end{frame}

\begin{frame}
  \frametitle{$k$-medoids}
  $k$-medoids is $k$-means but defining the center $\mu_{\ell}$ of
  $C_{\ell}$ as its object maximizing the sum of the similarities to
  its other objects.

  \vfill
  \pause

  Similarly to $k$-means, $k$-medoids:
  \begin{itemize}
  \item requires the number $k$ of clusters to be guessed beforehand;
  \item \emph{locally} maximizes
    $\sum_{\ell = 1}^k \sum_{o \in C_{\ell}} s(o, \mu_{\ell})$;
  \item \alert<4>{produces spherical clusters of approximately equal
      diameters}.
  \end{itemize}

  \vfill
  \pause

  Unlike $k$-means, $k$-medoids:
  \begin{itemize}
  \item elects an existing object to represent the cluster;
  \item is robust to outliers;
  \item has a run time quadratically increasing with the number of
    objects.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Tendency to produce equi-sized clusters}
  \includegraphics[width=\linewidth]{img/mouse}
\end{frame}

\begin{frame}
  \frametitle{EM}
  The dataset $\mathcal{D}$ is seen as a random sample (\ie,
  independent and identically distributed) from an
  $|\mathcal{A}|$-dimensional random variable $O$ whose probability
  density function is given as a mixture model of the $k$ clusters.

  \vfill
  \pause

  EM searches, by expectation-maximization, a parametrization of the
  model that locally maximizes the likelihood that $\mathcal{D}$ is
  indeed a random sample of $O$.

  \vfill
  \pause

  The distribution of a cluster is usually assumed multivariate
  normal, thus parametrized with a \emph{location} (the center of the
  cluster) and a \emph{covariance matrix}.
\end{frame}

\begin{frame}
  \frametitle{EM with $|\mathcal{A}| = 1$ and $k = 2$: illustration}
  EM clustering of objects described with one single attribute.

  \vfill

  \only<1>{Dataset}\only<2>{Iteration 1}\only<3>{Iteration 5}:\\

  \medskip

  \only<1>{\includegraphics[width=\linewidth]{img/1D-EM_it0}}\only<2>{\includegraphics[width=\linewidth]{img/1D-EM_it1}}\only<3>{\includegraphics[width=\linewidth]{img/1D-EM_it5}}
\end{frame}

\begin{frame}
  \frametitle{$k$-means specializes EM}
  $k$-means specializes EM:
  \begin{description}[<+->]
  \item[EM] the probability of a cluster given an object weights the
    contribution of the object to the cluster;
  \item[$k$-means] that probability is $1$ for the cluster with the
    closest center, $0$ for the other clusters.
  \end{description}

  \vfill

  \uncover<3>
  {
    Like $k$-means, EM:
    \begin{itemize}
    \item requires the number of clusters to be guessed beforehand;
    \item \emph{locally} optimizes the objective function, the
      likelihood (\ie, the probability of the data given the mixture
      model);
    \item is sensitive to outliers, which should be removed beforehand.
    \end{itemize}
  }
\end{frame}

\begin{frame}
  \frametitle{$k$-means vs. EM}
  $k$-means produces spherical clusters of approximately equal
  diameters, whereas EM produces ellipsoidal clusters of any sizes.

  \vfill
  \pause

  $k$-means is faster than EM: using a Gaussian mixture, EM's
  estimation of the $k\frac{|\mathcal{A}|^2 + 3|\mathcal{A}|}{2}$ real
  parameters (vs. $k|\mathcal{A}|$ for $k$-means) requires more
  iterations and every iteration takes
  $O(k|\mathcal{O}||\mathcal{A}|^2)$ time
  (vs. $O(k|\mathcal{O}||\mathcal{A}|)$ for $k$-means).

  \vfill
  \pause

  The covariances can be fixed to $0$ (diagonal covariance matrices)
  so that EM only estimates and uses $2k|\mathcal{A}|$ real
  parameters, hence a reduced run time... and quality.
\end{frame}

\begin{frame}
  \frametitle{EM with full covariance matrices}
  \includegraphics[width=\linewidth]{img/full_EM}
\end{frame}

\begin{frame}
  \frametitle{EM with diagonal covariance matrices}
  \includegraphics[width=\linewidth]{img/diagonal_EM}
\end{frame}

\begin{frame}
  \frametitle{Fuzzy $c$-means}
  Fuzzy $c$-means generalizes $k$-means.  Every object belongs to
  every cluster to a certain degree, increasing with the similarity to
  the center.  A hyperparameter controls how fast the degrees
  increase.  When it tends to 1, fuzzy $c$-means tends to
  $k$-means. The maximization step becomes the computation of a
  weighted mean.

  \vfill
  \pause

  Fuzzy $c$-means associates every object with degrees of membership
  to every cluster, whereas EM uses probabilities.  Besides that, it
  has the same advantages and drawbacks as $k$-means.

  \vfill
  \pause

  By default, EM is not included in KNIME. Fuzzy $c$-means is.
\end{frame}

\begin{frame}
  \frametitle{Non-convex clusters (\only<2>{kernel }$3$-means)}
  \begin{center}
    \only<1>{\includegraphics[width=\linewidth]{img/k-means}}\only<2>{\includegraphics[width=\linewidth]{img/kernel-k-means}}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Kernel $k$-means and spectral clustering}
  \begin{alertblock}{Problem}
    $k$-means, EM and fuzzy $c$-means only find convex clusters.
  \end{alertblock}

  \vfill
  \pause

  \begin{block}{Ideas}
    \begin{description}
    \item[Kernel methods] Using a nonlinear function, the objects are
      mapped to a higher-dimensional space where the clusters
      hopefully become convex;
    \item[Spectral methods] Mapping the objects to a space whose base
      is the eigenvectors of an affinity matrix.
    \end{description}
  \end{block}

  \vfill
  \pause

  Both families of methods are related.
\end{frame}

\begin{frame}
  \frametitle{Kernel $k$-means}
  Given, \emph{conceptually}, a nonlinear mapping $\Phi$ of the
  objects to a higher-dimensional space, kernel $k$-means is $k$-means
  in this space.

  \vfill
  \pause

  Knowing the scalar product $\kappa(o, \mu_{\ell}) = \Phi(o) \cdot
  \Phi(\mu_{\ell})$ is enough to compute $\|\Phi(o) -
  \Phi(\mu_{\ell})\|^2$, \ie, $\Phi$ needs not be applied. $\kappa$ is
  a continuous, symmetric and semi-definite function:
  \begin{description}
  \item[Polynomial kernel] $\kappa(o, \mu_{\ell}) = (o \cdot
    \mu_{\ell} + a)^b$;
  \item[Gaussian kernel] $\kappa(o, \mu_{\ell}) = e^{-\frac{o \cdot
        \mu_{\ell}}{2\sigma^2}}$;
  \item[Sigmoid kernel] $\kappa(o, \mu_{\ell}) = \tanh(a(o \cdot
    \mu_{\ell}) + \theta)$;
  \item[...]
  \end{description}
\end{frame}

\begin{frame}
  \frametitle{Normalized cut (a spectral clustering)}
  \begin{definition}
    \only<1>{Removing from the (non-negative and symmetric) similarity
      graph the edges with a small total weight so that $k$
      ``reasonably large'' connected components are
      obtained}\only<2->{Approximately compute the partitioning $(C_1,
      \dots, C_k) \in (2^{\mathcal{O}})^k$ that minimizes $\sum_{\ell
        = 1}^k \frac{\sum_{o_i \in C_{\ell}, o_j \in \mathcal{O}
          \setminus C_{\ell}} s(o_i, o_j)}{\sum_{o_i \in C_{\ell}, o_j
          \in \mathcal{O}} s(o_i, o_j)}$}.
  \end{definition}

  \vfill

  \uncover<3->
  {
    \begin{block}{Method}
      Extract the eigenvectors of an affinity matrix, \eg, the
      normalized Laplacian of the similarity matrix. Cluster the
      objects rewritten w.r.t. those relating to the smallest
      eigenvalues, but the first.
    \end{block}
  }

  \vfill

  \uncover<4>
  {
    \begin{block}{Time complexity}
      Spectral clustering takes $O(|\mathcal{O}|^3)$ time, dominated
      by the computation of the eigenvectors of the (dense) affinity
      matrix.
    \end{block}
  }
\end{frame}

\begin{frame}
  \frametitle{Assignment of new objects to clusters}
  (Kernel) $k$-means, EM and fuzzy $c$-means explicitly model every
  cluster with a center (and a covariance matrix for EM).

  \vfill
  \pause

  As a consequence, a new object can be assigned to the most probable
  cluster.  In KNIME, ``Cluster Assigner'' does so.

  \vfill
  \pause

  The completed clustering is usually not a local extremum of the
  objective function.
\end{frame}

\begin{frame}
  \frametitle{DBSCAN: illustration}
  DBSCAN clustering of objects described with two attributes of the
  interval type, using the Euclidean distance.

  \vfill

  \begin{columns}
    \begin{column}{.33\linewidth}
      \begin{displaymath}
        \begin{array}{c|cc}
          & x & y\\
          \hline
          o_1 & 91 & 70\\
          o_2 & 129 & 91\\
          o_3 & 359 & 243\\
          o_4 & 322 & 254\\
          o_5 & 100 & 104\\
          o_6 & 464 & 113\\
          o_7 & 342 & 297\\
          o_8 & 410 & 65\\
          o_9 & 334 & 329\\
          \vdots & \vdots & \vdots
        \end{array}
      \end{displaymath}
    \end{column}
    \begin{column}{.66\linewidth}
      \includegraphics[width=\linewidth]{img/clustering_bw}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{DBSCAN: algorithm}
  A density-based algorithm:
  \begin{enumerate}[<+->]
  \item At each iteration, choose an unlabeled object;
  \item \alert<7>{List the \alert<5>{sufficiently} \alert<6>{similar}
      objects};
  \item If there are \alert<5>{too few} of them, label the object as
    \alert<8>{outlier};
  \item Otherwise cluster these objects as well as those listed by the
    same \alert<9>{recursive process applied to the newly clustered
      objects}.
  \end{enumerate}

  \vfill

  \begin{itemize}
  \item \uncover<5->{\alert<5>{One single user-defined density
        threshold for all clusters (OPTICS addresses this problem)};}
  \item \uncover<6->{\alert<6>{Choice of a similarity (shape of the
        clusters)};}
  \item \uncover<7->{\alert<7>{$O(|\mathcal{O}|^2)$ worst-case time
        complexity, but $O(|\mathcal{O}| \log |\mathcal{O}|)$ in
        average, using a spatial index};}
  \item \uncover<8->{\alert<8>{Outlier detection};}
  \item \uncover<9->{\alert<9>{Single-linkage like}.}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Configuration}
  Configuring data mining algorithms is hard.  It often relies on
  sampling in the hyperparameter space and keeping the \alert<2>{best
    output}.  Metaheuristics can be used too.

  \vfill

  Nevertheless, understanding the various algorithms and the effect of
  their hyperparameters helps.
\end{frame}

\section{Assessing a clustering}

\begin{frame}
  \frametitle{An unsupervised task}
  Clustering aims to discover a \emph{hidden organization} of the
  objects: it is \emph{unsupervised}.

  \vfill
  \pause

  As a consequence, there are only \emph{intrinsic} measures of the
  quality of a clustering.
\end{frame}

\begin{frame}
  \frametitle{Intra and inter-cluster similarities}
  Given one cluster, the intra-cluster similarity can be defined as:
  \begin{itemize}[<+->]
  \item the minimal similarity between two objects in the cluster;
  \item the average similarity between two objects in the cluster;
  \item the average similarity to the center of the cluster.
  \end{itemize}

  \vfill

  Given two clusters, the inter-cluster similarity can be defined as:
  \begin{itemize}
  \item \uncover<1->{the maximal similarity between objects in the two
      clusters;}
  \item \uncover<2->{the average similarity between objects in the two
      clusters;}
  \item \uncover<3>{the similarity between the centers of the two
      clusters.}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Internal evaluation}
  \begin{description}[<+->]
  \item[BetaCV] the ratio of the average intra-cluster similarity to
    the average inter-cluster similarity;
  \item[Dunn] the ratio of the minimal intra-cluster similarity to the
    maximal inter-cluster similarity;
  \item[Davies-Bouldin] the average similarity between each cluster
    and its most similar one (minimal ratio of the sum of the two
    intra-cluster similarities to their inter-cluster similarity),
    averaged over all the clusters;
  \item[Silhouette] \emph{for each object}, the difference between the
    average similarity to the objects in the same cluster and the
    greatest average similarity to the objects in another cluster
    divided by the greatest term.
  \end{description}

  \vfill

  \uncover<5>{KNIME only provides a node for the silhouette
    coefficient.}
\end{frame}

\begin{frame}
  \frametitle{Comparing clusterings}
  A quality measure can compared to that of another clustering:
  \begin{description}[<+->]
  \item[of the same dataset] to select the best clustering;
  \item[of a randomized version of the dataset] to have an information
    about the tendency of the objects to be clustered.
  \end{description}
\end{frame}

\begin{frame}
  \frametitle{Randomization of a dataset}
  \begin{columns}
    \begin{column}{.5\linewidth}
      Uniform distribution between the extrema of each attribute:
      \begin{center}
        \includegraphics[width=.75\linewidth]{img/uniform_distribution}
      \end{center}
    \end{column}
    \begin{column}{.5\linewidth}
      Normal distribution parametrized from the dataset:
      \begin{center}
        \includegraphics[width=.75\linewidth]{img/normal_distribution}
      \end{center}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Stability of a clustering}
  If a clustering method involves randomness (\eg, $k$-means), the
  \alert<3>{stability} of its output over several runs is an indicator
  of its quality.

  \vfill
  \pause

  The clustering to keep is the one with the best quality.
\end{frame}

\begin{frame}
  \frametitle{Similarity between two partitions}
  A correlation between nominal attributes (the two partitions)
  measures their similarity.  In KNIME, ``Entropy scorer'' computes
  such a measure, the entropy (the smaller the more correlated).

  \vfill
  \pause

  The Fowlkes-Mallows index and the (adjusted) Rand index are
  alternatives, absent from KNIME.  They count pairs of objects: how
  many are in the same/different cluster(s) in one clustering and in
  the same/different cluster(s) in the other clustering.

  \vfill
  \pause

  Those same measures may help to interpret a clustering, correlating
  it with a nominal attribute that was not used to cluster.
\end{frame}

\section{Case study}

\section{Clustering in KNIME}

\begin{frame}
  \frametitle{Clustering in KNIME}
  \begin{exampleblock}{Practice}
    \begin{enumerate}
    \item After figuring out an appropriate $k$ with a hierarchical
      clustering, cluster, with $k$-means, the bears in
      \texttt{bears.csv} according to their attributes
      \texttt{Headlen}, \texttt{Headwth} and \texttt{Chest}.
    \item Test the stability of $k$-means' clustering.
    \item Does the clustering correlate more with the sex or with the
      age?
    \item Visualize the better correlation.
    \end{enumerate}
  \end{exampleblock}
\end{frame}

\section*{}

\begin{frame}
  \frametitle{License}
  \begin{block}{\copyright 2012--2025 Loïc Cerf}
    \includegraphics[height=1.5ex]{img/licenses/cc-by-sa}\hskip1pt
    These slides are licensed under the Creative Commons
    Attribution-ShareAlike 4.0 International License.
  \end{block}
\end{frame}

\end{document}