Before we dive into the code part, lets see some math equations.

  • For all x in training Data:
     xi.w + b <= -1   if yi = -1 (belongs to -ve class)
     xi.w + b >= +1	if yi = +1 (belongs to +ve class)
    
  • For all support vectors which decide the margin
    xi.w+b = -1    here xi is -ve SV and yi is -1
    xi.w+b = +1    here xi is +ve SV and yi is +1
    
  • For decision boudary yi(xi.w+b)=0
  • Our goal is maximize Width W
    W = ((X+ - X-).w)/|w|
    
  • The goal is to minimize ||w||2/2 Code part