Due: October 19th at 11:59pm
Formulate a soft-margin SVM without the bias term, i.e. one where the discriminant function is equal to $\mathbf{w}^{T} \mathbf{x}$. Derive the saddle point conditions, KKT conditions and the dual. Compare it to the standard SVM formulation that was derived in class.
Part 1 answer
Suppose you are given a linearly separable dataset, and you are training the soft-margin SVM, which uses slack variables with the soft-margin constant $C$ set to some positive value. Consider the following statement:
Since increasing the $\xi_i$ can only increase the cost function of the primal problem (which we are trying to minimize), at the solution to the primal problem, i.e. the hyperplane that minimizes the primal cost function, all the training examples will have $\xi_i$ equal to zero.
Is this true or false? Explain!
Your answer for part 2
The data for this question comes from a database called SCOP (structural classification of proteins), which classifies proteins into classes according to their structure (download it from here. The data is a two-class classification problem of distinguishing a particular class of proteins from a selection of examples sampled from the rest of the SCOP database using features derived from their sequence (a protein is a chain of amino acids, so as computer scientists, we can consider it as a sequence over the alphabet of the 20 amino acids). I chose to represent the proteins in terms of their sequence motif composition. A sequence motif is a pattern of amino acids (or DNA) that is conserved in evolution. Motifs are usually associated with regions of the protein that are important for its function, and are therefore useful in differentiating between classes of proteins. A given protein will typically contain only a handful of motifs, and so the data is very sparse. Therefore, only the non-zero elements of the data are represented. Each line in the file describes a single example. Here's an example from the file:
d1scta_,a.1.1.2 31417:1.0 32645:1.0 39208:1.0 42164:1.0 ....
The first column is the identifier of the protein, the second is the class it belongs to (the values for the class variable are a.1.1.2
, which is the given class of proteins, and rest
which is the negative class representing the rest of the database); the remainder consists of tokens of the form feature_id:value
which provide an id of a feature and the value associated with it.
This is an extension of the format used by LibSVM, that scikit-learn can read.
See a discussion of this format and how to read it here.
We note that the data is very high dimensional since the number of conserved patterns in the space of all proteins is large. The data was constructed as part of the following analysis of detecting distant relationships between proteins:
Your task is to explore the dependence of classifier accuracy on the kernel, kernel parameters, kernel normalization, and the SVM soft-margin parameter. In your implementation you can use the scikit-learn svm class.
Use both the Gaussian and polynomial kernels: $$ K_{gauss}(\mathbf{x}, \mathbf{x'}) = \exp(-\gamma || \mathbf{x} - \mathbf{x}' ||^2) $$ and $$ K_{poly}(\mathbf{x}, \mathbf{x'}) = (\mathbf{x}^T \mathbf{x}' + 1) ^{p}. $$
When using scikit-learn make sure you use the version of the polynomial kernel shown above (the scikit-learn default is the homogeneous polynomial kernel). Plot the accuracy of the SVM, measured using the area under the ROC curve as a function of both the soft-margin parameter of the SVM, and the free parameter of the kernel function. Accuracy should be measured in five-fold cross-validation. Show a couple of representative cross sections of this plot for a given value of the soft margin parameter, and for a given value of the kernel parameter. Comment on the results. When exploring the values of a continuous classifier/kernel parameter it is useful to use values that are distributed on an exponential grid, i.e. something like 0.01, 0.1, 1, 10, 100 (note that the degree of the polynomial kernel is not such a parameter).
Next, compare the accuracy of an SVM with a Gaussian kernel on the raw data with accuracy obtained when the data is normalized to be unit vectors (the values of the features of each example are divided by its norm). This is different than standardization which operates at the level of individual features. Normalizing to unit vectors is more appropriate for this dataset as it is sparse, i.e. most of the features are zero. Perform your comparison by comparing the accuracy measured by the area under the ROC curve using five-fold nested cross validation, where the classifier/kernel parameters are chosen using grid search. Use the scikit-learn grid search class for model selection. As a reference, compare the results with those obtained using a linear SVM and with regularized logistic regression, where model selection us performed by nested cross-validation.
Perform a similar comparison of Linear SVM, SVM with a Gaussian kernel, and Logistic regression on an additional dataset of your choice. Depending on the dataset chosen, your data may benefit from normalization to unit vectors or standardization. Comment on the results, and describe what you have learned from these comparisons.
Your final task is to visualize the kernel matrix associated with the dataset. Use the kernel matrix associated with the linear kernel. Explain the structure that you are seeing in the plot (it is more interesting when the data is normalized).
# Your answer here.
Answer the questions in the cells reserved for that purpose.
Mathematical equations should be written as LaTex equations; the assignment contains multiple examples of both inline formulas (such as the one exemplifying the notation for the norm of a vector $||\mathbf{x}||$ and those that appear on separate lines, e.g.:
$$ ||\mathbf{x}|| = \sqrt{\mathbf{x}^T \mathbf{x}}. $$Submit your report as a Jupyter notebook via Canvas. Running the notebook should generate all the plots and results in your notebook.
Here is what the grade sheet will look like for this assignment. A few general guidelines for this and future assignments in the course:
Grading sheet for the assignment:
Part 1: 40 points.
( 5 points): Primal SVM formulation is correct
(10 points): Lagrangian found correctly
(10 points): Derivation of saddle point equations
(15 points): Derivation of the dual
Part 2: 20 points.
Part 3: 40 points.
(20 points): Accuracy as a function of parameters and discussion of the results
(15 points): Comparison of normalized and non-normalized kernels and correct model selection
( 5 points): Visualization of the kernel matrix and observations made about it
Grading will be based on the following criteria: