from linear algebra to machine learning - europython...learning(imho). learningfromerrors...

22
from linear algebra to machine learning Omar Gutiérrez July 27, 2018 @trinogz

Upload: others

Post on 22-Mar-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

from linear algebrato machine learning

Omar GutiérrezJuly 27, 2018

@trinogz

Page 2: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Overview

Motivation

Vectors

Examples

Conclusions

Page 3: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

motivation

Page 4: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Motivation

∙ Linear algebra is important to understand machine learning.∙ As well as calculus, probability theory, and statistics.∙ It is rewarding to take the hard path to learn machinelearning (IMHO).

Page 5: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Learning from errors

Page 6: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Learning from errors

Page 7: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

vectors

Page 8: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

A vector is a collection of numbers

~a = a =

a1a2...an

Page 9: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Length of a vector

|a| =

√√√√ n∑i=0

a2i

Page 10: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Distance beetwen vectors

d(a,b) = ||a− b||

=

√√√√ n∑i=0

(ai − bi)2

Page 11: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Dot product

a · b =n∑i=0

aibi

= a0b0 + a1b1 + . . .+ anbnSo,

a · a = a0a0 + a1a1 + . . .+ anan= a20 + a21 + . . .+ a2n= |a|2

Page 12: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

examples

Page 13: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7
Page 14: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

The AI winter is coming

∙ Is really coming? No.∙ However, we already had an AI winter.∙ The research on neural nets was stopped for many years,after Minsky and Papert proved that a single layer perceptronwas not able to deal with the exclusive-or problem.

Page 15: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Toy dataset

b11 b12 1

b21 b22 0

b31 b32 1

. . . . . . . . .

bn1 bn2 1

Page 16: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Perceptron

1

x1

x2

...

xn

∑f (x)

0.5

0.1

0.1

0.1

x0 x1∑

f (x)

1 1 1× 0.5+ 1×−1 = −0.5 01 0 1× 0.5+ 0×−1 = 0.5 1

Page 17: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Linear Regression

40 50 60 70 80 90 100150

160

170

180

190

200

x

y

Page 18: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Linear Regression

∙ We want to calculate the intercept a and theslope b.

arg mina,b

∑i

(yi − (axi + b))2 = arg minw

||Xw − y||2

∙ The solution to this optimization problem is:

w∗ = (XTX)−1XTy .

Page 19: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

conclusions

Page 20: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

More topics we should check

∙ Gradient descent is a beautiful optimization algorithm,basically, we multiply matrices to many times.

∙ Eigenvectors and eigenvalues; some dimensionalityreduction techniques are based on eigendecomposition.

∙ Be aware that numerical instabilities can happen, and avoidthese ones.

Page 21: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

References

∙ Mathematics for Machine Learning: Linear Algebra byCoursera.

∙ The Math of Intelligence by Siraj Raval.∙ Deep Learning Book by Bengio and Goodfellow, has achapter summarizing which linear algebra topics you needto learn neural networks.

Page 22: From Linear Algebra to Machine Learning - EuroPython...learning(IMHO). Learningfromerrors Learningfromerrors vectors Avectorisacollectionofnumbers ~a= a= 2 6 6 6 4 a1 a2... an 3 7

Thank you.Questions?Comments?