18 Learning Slides
18 Learning Slides
Syllabus:
Decision Tree 18 – 18.3.4
Evaluation 18.4
Model Selection 18.4.1
Regularization 18.4.3
Theory 18.5.0
Regression 18.6 – 18.6.2
Classification 18.6.3 – 18.6.4
Neural Network 18.7 – 18.7.4 (exclude exotic varieties of NN in my slides)
Non-parametric models 18.8 – 18.8.4
SVM basics 18.5
Clustering basics
…
4/2/24 [Link] 1
mation-in-neural-networks-
INFORMATION THEORETIC ENTROPY:
If one were to transmit sequences comprising the 4 characters 'A', 'B', 'C', and 'D', a transmitted message
might be 'ABADDCAB'. Information theory gives a way to calculate the smallest possible amount of
information that will convey this.
If all 4 letters are equally likely (25%) in a text, one can't do better (over a binary channel) than to have 2 bits
encoding for each letter: 'A' might code as '00', 'B' as '01', 'C' as '10', and 'D' as '11‘, i.e., 2 bits per letter.
If 'A' occurs with 70% probability, 'B' with 26%, and 'C' and 'D' with 2% each, and we are allowed to assign
variable length codes, 'A' would be coded as '0' (one bit), 'B' as '10', and 'C' and 'D' as '110' and '111'. It is easy
to see that 70% of the time only one bit needs to be sent, 26% of the time two bits, and only 4% of the time 3
bits. On an average, fewer than 2 bits will be required since the entropy is lower (owing to the high prevalence
of 'A' followed by 'B' – together 96% of characters) than that with equal probability. Overhead of transmitting
the encoding of letters is additional but minimal.
The calculation of the sum of weighted log probabilities measures and captures this effect.
[Link]
4/2/24 [Link] 2
Decision Tree: Choice of attribute at each level
4/2/24 3
H(goal) or entropy before choosing attributes
Attribute s
4/2/24 4
Decision Tree: Choice of attribute at each level
m = vs + vf + vn
4/2/24 5
Decision Tree: Choice of attribute at each level
Compute this gain for each attribute at the current node of the
decision tree,
4/2/24 [Link] 6
Decision Tree:
Choice of attribute at the root node in the Restaurant example in book
H
4/2/24 7
MISCELLENEOUS: Machine Learning has two stages:
Do not forget
4/2/24 8
MISCELLENEOUS: Evaluation of Algorithm
4/2/24 9
MISCELLENEOUS: Evaluation of Algorithm
Cross-validation: divide data set into two groups - training and
validation,
for computing the rate of successful classification of test data.
4/2/24 10
MISCELLENEOUS: Evaluation of Algorithm
ML competitions hold out real “test data,” but still groups may
"cheat" by repeatedly submitting fine-tuned code.
4/2/24 11
MISCELLENEOUS: Hypothesis Selection
4/2/24 12
REGULARIZATION
Optimization function may embed simplicity of the model, or any
other relevant knowledge
4/2/24 14
Computational Learning Theory
4/2/24 15
Problem II: Linear Regression
Output is Continuous valued
4/2/24 16
Linear Regression
(Still supervised learning)
4/2/24 17
Linear Regression
Take partial derivatives over wi and equate each to zero, i runs over parameters.
wi’s are parameters that the algorithm learns.
w0 = [∑jyj – w1(∑jxj)]] / N
for two parameters
4/2/24 18
Linear Regression
4/2/24 19
Multivariate Linear Regression
Hypothesis is: y = w0 +w1x1 +w2x2 +..., for x1, x2, ...xn variables in n-dimension
Closed form solution is a matrix formulation with partial differential equations equated to 0
w ß start with arbitrary point in the parameter space (w vector); Optimizes on parameter-space
loop until convergence
for each parameter wi in w do
wi ß wi – α* ∂/∂wi (Loss(w) );
4/2/24 20
Multivariate Linear Regression
4/2/24 21
Multivariate Linear Regression
Stochastic-gradient descent:
For each training example j
update all wis
....
Typically, one uses a mix of the two: e.g., a fixed batch size
4/2/24 22
Three nested loops in gradient descent optimization:
Iterations
Parameters
Training data
… in any order
4/2/24 23
Multivariate Linear Regression
For example, with 2 parameters for one variable data (yj = w0 + w1*xj):
w0 ß w0 + α* ∑j(yj – hw(xj));
w1 ß w1 + α* ∑j(yj – hw(xj))*xj
4/2/24 24
Multivariate Linear Regression
L1-norm (absolute sum) is better for this second term on complexity of the model:
"sparse model": minimizes #of “dimensions” (Fig 18.14 p722)
sometimes called Lasso regrerssion
4/2/24 25
Problem III: LINEAR CLASSIFIER 18.6.3
4/2/24 26
Problem III: LINEAR CLASSIFIER 18.6.3
• Predicting y is the objective for regression, but classifiers predicts “type” or “class”
• Training problem:
set of (x, y) is given, x are data points and now, y =1 or 0,
find hw(x) that models y
• Test by inferencing:
a data point x is given, predict if it is in the class or not (compute hw(x) )
4/2/24 27
LINEAR CLASSIFIER 18.6.3
• No longer hw(x) is the line expected to pass through (or close to) the data samples
as in regression,
but to separate or classify them into two sides of the line – in class or out of class
• Finding the line is very similar as in regression: optimize for (w0, w1, …)
4/2/24 28
LINEAR CLASSIFIER 18.6.3
• Rewrite the model: (w0, w1, w2, ...)T * (x0, x1, x2, ...) ≥0, a vector product
where (…) is a column vector, (.)T stands for matrix transpose, and x0 = 1
• Consider two vectors, w= (w0, w1, w2, ...)T and x= (x0, x1, x2, ...)T
• hw(x) = 1 when (w.x)≥0, otherwise hw(x) = 0
4/2/24 29
LINEAR CLASSIFIER 18.6.3
• Training:
• (2) False negative: y=1, but hw(x) =0, increase wi for each positive?(xi), decrease otherwise
• (3) False positive: y=0, but hw(x) =1, decrease wi for each positive?(xi), increase otherwise
4/2/24 30
LINEAR CLASSIFIER 18.6.3
• Logistic regression:
use sigmoid hw(x) rather than Boolean function (step function) as abov
hw(x) = Logistic(w.x) = 1 / [1 + e-w.x]
4/2/24 31
LINEAR CLASSIFIER 18.6.3
• Logistic regression:
use sigmoid hw(x) rather than Boolean function (step function) as above
hw(x) = Logistic(w.x) = 1 / [1 + e-w.x]
4/2/24 32
Problem IV: ARTIFICIAL NEURAL NETWORK Ch 18.7
1
x1 w0
w1
x2 w2
∑i=0n wixi ∫ 0 or 1
xn wn
4/2/24 33
ARTIFICIAL NEURAL NETWORK Ch 18.7
• A single layer perceptron network CANNOT "learn" xor function or Boolean sum,
• Fig 18.21 p 730
4/2/24 34
ARTIFICIAL NEURAL NETWORK Ch 18.7
4/2/24 [Link] 35
ARTIFICIAL NEURAL NETWORK Ch 18.7
4/2/24 [Link] 36
ARTIFICIAL NEURAL NETWORK Ch 18.7
• A single layer perceptron network CANNOT "learn" xor function or Boolean sum
• Multi-layer Feed Forward Network:
• Multiple layers can coordinate to create complex multi-linear classification space,
• Fig 18.23 p732
4/2/24 37
ARTIFICIAL NEURAL NETWORK Ch 18.7
• Types of architectures:
• Transformer
4/2/24 38
ARTIFICIAL NEURAL NETWORK Ch 18.7.4
4/2/24 [Link] 39
ARTIFICIAL NEURAL NETWORK Ch 18.7.4
• This is to be minimized
• Weight updates:
wij ß wij + α * aj * Delj
• Error propagation
Delj = g’(inj) ∑k (wjk Delk), where g’() derivative of activation, k is over next layer neurons
(previous layer in backward direction)
• An iteration of backpropagation learning:
Propagate errors then update weight, layer by layer backwards
4/2/24 40
GENERATIVE NEURAL NETWORK
Not only classification…
Transformations: say, (x,y) goes to (2x,y) – a linear transformation that we want to learn
Neural Net:
4/2/24 [Link]
GENERATIVE NEURAL NETWORK
Neural Net:
4/2/24 [Link]
NEURAL NETWORK
4/2/24 43
NEURAL NETWORK
4/2/24 [Link]
CONVOLUTIONAL NEURAL NETWORK
[Link]
4/2/24 45
RECURRENT NEURAL NETWORK
[Link]
4/2/24 46
DEEP LEARNING / NEURAL NETWORK
ISSUES TO WATCH FOR
• Network architecture
• Skip connections
• Activation function (more next slide)
• Loss function
• Optimization algorithm
• Epochs for training
• Learning rate
• Drop out
4/2/24 47
DEEP LEARNING / NEURAL NETWORK
ACTIVATION FUNCTIONS
[Link]
4/2/24 48
NON-PARAMETRIC MODELS Ch 18.8
4/2/24 49
NON-PARAMETRIC MODELS Ch 18.8
4/2/24 [Link] 50
NON-PARAMETRIC MODELS Ch 18.8
• K-nearest neighbor look up -kNN (Problem VI):
find k nearest neighboring example data instead of one,
and vote by their attribute values (pure counting for Boolean attributes)
• k is typically odd integer for this reason
• Fig. 18.26 p738, shows the “query-space”,
• Runs query for every point in the 2D space to check what the prediction will return for that point
• Gray areas indicate prediction=dark circle; and white areas indicate prediction=open circle
4/2/24 51
NON-PARAMETRIC MODELS Ch 18.8
• Advantage: faster search, conventional kNN may need very expensive data organization
(Note: this is a search problem, before the query gets answered)
4/2/24 52
NON-PARAMETRIC MODELS Ch 18.8
• k is dimension here
• Balanced binary search tree over k-dimension, with median (on each dimension) as the
splitting boundary
4/2/24 53
NON-PARAMETRIC MODELS Ch 18.8
• Another efficient data organization: LSH or locality sensitive hashing (Problem VIII)
• Hashing typically distributes data randomly, but we want nearer points together in memory
o Two close points have always close projections on any dimension(s), although the reverse is
unlikely to be true
o Create multiple hash functions on multiple subset of dimensions (random), [ideal: on all
dimensions] e.g., x1x3x4, x5x2x9,…
o Retrieve all points close to the query point in any of the hash function (union of points with
same hash value in each hash function)
[Link]
4/2/24 55
NON-PARAMETRIC MODELS Ch 18.8
• Back to regression: NON-PARAMETRIC REGRESSION (Problem IX)
4/2/24 56
NON-PARAMETRIC MODELS Ch 18.8
4/2/24 58
NON-PARAMETRIC MODELS Ch 18.9
• SUPPORT VECTOR MACHINE (SVM) – basics, the best ML algorithm so far (Problem X)
• Support vector: Data points separating the boundary between + and – labels
(Classification or decision boundary)
• But with, two parallel lines, one passing through +ve support vectors, one through –ve ones
The gap between these two lines that must be maximized, Fig 18.31 p747
4/2/24 59
H1 does not separate the classes.
H2 does, but only with a small margin.
H3 separates them with the maximal margin.
-- Wiki on SVM
4/2/24 60
NON-PARAMETRIC MODELS Ch 18.9
• SUPPORT VECTOR MACHINE (SVM) – basics [few concepts come together]
4/2/24 61
NON-PARAMETRIC MODELS Ch 18.9
4/2/24 62
TYPES OF LEARNING
• Unsupervised / Clustering:
• Only data, no label to predict.
• So, group or cluster data by their “proximity”
• Semi-supervised learning:
• Predict (hypothesis h) and include the prediction as training data (!!) if actual predicted
value (y) was not available
• Follows the “trajectory” of incoming data
4/2/24 63
UNSUPERVISED LEARNING / CLUSTERING
• No target output value to predict, i.e., no label, only a set of data points
4/2/24 64
TYPES OF CLUSTERING
• Centroid models: for example, the k-means algorithm represents each cluster by a
single mean vector.
• Connectivity models: for example, hierarchical clustering builds models based on
distance-based connectivity or topology. Mapper algo creates maps of data space.
• Distribution models: clusters are modeled using statistical distributions, such as
multivariate normal distributions used by the expectation-maximization algorithm.
• Density models: for example, DBSCAN and OPTICS defines clusters as connected
dense regions in the data space. ToMato for topological clustering uses this.
• Subspace models: in bi-clustering (also known as co-clustering or two-mode-clustering),
clusters are modeled with both cluster members and relevant attributes.
• Group models: some algorithms do not provide a refined model for their results and
just provide the grouping information of data space.
• Graph-based models: a clique, that is, a subset of nodes in a graph such that every
two nodes in the subset are connected by an edge that can be considered as a
prototypical form of cluster.
• Neural models: the most well known unsupervised neural network is the
self-organizing map (SOM) and these models can usually be characterized as similar
to one or more of the above models: learns local manifolds in data space
• Topological data analysis (e.g., Mapper or ToMato algorithm): visualize topology of data
points on space
4/2/24 65
K-MEANS CLUSTERING
(Problem XII)
• [Link]
4/2/24 66
HIERARCHICAL CLUSTERING
(Problem XIII)
• [Link]
4/2/24 67
HIERARCHICAL CLUSTERING
• Needs a measure for inter-cluster distance, for splitting or merging
• UPGMA algorithm’s (bottom up) inter-cluster distance: [1/|A|*|B|] * ∑xÎA ∑xÎB d(x,y)
4/2/24 68
DENSITY-BASED CLUSTERING
(Problem XIV)
• Given a set of points in some space, it groups points that are closely packed together
(points with many nearby neighbors), marking as outlier data points
that lie alone in low-density regions (whose nearest neighbors are too far away).
• [Link]
4/2/24 69
ADVANTAGES: DBSCAN
• Requires two parameters minPts and ε, can be set by expert by pre-analyzing data
4/2/24 70
DISADVANTAGES: DBSCAN
• DBSCAN is non-deterministic: border points that are reachable from more than one cluster
• DBSCAN* is a variation that treats border points as noise, and not included in clusters
• DBSCAN cannot cluster data sets well with large differences in densities,
since the minPts and ε combination cannot then be chosen appropriately for all clusters
• If the data and scale are not well understood, choosing a meaningful ε can be difficult.
4/2/24 71
RESOURCE (IGNORE IN SYLLABUS)
A group of data scientists tested some popular chatbots on tasks
including formal and casual writing, text and tone editing, and
programming. Here are some of their impressions:
4/2/24 72
IGNORE FOR NOW: SELF-SUPERVISED LEARNING
4/2/24 73
SELF-SUPERVISED LEARNING
Based on Autoencoder-Decoder
4/2/24 74