svm#
Module: svm
#
Helper functions for SVMs#
This module contains functions used for the SVM lab of ISLP. Currently it contains just a simple function to plot decision boundary and points through a two-dimensional slice for an SVM classifier.
- ISLP.svm.plot(X, Y, svm, features=(0, 1), xlim=None, nx=300, ylim=None, ny=300, ax=None, decision_cmap=<matplotlib.colors.ListedColormap object>, scatter_cmap=<matplotlib.colors.ListedColormap object>, alpha=0.2)#
Graphical representation of fitted support vector classifier.
There are two types of support vectors:
Points violating the margin but correctly classified. These are marked with a black ‘+’.
Misclassified points. These are marked with a red ‘x’.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Features used in fitting svm. Assumed to have at least 2 columns.
- Yarray-like of shape (n_samples,)
Labels used in fitting svm. Used to color points by class.
- svmsklearn.svm.SVC
Fitted support vector classifier. Assumed that svm has been fit on (X,Y).
- features(int, int), default=(0, 1)
Which columns of X used for plotting. If more then two features, remaining features are set at mean values for 2-dimensional slice.
- xlim(float, float), optional
Range of values for x-axis of plot.
- nxint, default=300
Resolution of grid for x-axis.
- ylim(float, float), optional
Range of values for y-axis of plot.
- nyint, default=300
Resolution of grid for y-axis.
- axa matplotlib axis
- decision_cmapa matplotlib colormap for coloring decision rule.
- scatter_cmapa matplotlib colormap for coloring points by class.
- alphafloat
Alpha level for opacity of decision rule.