Soft margin SVM

Make fake data to see the effect of C on decision boundary and margin width.

Train classifier with C=1000 (to approach hard margin SVM),

which yields a smaller margin and classifies training examples better.

Repeat the last block of code (oops), this time with with C=1,

which yields a larger margin suited to noisy data but makes training errors.

More practice with soft margin SVM:

guess transmission type from car weight and mileage

Nonlinear boundary: use kernel trick

Make fake data consisting of (noisy) concentric circles.

These are not linearly separable in 2D.

Plot data.

Make 3D plot of transformed data to understand how kernel trick can help.

The transformed data are easy to separate linearly with a plane. The kernel trick avoids this explicit transformation but has the same effect.

Notice that a linear SVM gives low accuracy.

The kernel trick's implicit transformation into higher dimensions works well.