Question: Use Python to solve. Below are the data and python code to fill: 1 2 1 0 8 3 6 8 1 1 1 3

Use Python to solve. Below are the data and python code to fill:
12108368
11131355
11105469
1286506
1199402
1287423
1194440
12117489
1279432
1199403
11114428
12123372
11123372
12109420
12112394
11104407
12111422
12126423
12105434
11119474
11114396
12100470
1284399
12102429
12101469
1285444
11109397
12106442
1182431
12118381
11105388
11121403
1185451
1183453
1153427
1195411
1176442
1195426
1287402
1170397
1284511
1291469
1174451
12101474
1180398
1195433
1292404
1199481
1294491
1187480
21129420
21148371
21179407
22152381
22166377
22124389
21156419
22131345
21140362
22144345
22149393
21108330
21135355
22170386
21152301
21153397
21152301
22136438
22122306
21148383
2290385
21145337
21123364
22145376
22115354
22134383
21117355
22126345
21118379
22120369
21153403
22150354
21154390
21155349
22109325
22117344
21128400
21144403
22163370
22145355
21133375
21128383
22123349
21144373
22140388
22150339
22124341
21125346
21153352
21108339
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from sklearn.svm import SVC
from cvxopt import matrix as cvxopt_matrix
from cvxopt import solvers as cvxopt_solvers
#Data set
# blanks (data)
#Data for the next section
X = # blanks (predictors) #
y = # blanks (target) #
#Initializing values and computing H. Note the 1. to force to float type
m,n = X.shape
y = y.reshape(-1,1)*1.
X_dash = y * X
H = np.dot(X_dash , X_dash.T)*1.
#Converting into cvxopt format
P = # blank(1) #
q = # blank(2) #
G = # blank(3) #
h = # blank(4) #
A = cvxopt_matrix(y.reshape(1,-1))
b = # blank(5) #
#Setting solver parameters (change default to decrease tolerance)
cvxopt_solvers.options['show_progress']= False
cvxopt_solvers.options['abstol']=1e-10
cvxopt_solvers.options['reltol']=1e-10
cvxopt_solvers.options['feastol']=1e-10
#Run solver
sol = cvxopt_solvers.qp(P, q, G, h, A, b)
alphas = np.array(sol['x'])
#w parameter in vectorized form
w = # blank(6) #
#Selecting the set of indices S corresponding to non zero parameters
S =(alphas >1e-4).flatten()
#Computing b
b = # blanks(7) #
#Display results
print('Alphas =',alphas[alphas >1e-4])
print('w =', w.flatten())
print('b =', b) Problem 2
In this problem, we will implement the SVM dual problem code in Python using 'CVXOPT' library. 'CVXOPT' is a library to solve convex optimization problems as well as quadratic optimization problems. We will be using the dataset 'T11-2.DAT' available on webcourse. The first column represents our binary response variable and the last two columns our predictors.
a. The file 'svm_sep_p.py' is posted on webcourse. This code assumes that the data set is linear separable. Consequently, we will use the SVM dual problem for this question. Fill in the blanks and execute the procedure. Report the values of '\(\boldsymbol{\alpha}\)', number of support vectors,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!