Homework 7: Linear Support Vector Machine (SVM)
Submit your assignments on Gradescope.
Please name your coding assignment as ‘HW7.py’.
Use the provided Python template file, and complete the functions ONLY. (DO NOT edit function
definitions, code outside the function, or use other libraries).
In this homework, you have been provided with the read_data(), get_df_shape(), data_split(), and
extract_features_label() functions to help you with your implementation.
The functions you will be graded on have detailed information on the starter code.
This homework is about the linear support vector machine covered in the Week 7 lecture. Please refer to
the lecture slides for more information about the implementation of the linear SVM.
This is a coding assignment.
You will be implementing the training function for the Linear SVM model.
We have separated the function into three individual test cases for extra guidance in your implementation
(cost(.), decision_function(.), margin(.) ).
Your code will be tested on,
1. Cost Function (25 Points)
The cost function implements Hinge loss and regularization term (w.w) as described in
W_7_M_SupportVectorMachine notes, slides 25-27.
2. Margin Function (25 Points)
Your margin function implementation will be evaluated by looking at the margin array in the fit function.
(slides 24)
You will be implementing the fit function, use the update rule given in W_7_W_SupportVectorMachines,
slides 24, Only update if misclassified (else part in the slides), which also means that points are in the
margin!
your code will be tested,
3. Predict Function (25 Points)
Implement your predict function using your decision function implementation.
4. Train Score (25 Points)
Implement the train score in the score() function.