python实现svm_引入python包cvxopt从头开始实现svm

python实现svm

CVXOPT is a free python package that is widely used in solving the convex optimization problem. In this article, I will first introduce the use of CVXOPT in quadratic programming, and then discuss its application in implementing Support Vector Machine (SVM) by solving the dual optimization problem.

CVXOPT是一个免费的python软件包,广泛用于解决凸优化问题。 在本文中,我将首先介绍CVXOPT在二次编程中的用途,然后通过解决双重优化问题来讨论其在实现支持向量机(SVM)中的应用。

如何使用CVXOPT解决优化问题 (How to use CVXOPT to solve an optimization problem)

To understand how to use CVXOPT, we need to know its standard form and apply it to each individual question. According to CVXOPT API, we can solve the optimization problem in this form:

要了解如何使用CVXOPT,我们需要了解其标准格式并将其应用于每个单独的问题。 根据CVXOPT API,我们可以通过以下形式解决优化问题:

python实现svm_引入python包cvxopt从头开始实现svm_第1张图片
standard form 标准格式

It is solving a minimization problem, with two types of linear constraints. One is an inequality constraint, and another is an equality constraint. To use the package to solve for the best x, that minimizing the object function, under the linear constraints, we just need to transform the specific question to identify matrics P, q, G, h, A, b.

它正在解决具有两种线性约束的最小化问题。 一个是不平等约束,另一个是平等约束。 为了使用包来求解最佳x,从而在线性约束下最小化目标函数,我们只需要变换特定问题即可识别矩阵P,q,G,h,A,b。

Let’s take a simple example from here:

让我们从这里举一个简单的例子:

python实现svm_引入python包cvxopt从头开始实现svm_第2张图片
an example 一个例子

In this example, we have two variables we need to solve for optimization, which is x1 and x2. First, look at the objective function 2x1² +x2² +x1x2+x1+x2, we can rewrite it as its matrix form:

在此示例中,我们需要求解两个变量以进行优化,分别是x1和x2。 首先,查看目标函数2x1

你可能感兴趣的:(python)