# Python代写 | Introduction to Statistical Machine Learning

Introduction to Statistical Machine Learning

Coding
• Please implement soft margin binary class linear SVMs by:
− Solving the primal problem:
min
w,b,ξ
kwk
2
2 + C ·
1
n
Xn
i=1
ξi
s.t. yi(w
T
xi + b) ≥ 1 − ξi
ξi ≥ 0, i = 1, …, n
(1)
− Solving the dual problem:
max
α
Xn
i=1
αi −
1
2
Xn
i=1
Xn
j=1
αiαjyiyjx
T
i xj
s.t.
Xn
i=1
αiyi = 0
0 ≤ αi ≤ C, i = 1, …, n
(2)
Your code should strictly implement the functions that are in the form of the prototypes
below. Otherwise you may not get marks even if your experiment results are correct.
Other necessary functions such as data IO, plotting, analysis of results etc. and anything else can be in
any form.
1
2
3 # train your svm in the primal
4 svm_model = svm_train_primal ( data_train , label_train , regularisation_para_C )
5
6 # test on your test data
7 test_accuracy = svm_predict_primal ( data_test , label_test , svm_model )
8
9 # …
10
11 # train your svm in the dual
12 svm_model_d = svm_train_dual ( data_train , label_train , regularisation_para_C )
13
14 # test on your test data
15 test_accuracy_d = svm_predict_dual ( data_test , label_test , svm_model_d )
NB: ‘regularisation para C’ is the hyper-parameter C in the above two equations and typically need to
be determinted by cross-validation if you want to achieve good accuracy on test data.
Examples that do not follow the coding requirement:
a) Input and output arguments are not the same as above prototypes, such as:
… … svm train primal( data train , label train , regularisation para C, kernel para )
b) Implement SVM as a CLASS. Do not implement SVM as a CLASS! E-mail: [email protected]  微信:itcsdx 