welcome to machine learning

91
Welcome to Machine Learning Konstantin Tretyakov http://kt.era.ee IFI Summer School 2014

Upload: others

Post on 19-May-2022

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Welcome to Machine Learning

Welcome to Machine Learning

Konstantin Tretyakovhttp://kt.era.ee

IFI Summer

School 2014

Page 2: Welcome to Machine Learning

Data mining,

Data analysis, Statistical analysis,

Pattern discovery, Statistical learning,

Machine learning, Predictive analytics,

Business intelligence, Data-driven statistics,

Inductive reasoning, Pattern analysis,

Knowledge discovery from databases,

Neural networks,

Page 3: Welcome to Machine Learning
Page 4: Welcome to Machine Learning
Page 5: Welcome to Machine Learning
Page 6: Welcome to Machine Learning

A

Page 7: Welcome to Machine Learning
Page 8: Welcome to Machine Learning
Page 9: Welcome to Machine Learning

“Unformalizable” problems

Page 10: Welcome to Machine Learning

“Unformalizable” problems

Page 11: Welcome to Machine Learning

“Unformalizable” problems

А

A

A

B

B

B

B

Page 12: Welcome to Machine Learning
Page 13: Welcome to Machine Learning
Page 14: Welcome to Machine Learning

General rule:

IF (Х is made of plastic), THEN (Х is not edible)

Application in the particular case:Х = Rubic’s cube

⇒Rubic’s cube is not edible

Page 15: Welcome to Machine Learning

General rule:

add(x, y) = function { … }

Application in the particular case:add(2,4)

Page 16: Welcome to Machine Learning

General rule:

add(x, y) = function {

???

}

Particular cases:add(2,4) = 6

add(5,3) = 8

add(1,2) = 3

Ind

uc

tio

n

Page 17: Welcome to Machine Learning

Deduction

Given a general rule, make a decision in a particular case

Page 18: Welcome to Machine Learning

Induction

Given particular cases, find a general rule

Page 19: Welcome to Machine Learning

Deduction and Induction

Page 20: Welcome to Machine Learning

Classification

by analogy

Page 21: Welcome to Machine Learning

MNIST dataset

http://yann.lecun.com/exdb/mnist/

Handwritten digits, 28 х 28

Page 22: Welcome to Machine Learning

MNIST dataset

images = load_images()

labels = load_labels()

# Let us just use 1000 images

training_set = images[0:1000]

training_labels = labels[0:1000]

Page 23: Welcome to Machine Learning

MNIST dataset

> training_set[0]

array([ 0, 0, 0, ...,

254, 241, 198, ...])

> training_labels[0]

‘7’

Page 24: Welcome to Machine Learning

Nearest neighbor method

Training set

?4

7

9

7

4

Page 25: Welcome to Machine Learning

Nearest neighbor method

Training set

4

4

7

9

7

4

Page 26: Welcome to Machine Learning

Nearest neighbor method

def classify(img):

similarities =

[similarity(img, p) for p in training_set]

i = similarities.index(max(similarities))

return training_labels[i]

Page 27: Welcome to Machine Learning

Nearest neighbor method

def classify(img):

similarities =

[similarity(img, p) for p in training_set]

i = similarities.index(max(similarities))

return training_labels[i]

def similarity(img1, img2):

return -sum(abs(img1 - img2))

Page 28: Welcome to Machine Learning

Testing the algorithm

test_set = images[1000:2000]

test_labels = labels[1000:2000]

predicted_class = [classify(p) for p in test_set]

n_successes =

sum(array(predicted_class) ==

array(test_labels))

=> 843/1000

Page 29: Welcome to Machine Learning

9 or 4?

Page 30: Welcome to Machine Learning

from sklearn.neighbors import

KNeighborsClassifier

clf = KNeighborsClassifier(n_neighbors=1)

clf.fit(training_set, training_labels)

predicted_class = clf.predict(test_set)

=> 855/1000

Scikit-learnhttp://scikit-learn.org/

Page 31: Welcome to Machine Learning
Page 32: Welcome to Machine Learning

Nearest neighbor method

Training set

4

4

7

9

7

4

Page 33: Welcome to Machine Learning

Some samples may be thrown away

Training set

4

4

7

9

7

4

Page 34: Welcome to Machine Learning

…or we can add “weights”

Training set

4

4

7

9

7

4

0.0

1.0

1.0

1.0

0.0

Page 35: Welcome to Machine Learning

…or we can add “weights”

Training set

4

4

7

9

7

4

0.0

0.9

1.1

2.0

0.0

Page 36: Welcome to Machine Learning

.. or we can SUM instead of MAX

Training set

4

4

7

9

7

4

0.0

0.9

1.1

2.0

0.0

Page 37: Welcome to Machine Learning

.. or we can SUM instead of MAX

Training set

4

7

9

7

4

0.0

0.9

1.1

2.0

0.0

evidence(img, 4) =

0.9 * similarity(img, tr[1])

+

0.0 * similarity(img, tr[4])

= 34.0

Page 38: Welcome to Machine Learning

.. or we can SUM instead of MAX

Training set

4

7

9

7

4

0.0

0.9

1.1

2.0

0.0

evidence(img, 7) =

0.0 * similarity(img, tr[0])

+

2.0 * similarity(img, tr[3])

= 20.0

Page 39: Welcome to Machine Learning

General form

𝐾(𝒙𝑖 , 𝒛)

Page 40: Welcome to Machine Learning

General form

𝐾(𝒙𝑖 , 𝒛)

𝐾(𝒙𝑗 , 𝒛)

Page 41: Welcome to Machine Learning

General form

𝑖

𝑤𝑖𝐾(𝒙𝑖 , 𝒛)

𝑗

𝑤𝑗𝐾(𝒙𝑗 , 𝒛)

Page 42: Welcome to Machine Learning

General form

𝑖

𝑤𝑖𝐾(𝒙𝑖 , 𝒛)

𝑗

𝑤𝑗𝐾(𝒙𝑗 , 𝒛)

Page 43: Welcome to Machine Learning

General form

𝑖

𝑤𝑖𝑦𝑖𝐾(𝒙𝑖 , 𝒛)

+

𝑗

𝑤𝑗𝑦𝑗𝐾(𝒙𝑗 , 𝒛)

Page 44: Welcome to Machine Learning

General form

𝑓𝒘 𝒛 =

𝑖

𝑤𝑖𝑦𝑖 𝐾(𝒙𝑖 , 𝒛)

Page 45: Welcome to Machine Learning

How to find the weights?

𝑓𝒘 𝒛 =

𝑖

𝑤𝑖𝑦𝑖 𝐾(𝒙𝑖 , 𝒛)

Page 46: Welcome to Machine Learning

How to find the weights?

Find weights, such that the

misclassification error rate on the training set

is the smallest.

w = argminw ErrorRate (fw, Data)

𝑓𝒘 𝒛 =

𝑖

𝑤𝑖𝑦𝑖 𝐾(𝒙𝑖 , 𝒛)

Page 47: Welcome to Machine Learning

How to find the weights?

Find weights, such that the

approximation to misclassification error on

the training set is the smallest.

w = argminw Error (fw, Data)

𝑓𝒘 𝒛 =

𝑖

𝑤𝑖𝑦𝑖 𝐾(𝒙𝑖 , 𝒛)

Page 48: Welcome to Machine Learning

How to find the weights?

Find weights, such that the

error rate on the training set is the smallest +

there are many zero weights.

w = argminw Error (fw, Data) + Complexity (w)

𝑓𝒘 𝒛 =

𝑖

𝑤𝑖𝑦𝑖 𝐾(𝒙𝑖 , 𝒛)

Page 49: Welcome to Machine Learning

Support Vector Machine

from sklearn.svm import SVC

clf = SVC(kernel=‘linear’)

clf.fit(training_set, training_labels)

predicted_class = clf.predict(test_set)

=> 865/1000

Page 50: Welcome to Machine Learning
Page 51: Welcome to Machine Learning

Classification by

analogy:k-NN

SVM

RBF

Page 52: Welcome to Machine Learning

Search for the nearest neighbor

def classify(img):

similarities =

[similarity(img, p) for p in training_set]

i = similarities.index(max(similarities))

return training_labels[i]

Page 53: Welcome to Machine Learning

Search for the nearest neighbor

def classify(img):

similarities =

[similarity(img, p) for p in training_set]

i = similarities.index(max(similarities))

return training_labels[i]

Inefficient

Page 54: Welcome to Machine Learning

Search for the nearest neighbor

def classify(img):

nearest_neighbour =

training_set.find_nearest_neighbour(img)

return nearest_neighbour.label

Indexing!

Page 55: Welcome to Machine Learning
Page 56: Welcome to Machine Learning
Page 57: Welcome to Machine Learning
Page 58: Welcome to Machine Learning
Page 59: Welcome to Machine Learning
Page 60: Welcome to Machine Learning

find_nearest_neighbour

if pixel[10,13] > 4:

if pixel[3,24] < 0:

nearest_neighbour = A

else:

nearest_neighbour = B

else:

nearest_neighbour = C

Page 61: Welcome to Machine Learning

Classification Tree

if pixel[10,13] > 4:

if pixel[3,24] < 0:

class = ‘1’

else:

class = ‘2’

else:

class = ‘3’

Page 62: Welcome to Machine Learning

Classification Tree

Page 63: Welcome to Machine Learning

Classification Tree

Page 64: Welcome to Machine Learning

Classification Tree

Orangehttp://orange.biolab.si/

Page 65: Welcome to Machine Learning
Page 66: Welcome to Machine Learning

Trees

ID3

C4.5

RegTree

Page 67: Welcome to Machine Learning

Search for optimal model

parameters

General form of a model

𝑓𝒘 𝒛 =

𝑖

𝑤𝑖𝑦𝑖 𝐾(𝒙𝑖 , 𝒛)

Page 68: Welcome to Machine Learning

Search for the optimal

tree

General form of a model

Page 69: Welcome to Machine Learning

Optimization

Modeling

Page 70: Welcome to Machine Learning

Linear model

f(image) =

pixel1*w1 + pixel2*w2 + … + pixel784*w784

Page 71: Welcome to Machine Learning

Linear Classification

from sklearn.linear_model import

LinearRegression,

LogisticRegression,

RidgeClassifier,

LARS,

ElasticNet,

SGDClassifier,

...

=> 809/1000

Page 72: Welcome to Machine Learning
Page 73: Welcome to Machine Learning

Modeling

Page 74: Welcome to Machine Learning

Linear model

f(image) =

pixel1*w1 + pixel2*w2 + … + pixel784*w784

Page 75: Welcome to Machine Learning

f(image) =

pixel1*w1 + pixel2*w2 + … + pixel784*w784

pixel1

pixel2

pixel3

pixel4

pixel784

w1w2

w3

w4

w784

f(image)

Page 76: Welcome to Machine Learning

Neural network

Page 77: Welcome to Machine Learning

Modeling

Page 78: Welcome to Machine Learning

Why should a model,

trained on one set of data,

work well on future data?

When is it not the case?

Page 79: Welcome to Machine Learning

How to formalize a new model?

How to find parameters?

Page 80: Welcome to Machine Learning

How to create efficient learning algorithms?

Page 81: Welcome to Machine Learning

How to handle structured data?

Page 82: Welcome to Machine Learning

Unsupervised learning

Semi-supervised learning

On-line learning

Active learning

Multi-instance learning

Reinforcement learning

Page 83: Welcome to Machine Learning

Probabilistic models

Graphical models

Ensemble learners

Data fusion

HPC

Page 84: Welcome to Machine Learning

Tools:R, Weka, RapidMiner,

Orange, scikits-learn,

MLPy, MDP, PyBrain, …

Page 85: Welcome to Machine Learning
Page 86: Welcome to Machine Learning

“Unformalizable” problems

Model-based Instance-based

Deduction and Induction

Theory and

Practice

Page 87: Welcome to Machine Learning

Quiz

The OCR problem is unusual in that it is ____.

The two important perspectives on machine

learning are ______-based and _____-based.

The “soul” of machine learning is the

minimization task

argmin𝒘 ________ + 𝜆 _________

Page 88: Welcome to Machine Learning

Quiz

Two important components of machine

learning:

?

?

Page 89: Welcome to Machine Learning

Quiz

The machine learning algorithms mentioned in

this lecture were:

Page 90: Welcome to Machine Learning

Quiz

The machine learning algorithms mentioned in

this lecture were:

K-nearest neighbor classifier

SVM

Classification trees

Linear models

Neural networks

Page 91: Welcome to Machine Learning

Questions?