unsupervised learning

33
Unsupervised Learning Clustering K-Means

Upload: herb

Post on 24-Feb-2016

51 views

Category:

Documents


0 download

DESCRIPTION

Unsupervised Learning. Clustering K-Means. Recall: Key Components of Intelligent Agents. Representation Language: Graph, Bayes Nets, Linear functions Inference Mechanism: A*, variable elimination, Gibbs sampling - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Unsupervised  Learning

Unsupervised Learning

ClusteringK-Means

Page 2: Unsupervised  Learning

Recall: Key Components of Intelligent Agents

Representation Language: Graph, Bayes Nets, Linear functions

Inference Mechanism: A*, variable elimination, Gibbs sampling

Learning Mechanism: Maximum Likelihood, Laplace Smoothing, gradient descent, perceptron, k-Nearest Neighbor, many more: k-means, EM, PCA, …

-------------------------------------Evaluation Metric: Likelihood, quadratic loss (a.k.a. squared error), regularized loss, margins, many more: 0-1 loss, conditional likelihood, precision/recall, …

Page 3: Unsupervised  Learning

Supervised vs. Unsupervised LearningSupervised Learning: “Labeled” Data

X11 X12 … X1N Y1

X21 X22 … X2N Y2

… … … … …

XM1 XM2 … XMN YM

Unsupervised Learning: “Unlabeled” Data

X11 X12 … X1N ?

X21 X22 … X2N ?

… … … … …

XM1 XM2 … XMN ?

In supervised learning, the learning algorithm is given training examples that contain inputs (the X values) and “labels” or “outputs” (the Y values).

In unsupervised learning, the learning algorithm is given training examples that contain inputs (the X values), but no “labels” or “outputs” (no Y values).

It’s called “unsupervised” because there are no “labels” to help “supervise” the learning algorithm during the learning process, to get it to the right model.

Page 4: Unsupervised  Learning

Example Unsupervised Problem 1

Are these data points distributed completely randomly, or do you see some structure in them?

How many clusters do you see?None12345

X1

X 2

Page 5: Unsupervised  Learning

Example Unsupervised Problem 1

Are these data points distributed completely randomly, or do you see some structure in them?

Structured – there are clusters!

How many clusters do you see?None12345

X1

X 2

Page 6: Unsupervised  Learning

Example Unsupervised Problem 2

There are 2 input variables, X1 and X2, in this space. So this is called a “2-dimensional space”.

How many dimensions are actually needed to describe this data?0123

X1

X 2

Page 7: Unsupervised  Learning

Example Unsupervised Problem 2

There are 2 input variables, X1 and X2, in this space. So this is called a “2-dimensional space”.

How many dimensions are actually needed to describe this data?1 dimension captures most of the variation in this data.2 dimensions will capture everything.

X1

X 2

Page 8: Unsupervised  Learning

Types of Unsupervised Learning

Density Estimation- Clustering (Example 1)- Dimensionality Reduction (Example 2)

Factor Analysis- Blind signal separation

Page 9: Unsupervised  Learning

Example Open Problem in AI: Unsupervised Image Segmentation (and Registration)

Examples taken from (Felzenszwab and Huttenlocher, Int. Journal of Computer Vision, 59:2, 2004). http://cs.brown.edu/~pff/segment/.

Page 10: Unsupervised  Learning

The K-Means Clustering Algorithm

Inputs: 1) Some unlabeled (no outputs) training data2) A number K, which must be greater than 1

Output:A label between 1 and K for each data point, indicating which cluster the data point belongs to.

Page 11: Unsupervised  Learning

Visualization of K-Means

Data

Page 12: Unsupervised  Learning

Visualization of K-Means

1. Generate K random initial cluster centers, or “means”.

Page 13: Unsupervised  Learning

Visualization of K-Means

2. Assign each point to the closest “mean” point.

Page 14: Unsupervised  Learning

Visualization of K-Means

2. Assign each point to the closest “mean” point.Visually, the mean points divide the space into a Voronoi diagram.

Page 15: Unsupervised  Learning

Visualization of K-Means

3. Recompute the “mean” (center) of each colored set of data.Notice: “means” do not have to be at the same position as a data point,

although some times they might be.

Page 16: Unsupervised  Learning

Visualization of K-Means

3. Recompute the “mean” (center) of each colored set of data.Notice: “means” do not have to be at the same position as a data point,

although some times they might be.

Page 17: Unsupervised  Learning

Visualization of K-Means

4. Repeat steps 2 & 3 until the “means” stop moving (convergence).a. Repeat step 2 (assign each point to the nearest mean)

Page 18: Unsupervised  Learning

Visualization of K-Means

4. Repeat steps 2 & 3 until the “means” stop moving (convergence).a. Repeat step 2 (assign each point to the nearest mean)

Page 19: Unsupervised  Learning

Visualization of K-Means

4. Repeat steps 2 & 3 until the “means” stop moving (convergence).a. Repeat step 2 (assign each point to the nearest mean)b. Repeat step 3 (recompute means)

Page 20: Unsupervised  Learning

Visualization of K-Means

4. Repeat steps 2 & 3 until the “means” stop moving (convergence).a. Repeat step 2 (assign each point to the nearest mean)b. Repeat step 3 (recompute means)

Quiz: Where will the means be after the next iteration?

Page 21: Unsupervised  Learning

Visualization of K-Means

4. Repeat steps 2 & 3 until the “means” stop moving (convergence).a. Repeat step 2 (assign each point to the nearest mean)b. Repeat step 3 (recompute means)

Answer: Where will the means be after the next iteration?

Page 22: Unsupervised  Learning

Visualization of K-Means

4. Repeat steps 2 & 3 until the “means” stop moving (convergence).a. Repeat step 2 (assign each point to the nearest mean)b. Repeat step 3 (recompute means)

Quiz: Where will the means be after the next iteration?

Page 23: Unsupervised  Learning

Visualization of K-Means

4. Repeat steps 2 & 3 until the “means” stop moving (convergence).a. Repeat step 2 (assign each point to the nearest mean)b. Repeat step 3 (recompute means)

Answer: Where will the means be after the next iteration?

Page 24: Unsupervised  Learning

Formal Description of the Algorithm

Input: 1) X11, …, X1N; … ; XM1, …, XMN

2) K

Output: Y1; …; YM, where each Yi is in {1, …, K}

Page 25: Unsupervised  Learning

Formal Description of the Algorithm

1. Init: For each k in {1, …, K}, create a random point Ck

2. Repeat until all Ck remain the same: Assignment (aka Expectation):For each Xi, let C[Xi] the k value for the closest Ck to Xi

Update (aka Maximization): For each Ck, let Dk{Xi |C[Xi] = k} (set of Xi assigned to cluster k) if |Dk| = 0, let Ck random new point else let Ck (average of points in Dk)

3. Return C[Xi] for each Xi

Page 26: Unsupervised  Learning

Evaulation metric for K-means

LOSS Function (or Objective function) for K-means:

Within-cluster-sum-of-squares loss (WCSS):WCSS(X1, …, XM, C1, …, CK)

Page 27: Unsupervised  Learning

Complexity of K-MeansFinding a globally-optimal solution to WCSS is known to be an NP-hard problem.

K-means is known to converge to a local minimum of WCSS.

K-means is a “heuristic” or “greedy” algorithm, with no guarantee that it will find the global optimum.

On real datasets, K-means usually converges very quickly. Often, people run it multiple times with different random initializations, and choose the best result.

In some cases, K-means will still take exponential time (assuming P!=NP), even to find a local minimum. However, such cases are rare in practice.

Page 28: Unsupervised  Learning

Quiz

Is K-meansClassification or Regression?

Generative or Discriminative?

Parametric or Nonparametric?

Page 29: Unsupervised  Learning

AnswerIs K-meansClassification or Regression?- classification: output is a discrete value (cluster label) for each point

Generative or Discriminative?- discriminative: it has fixed input variables and output variables.

Parametric or Nonparametric?- parametric: the number of cluster centers (K) does not change with the number of training data points

Page 30: Unsupervised  Learning

Quiz

Is K-meansSupervised or Unsupervised?

Online or batch?

Closed-form or iterative?

Page 31: Unsupervised  Learning

Answer

Is K-meansSupervised or Unsupervised?- Unsupervised

Online or batch?- batch: if you add a new data point, you need to revisit all the training data to recompute the locally-optimal model

Closed-form or iterative?-iterative: training requires many passes through the data

Page 32: Unsupervised  Learning

Quiz

Which of the following problems might be solved using K-Means? Check all that apply.For those that work, explain what the inputs and outputs (X and Y variables) would be.• Segmenting an image • Finding galaxies (dense groups of stars) in a

telescope’s image of the night sky• Identify different species of bacteria from DNA

samples of bacteria in seawater

Page 33: Unsupervised  Learning

AnswerWhich of the following problems might be solved using K-Means? Check all that apply.For those that work, explain what the inputs and outputs (X and Y variables) would be.• Segmenting an image: Yes. Inputs are the pixel intensities,

outputs are segment labels.• Finding galaxies (dense groups of stars) in a telescope’s image of

the night sky. Yes. Inputs are star locations, outputs are galaxy labels

• Identify different species of bacteria from DNA samples of bacteria in seawater. Yes. Inputs are gene sequences, outputs are species labels.