32
Machine learning Image source: https://www.coursera.org/course/ml

Machine learning Image source:

Embed Size (px)

Citation preview

Page 1: Machine learning Image source:

Machine learning

Image source: https://www.coursera.org/course/ml

Page 2: Machine learning Image source:

Machine learning

• Definition– Getting a computer to do well on a task

without explicitly programming it– Improving performance on a task based on

experience

Page 3: Machine learning Image source:

Learning for episodic tasks

• We have just looked at learning in sequential environments

• Now let’s consider the “easier” problem of episodic environments– The agent gets a series of unrelated problem

instances and has to make some decision or inference about each of them

Page 4: Machine learning Image source:

Example: Image classification

apple

pear

tomato

cow

dog

horse

input desired output

Page 5: Machine learning Image source:

Learning for episodic tasks

• We have just looked at learning in sequential environments

• Now let’s consider the “easier” problem of episodic environments– The agent gets a series of unrelated problem

instances and has to make some decision or inference about each of them

– In this case, “experience” comes in the form of training data

Page 6: Machine learning Image source:

Training data

• Key challenge of learning: generalization to unseen examples

apple

pear

tomato

cow

dog

horse

Page 7: Machine learning Image source:

Example 2: Seismic data classification

Body wave magnitude

Sur

face

wav

e m

agni

tude

Nuclear explosions

Earthquakes

Page 8: Machine learning Image source:

Example 3: Spam filter

Page 9: Machine learning Image source:

Example 4: Sentiment analysis

http://gigaom.com/2013/10/03/stanford-researchers-to-open-source-model-they-say-has-nailed-sentiment-analysis/

http://nlp.stanford.edu:8080/sentiment/rntnDemo.html

Page 10: Machine learning Image source:

The basic machine learning framework

y = f(x)

• Learning: given a training set of labeled examples {(x1,y1), …, (xN,yN)}, estimate the parameters of the prediction function f

• Inference: apply f to a never before seen test example x and output the predicted value y = f(x)

output classification function

input

Page 11: Machine learning Image source:

Naïve Bayes classifier

ddy

y

y

yxPyP

yPyP

yPf

)|()(maxarg

)|()(maxarg

)|(maxarg)(

x

xx

A single dimension or attribute of x

Page 12: Machine learning Image source:

Decision tree classifier

Example problem: decide whether to wait for a table at a restaurant, based on the following attributes:1. Alternate: is there an alternative restaurant nearby?

2. Bar: is there a comfortable bar area to wait in?

3. Fri/Sat: is today Friday or Saturday?

4. Hungry: are we hungry?

5. Patrons: number of people in the restaurant (None, Some, Full)

6. Price: price range ($, $$, $$$)

7. Raining: is it raining outside?

8. Reservation: have we made a reservation?

9. Type: kind of restaurant (French, Italian, Thai, Burger)

10. WaitEstimate: estimated waiting time (0-10, 10-30, 30-60, >60)

Page 13: Machine learning Image source:

Decision tree classifier

Page 14: Machine learning Image source:

Decision tree classifier

Page 15: Machine learning Image source:

Nearest neighbor classifier

f(x) = label of the training example nearest to x

• All we need is a distance function for our inputs• No training required!

Test example

Training examples

from class 1

Training examples

from class 2

Page 16: Machine learning Image source:

K-nearest neighbor classifier

• For a new point, find the k closest points from training data

• Vote for class label with labels of the k points k = 5

Page 17: Machine learning Image source:

Linear classifier

• Find a linear function to separate the classes

f(x) = sgn(w1x1 + w2x2 + … + wDxD) = sgn(w x)

Page 18: Machine learning Image source:

NN vs. linear classifiers• NN pros:

– Simple to implement– Decision boundaries not necessarily linear– Works for any number of classes– Nonparametric method

• NN cons:– Need good distance function– Slow at test time

• Linear pros:– Low-dimensional parametric representation– Very fast at test time

• Linear cons:– Works for two classes– How to train the linear function?– What if data is not linearly separable?

Page 19: Machine learning Image source:

Perceptron

x1

x2

xD

w1

w2

w3

x3

wD

Input

Weights

.

.

.

Output: sgn(wx + b)

Can incorporate bias as component of the weight vector by always including a feature with value set to 1

Page 20: Machine learning Image source:

Loose inspiration: Human neurons

Page 21: Machine learning Image source:

Linear separability

Page 22: Machine learning Image source:

Perceptron training algorithm• Initialize weights• Cycle through training examples in multiple

passes (epochs)• For each training example:

– If classified correctly, do nothing– If classified incorrectly, update weights

Page 23: Machine learning Image source:

Perceptron update rule• For each training instance x with label y:

– Classify with current weights: y’ = sgn(wx)– Update weights:

– α is a learning rate that should decay as 1/t, e.g., 1000/(1000+t)

– What happens if answer is correct?– Otherwise, consider what happens to individual

weights: • If y = 1 and y’ = −1, wi will be increased if xi is positive or

decreased if xi is negative −> wx gets bigger

• If y = −1 and y’ = 1, wi will be decreased if xi is positive or increased if xi is negative −> wx gets smaller

Page 24: Machine learning Image source:

Convergence of perceptron update rule

• Linearly separable data: converges to a perfect solution

• Non-separable data: converges to a minimum-error solution assuming learning rate decays as O(1/t) and examples are presented in random sequence

Page 25: Machine learning Image source:

Implementation details

• Bias (add feature dimension with value fixed to 1) vs. no bias

• Initialization of weights: all zeros vs. random• Number of epochs (passes through the training

data)• Order of cycling through training examples

Page 26: Machine learning Image source:

Multi-class perceptrons

• Need to keep a weight vector wc for each class c

• Decision rule: • Update rule: suppose an example from

class c gets misclassified as c’– Update for c: – Update for c’:

Page 27: Machine learning Image source:

Differentiable perceptron

x1

x2

xd

w1

w2

w3

x3

wd

Sigmoid function:

Input

Weights

.

.

.te

t 1

1)(

Output: (wx + b)

Page 28: Machine learning Image source:

Update rule for differentiable perceptron

• Define total classification error or loss on the training set:

• Update weights by gradient descent:

• For a single training point, the update is:

)()(,)()(1

2jj

N

jjj ffyE xwxxw ww

N

jjjjjj

N

jjjjj

fy

fyE

1

1

))(1)(()(2

)()(')(2

xxwxwx

xww

xwxw

www

E

xxwxwxww ))(1)(()( fy

Page 29: Machine learning Image source:

Update rule for differentiable perceptron

• For a single training point, the update is:

• Compare with update rule with non-differentiable perceptron:

xxwxwxww ))(1)(()( fy

xxww )(fy

Page 30: Machine learning Image source:

Multi-Layer Neural Network

• Can learn nonlinear functions• Training: find network weights to minimize the error between true and

estimated labels of training examples:

• Minimization can be done by gradient descent provided f is differentiable– This training method is called back-propagation

N

iii fyfE

1

2)()( x

Page 31: Machine learning Image source:

Deep convolutional neural networks

Zeiler, M., and Fergus, R. Visualizing and Understanding Convolutional Neural Networks, tech report, 2013.Krizhevsky, A., Sutskever, I., and Hinton, G.E. ImageNet classication with deep convolutional neural networks. NIPS, 2012.

Page 32: Machine learning Image source:

Demo from Berkeley

http://decaf.berkeleyvision.org/