(update 1 Februari 01) Lecture 3 Linear Discrimant Model
Learning a Class from Examples (Alpaydin 009) Class C of a family car Prediction: Is car x a family car? Knowledge extraction: What do people expect from a family car? Output: Positive (+) and negative ( ) examples Input representation: x 1 : price, x : engine power
Training set X X x t { t,r } t1 r 1if 0 if x ispositive x isnegative x x x 1
p price p AD e engine power e 1 1
1if h says x ispositive h( x) 0 if h says x isnegative Error of h on H E( h X) t t 1 h x r t1
most specific hypothesis, S most general hypothesis, G h H, between S and G is consistent and make up the version space (Mitchell, 1997)
Choose h with largest margin
Vapnik Chervonenkis dimension (VC Dimension) is a measure of the capacity of a statistical classification algorithm, defined as the cardinality of the largest set of points that the algorithm can shatter. It is a core concept in Vapnik Chervonenkis theory, and was originally defined by Vladimir Vapnik and Alexey Chervonenkis.
A classification model f with some parameter vector θ is said to shatter a set of data points (x 1,x,,x ) if, for all assignments of labels to those points, there exists a θ such that the model f makes no errors when evaluating that set of data points. Example : VC Dimension for linear classifier 3 points shattered 4 points impossible
points can be labeled in ways as +/ H shatters if there exists h H consistent for any of these: VC(H ) = An axis-aligned rectangle shatters 4 points only!
Use the simpler one because Simpler to use (lower computational complexity) Easier to train (lower space complexity) Easier to explain (more interpretable) Generalizes better (lower variance - Occam s razor) simpler explanations are more plausible and any unnecessary complexity should be shaved off.
Andaikan diberikan data training yang linearly separable menjadi dua kelas, yaitu A dan B. Terdapat banyak sekali hyperplane yang memisahkan kedua kelas dari data. Mana yang dipilih? Bagaimana menemukan hyperplane terbaik yang memisahkan kedua himpunan dengan margin terbesar? Margin: jarak hyperplane ke titik terdekat dari kedua himpunan Dalam dimensi, hyperplane garis Dalam 3 dimensi, hyperplane bidang
Persamaan hyperplane (garis) g: w 1 x 1 +w x +b=0 Agar g memisahkan kelas A dan B, maka dapat dipilih w 1,w dan b sehingga w 1 x 1 +w x +b>0 utk (x 1,x ) A w 1 x 1 +w x +b<0 utk (x 1,x ) B Andaikan (x 1+,x + ) dan (x 1-,x - ) masing-masing titik terdekat dari kelas A dan B terhadap g.tanpa mengurangi keumuman, dapat dipilih: w 1 x 1+ +w x + +b=1 dan w 1 x 1- +w x - +b=-1 dan w 1 x 1 +w x +b 1 utk (x 1,y 1 ) A w 1 x 1 +w x +b -1 utk (x 1,y 1 ) B
J Maka jarak garis g ke titik (x 1+,x + ) dan (x 1-,x - ) adalah w1 x1 w x b 1 w1 x1 w x b w w w w w w Definisikan: 1 1 1 y f ( x, x ) sign( x, x ) i ( i) ( i) ( i) ( i) 1 1 ( i) ( i) 1, untuk ( x1, x ) A ( i) ( i) 1, untuk ( x1, x ) B maka (w 1 x 1 +w x +b)y i 1, untuk I = 1,,,
Masalah Penentuan Hyperplane terbaik: Arg Max st.. wb, w ( i) ( i) 1 1 1 w 1 ( w x w x b) y 1, i 1,,.., i Ekivalen dengan 1 Arg Min w w wb, st.. ( i) ( i) 1 1 1 ( w x w x b) y 1, i 1,,.., i
Persamaan hyperplane g: w T x+b=0 Agar g memisahkan kelas A dan B, maka dapat dipilih w 1,w dan b sehingga w T x +b>0 utk x A w T x +b<0 utk x B Andaikan x + dan x - masing-masing titik terdekat dari kelas A dan B terhadap g.tanpa mengurangi keumuman, dapat dipilih: w T x + +b =1 dan w T x - +b = -1 dan w T x +b 1 utk x A w T x +b -1 utk x B
Maka jarak g ke titik x +,x + dan x - adalah J T T w x b 1 1 w x b w w w w w w w Definisikan: i T T T y f x sign x ( i) ( i) ( ) ( ) 1, untuk x 1, untuk x () i () i A B maka (w T x +b)y i 1, untuk i = 1,,,
Masalah Penentuan Hyperplane terbaik: 1 Arg Max wb, w st.. T () i ( ) i 1, 1,,.., w x b y i Ekivalen dengan Arg Min st.. wb, 1 T w w T () i ( ) i 1, 1,,.., w x b y i
Solusi x yang memaksimumkan/ meminimumkan fungsi f(x) yang memenuhi kendala g(x) = 0 diperoleh dari solusi persamaan f(x) = g(x) Contoh: Carilah nilai maksimum/minimum untuk fungsi f(x,y) = x +y yang memenuhi x-y = 1 Titik kritis diperoleh dari x = y = - x-y = 1 Diperoleh x = ½, y=-½, = 1 atau x- = 0 y + = 0 x-y = 1
Cari nilai maksimum/minimum f(x,y,z) = x + y +3z yang memenuhi x + y = dan y +z = 1 g 1 (x,y,z) = x + y - =0 g (x,y,z) = y + z 1 = 0 Solusi masalah maks/minimum diperoleh dari: f(x,y,z) = 1 g 1 (x,y,z) + g (x,y,z)
Solusi x yang memaksimumkan/meminimumkan fungsi f(x) yang memenuhi kendala g(x) = 0 diperoleh dari solusi persamaan f(x) = g(x) Versi lain: L(x, ) = f(x)+g(x) Solusi masalah maksimum/minimum diperoleh dari L(x, ) = 0 L dikenal sebagai Lagrangian
Solusi masalah optimasi (primal) Min f(x), x s.t. g(x) 0 dan h(x)=0 Feasible Domain D={x g(x)0, h(x)=0} Lagrangian L(x,, ) = f(x)+g(x)+ h(x) Dual Problem Max (, ) s.t. 0 (, ) = inf x L(x,, ) Untuk setiap titik feasible x, (, ) L(x,, ) f(x) Duality Gap = f(x) - (, ) Dengan memaksimumkan (, ) terhadap dan, akan meminimumkan duality gap. Khususnya, Jika g dan h fungsi Affine, yaitu g(x) = Ax b ( A matriks, b vektor) maka duality gap menjadi 0. Artinya, solusi masalah primal ekivalen dengan solusi masalah dual.
Solusi masalah optimasi (primal) Min x +y, s.t. x-y 1 Untuk suatu nilai yang diberikan, agar L minimum x + = 0 y - = 0 Lagrangian L(x,y, ) = x +y +(x-y-1) Dual Problem Max () = ¼ + ¼ +(-/-/-1) = - / - s.t. 0 Diperoleh =0, x = 0 dan y = 0 Ini berarti constraint tidak aktif!!!
Solusi masalah optimasi (primal) Min x +y, s.t. x-y 1 Agar L minimum x - = 0 y + = 0 Lagrangian L(x,y, ) = x +y -(x-y-1) Dual Problem Max (, ) = ¼ + ¼ -(/+/-1) = - / + s.t. 0 Diperoleh =1, x = 1/ dan y = -1/ Ini berarti constraint aktif, artinya nilai minimum tercapai pada batas constraint.
1 Arg Min w w wb, st.. ( i) ( i) 1 1 1 L( w, w, b, ) ( w w ) ( w x w x b) yi 1 ( i) ( i) 1 1 i 1 1 i1 () i () i w ix yi 0 1i 1 i 0 i1 i1 i1 w x y 1 ( w x w x b) y 1, i 1,,.., ilai minimum L diperoleh dari : L( w1, w, b, ) 0 yaitu i y i i 0
Substitusi ke Lagrangian: 1 ( ) ( i) ( i) ix1 y i ix yi i1 i1 ( i) ( i) ( i) ( i) i ix1 yi x1 ix yi x by j 1 j1 i1 i1 diperoleh 1 ( ) ( i) ( i) ix1 y i ix yi i1 i1 ( i) ( i) ( i) ( i) j ix1 yi x1 ix yi x y j 1 i1 i1 i1
1 ( ) Studi Kasus ( i) ( i) ix1 y i ix yi i1 i1 ( i) ( i) ( i) ( i) j ix1 yi x1 ix yi x y j 1 j1 i1 i1 Max st.. i ( ) 0, i1,,..., Cari hyperplane classifier terbaik untuk data training P 1 (1,0), P (0,1), P 3 (,), dan Q 1 (-1,0), Q (0,-1),
(1) Generate Dual Problem untuk dataset tersebut () Tentukan nilai alpha[i], i=1,,..,5 yang optimal (Hint: Gunakan gradient ascent dgn tambahan : if alpha < 0 then alpha = 0) (3) Tentukan nilai w1, w dan b