SP14 CS188 Lecture 23 - Kernels and Clustering - Print
SP14 CS188 Lecture 23 - Kernels and Clustering - Print
Instructors: Dan Klein and Pieter Abbeel --- University of California, Berkeley
[These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http://ai.berkeley.edu.]
Case-Based Learning
Non-Separable Data
Case-Based Reasoning
Classification from similarity
Case-based reasoning
Predict an instance’s label using similar instances
Nearest-neighbor classification
1-NN: copy the label of the most similar data point
K-NN: vote the k nearest neighbors (need a weighting
scheme)
Key issue: how to define similarity
Trade-offs: Small k gives relevant neighbors, Large k gives
smoother functions
http://www.cs.cmu.edu/~zhuxj/courseproject/knndemo/KNN.html
Parametric / Non-Parametric
Parametric models:
Fixed set of parameters
More data means better settings
Non-parametric models:
Complexity of the classifier increases with data
Better in the limit, often worse in the non-limit
(K)NN is non-parametric Truth
1
Usually normalize vectors so ||x|| = 1
min = 0 (when?), max = 1 (when?) 2
Similarity Functions
Basic Similarity
Many similarities based on feature dot products:
This and next few slides adapted from Xiao Hu, UIUC
Rotation Invariant Metrics
s’=max s( r( ), r( ))
Perceptron-like approaches
Explicit training to reduce empirical error
Can’t use fancy similarity, only linear
Or can they? Let’s find out!
Kernelization
Perceptron Weights
What is the final value of a weight wy of a perceptron?
Can it be any real vector?
No! It’s built by adding up inputs.
If someone tells us the value of K for each pair of examples, never need to build the
weight vectors (or the feature vectors)!
Dual Perceptron
Start with zero counts (alpha)
Pick up training instances one by one
Try to classify x ,
n
If correct, no change!
If wrong: lower count of wrong class (for this instance), raise
count of right class (for this instance)
Kernelized Perceptron
If we had a black box (kernel) K that told us the dot product of two examples x and x’:
Could work entirely with the dual representation
No need to ever take dot products (“kernel trick”)
“Kernel trick”: we can substitute any* similarity function in place of the dot
product
0 x
0 x
How about… mapping data to a higher-dimensional space:
x2
0 x
This and next few slides adapted from Ray Mooney, UT
Non-Linear Separators
General idea: the original feature space can always be mapped to some higher-
dimensional feature space where the training set is separable:
Φ: x → φ(x)
Some Kernels
Kernels implicitly map original vectors to higher dimensional spaces, take the dot
product there, and hand the result back
Linear kernel:
Quadratic kernel:
Classification systems:
Supervised learning
Make a prediction given evidence
We’ve seen several methods for this
Useful when you have labeled data
Clustering
Clustering systems:
Unsupervised learning
Detect patterns in unlabeled data
E.g. group emails or search results
E.g. find categories of customers
E.g. detect anomalous program executions
Useful when don’t know what you’re
looking for
Requires data, but no labels
Often get gibberish
Clustering
Clustering
Basic idea: group together similar instances
Example: 2D point patterns
An iterative clustering
algorithm
Pick K random points as cluster
centers (means)
Alternate:
Assign data instances to closest
mean
Assign each mean to the average of
its assigned points
Stop when no points’
assignments change
K-Means Example
K-Means as Optimization
Consider the total distance to the means:
points means
assignments
Each iteration reduces phi
K-means is non-deterministic
Requires initial means
It does matter what you pick!
What can go wrong?
Algorithm:
Maintain a set of clusters
Initially, each instance in its own cluster
Repeat:
Pick the two closest clusters
Merge them into a new cluster
Stop when there’s only one cluster left
Many options
Closest pair (single-link clustering)
Farthest pair (complete-link clustering)
Average of all pairs
Ward’s method (min variance, like k-means)