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:
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from sklearn.svm import SVC
from cvxopt import matrix as cvxoptmatrix
from cvxopt import solvers as cvxoptsolvers
#Data set
# blanks data
#Data for the next section
X # blanks predictors #
y # blanks target #
#Initializing values and computing H Note the to force to float type
mn Xshape
y yreshape
Xdash y X
H npdotXdash Xdash.T
#Converting into cvxopt format
P # blank #
q # blank #
G # blank #
h # blank #
A cvxoptmatrixyreshape
b # blank #
#Setting solver parameters change default to decrease tolerance
cvxoptsolvers.optionsshowprogress' False
cvxoptsolvers.optionsabstole
cvxoptsolvers.optionsreltole
cvxoptsolvers.optionsfeastole
#Run solver
sol cvxoptsolvers.qpP q G h A b
alphas nparraysolx
#w parameter in vectorized form
w # blank #
#Selecting the set of indices S corresponding to non zero parameters
S alphas eflatten
#Computing b
b # blanks #
#Display results
printAlphas alphasalphas e
printw wflatten
printb b Problem
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 TDAT' available on webcourse. The first column represents our binary response variable and the last two columns our predictors.
a The file svmsepppy 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 boldsymbolalpha number of support vectors,
