Scikit Learn-支持向量机

Scikit Learn-支持向量机 (Scikit Learn - Support Vector Machines)

This chapter deals with a machine learning method termed as Support Vector Machines (SVMs).

本章介绍了一种称为支持向量机(SVM)的机器学习方法。

介绍 (Introduction)

Support vector machines (SVMs) are powerful yet flexible supervised machine learning methods used for classification, regression, and, outliers’ detection. SVMs are very efficient in high dimensional spaces and generally are used in classification problems. SVMs are popular and memory efficient because they use a subset of training points in the decision function.

支持向量机(SVM)是强大而灵活的监督型机器学习方法,用于分类,回归和离群值检测。 SVM在高维空间中非常有效,通常用于分类问题。 SVM受欢迎且具有存储效率,因为它们在决策函数中使用训练点的子集。

The main goal of SVMs is to divide the datasets into number of classes in order to find a maximum marginal hyperplane (MMH) which can be done in the following two steps −

SVM的主要目标是将数据集分为几类,以找到最大的边际超平面(MMH) ,可以在以下两个步骤中完成-

  • Support Vector Machines will first generate hyperplanes iteratively that separates the classes in the best way.

    支持向量机将首先以迭代方式生成超平面,从而以最佳方式分隔类。

  • After that it will choose the hyperplane that segregate the classes correctly.

    之后,它将选择正确隔离类的超平面。

Some important concepts in SVM are as follows −

SVM中的一些重要概念如下-

  • Support Vectors − They may be defined as the datapoints which are closest to the hyperplane. Support vectors help in deciding the separating line.

    支持向量 -它们可以定义为最接近超平面的数据点。 支持向量有助于确定分隔线。

  • Hyperplane − The decision plane or space that divides set of objects having different classes.

    超平面 -划分具有不同类别的对象集的决策平面或空间。

  • Margin − The gap between two lines on the closet data points of different classes is called margin.

    裕度 -不同类别的壁橱数据点上的两条线之间的间隙称为裕度。

Following diagrams will give you an insight about these SVM concepts −

下图将为您提供有关这些SVM概念的见解-

Marginal Hyperplane

SVM in Scikit-learn supports both sparse and dense sample vectors as input.

Scikit-learn中的SVM支持稀疏和密集样本矢量作为输入。

支持向量机的分类 (Classification of SVM)

Scikit-learn provides three classes namely SVC, NuSVC and LinearSVC which can perform multiclass-class classification.

Scikit-learn提供三个类,即SVC,NuSVCLinearSVC ,它们可以执行多类分类。

SVC (SVC)

It is C-support vector classification whose implementation is based on libsvm. The module used by scikit-learn is sklearn.svm.SVC. This class handles the multiclass support according to one-vs-one scheme.

这是C支持向量分类,其实现基于libsvm 。 scikit-learn使用的模块是sklearn.svm.SVC 。 此类根据一对一方案处理多类支持。

参量 (Parameters)

Followings table consist the parameters used by sklearn.svm.SVC class −

followings表包含sklearn.svm.SVC类使用的参数-

Sr.NoParameter & Description
1

C − float, optional, default = 1.0

It is the penalty parameter of the error term.

2

kernel − string, optional, default = ‘rbf’

This parameter specifies the type of kernel to be used in the algorithm. we can choose any one among, ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’. The default value of kernel would be ‘rbf’.

3

degree − int, optional, default = 3

It represents the degree of the ‘poly’ kernel function and will be ignored by all other kernels.

4

gamma − {‘scale’, ‘auto’} or float,

It is the kernel coefficient for kernels ‘rbf’, ‘poly’ and ‘sigmoid’.

5

optinal default − = ‘scale’

If you choose default i.e. gamma = ‘scale’ then the value of gamma to be used by SVC is 1/(𝑛_𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠∗𝑋.𝑣𝑎𝑟()).

On the other hand, if gamma= ‘auto’, it uses 1/𝑛_𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠.

6

coef0 − float, optional, Default=0.0

An independent term in kernel function which is only significant in ‘poly’ and ‘sigmoid’.

7

tol − float, optional, default = 1.e-3

This parameter represents the stopping criterion for iterations.

8

shrinking − Boolean, optional, default = True

This parameter represents that whether we want to use shrinking heuristic or not.

9

verbose − Boolean, default: false

It enables or disable verbose output. Its default value is false.

10

probability − boolean, optional, default = true

This parameter enables or disables probability estimates. The default value is false, but it must be enabled before we call fit.

11

max_iter − int, optional, default = -1

As name suggest, it represents the maximum number of iterations within the solver. Value -1 means there is no limit on the number of iterations.

12

cache_size − float, optional

This parameter will specify the size of the kernel cache. The value will be in MB(MegaBytes).

13

random_state − int, RandomState instance or None, optional, default = none

This parameter represents the seed of the pseudo random number generated which is used while shuffling the data. Followings are the options −

  • int − In this case, random_state is the seed used by random number generator.

  • RandomState instance − In this case, random_state is the random number generator.

  • None − In this case, the random number generator is the RandonState instance used by np.random.

14

class_weight − {dict, ‘balanced’}, optional

This parameter will set the parameter C of class j to 𝑐𝑙𝑎𝑠𝑠_𝑤𝑒𝑖𝑔ℎ𝑡[𝑗]∗𝐶 for SVC. If we use the default option, it means all the classes are supposed to have weight one. On the other hand, if you choose class_weight:balanced, it will use the values of y to automatically adjust weights.

15

decision_function_shape − ovo’, ‘ovr’, default = ‘ovr’

This parameter will decide whether the algorithm will return ‘ovr’ (one-vs-rest) decision function of shape as all other classifiers, or the original ovo(one-vs-one) decision function of libsvm.

16

break_ties − boolean, optional, default = false

True − The predict will break ties according to the confidence values of decision_function

False − The predict will return the first class among the tied classes.

序号 参数及说明
1个

C −浮动,可选,默认= 1.0

它是误差项的惩罚参数。

2

内核 -字符串,可选,默认='rbf'

此参数指定算法中要使用的内核类型。 我们可以选择“线性”,“多边形”,“ rbf”,“ Sigmoid”,“预计算”中的任意一种。 kernel的默认值为'rbf'

3

-int,可选,默认= 3

它代表“多边形”内核功能的程度,并且将被所有其他内核忽略。

4

伽玛 -{'scale','auto'}或float,

它是内核“ rbf”,“ poly”和“ Sigmoid”的内核系数。

5

最佳默认值 -='scale'

如果选择默认值,即gamma ='scale',则SVC使用的gamma值为1 /(𝑛_𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠∗𝑋.𝑣𝑎𝑟())。

另一方面,如果gamma ='auto',则使用1 /𝑛_𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠。

6

coef0-浮动,可选,默认值= 0.0

内核函数中的一个独立术语,仅对“ poly”和“ Sigmoid”有效。

7

tol-浮动,可选,默认= 1.e-3

此参数表示迭代的停止标准。

8

收缩 -布尔值,可选,默认= True

此参数表示我们是否要使用缩减启发式。

9

详细 -布尔值,默认值:false

它启用或禁用详细输出。 其默认值为false。

10

概率 -布尔值,可选,默认= true

此参数启用或禁用概率估计。 默认值为false,但必须先启用它才能调用fit。

11

max_iter -int,可选,默认= -1

顾名思义,它表示求解器中的最大迭代次数。 值-1表示对迭代次数没有限制。

12

cache_size-浮点数,可选

此参数将指定内核缓存的大小。 该值将以MB(兆字节)为单位。

13

random_state -int,RandomState实例或无,可选,默认=无

此参数表示生成的伪随机数的种子,在对数据进行混洗时会使用该种子。 以下是选项-

  • INT -在这种情况下,random_state是由随机数生成所使用的种子。

  • RandomState实例 -在这种情况下,random_state是随机数生成器。

  • -在这种情况下,随机数生成器是np.random使用的RandonState实例。

14

class_weight- {dict,'balanced'},可选

对于SVC,此参数会将类别j的参数C设置为__ [[]]。 如果使用默认选项,则意味着所有类都应具有权重一。 另一方面,如果选择class_weight:balanced ,它将使用y的值自动调整权重。

15

decision_function_shape -大毛”, 'OVR',默认值为'OVR'

该参数将决定算法是否返回像所有其他分类器一样的shape的'ovr' (One-VS- Rest )决策函数,或者是libsvm的原始ovo (One-VS-One)决策函数。

16

break_ties-布尔值,可选,默认= false

正确 -预测将根据Decision_function的置信度值打破平局

False-预测将返回绑定类中的第一类。

属性 (Attributes)

Followings table consist the attributes used by sklearn.svm.SVC class −

followings表包含sklearn.svm.SVC类使用的属性-

Sr.NoAttributes & Description
1

support_ − array-like, shape = [n_SV]

It returns the indices of support vectors.

2

support_vectors_ − array-like, shape = [n_SV, n_features]

It returns the support vectors.

3

n_support_ − array-like, dtype=int32, shape = [n_class]

It represents the number of support vectors for each class.

4

dual_coef_ − array, shape = [n_class-1,n_SV]

These are the coefficient of the support vectors in the decision function.

5

coef_ − array, shape = [n_class * (n_class-1)/2, n_features]

This attribute, only available in case of linear kernel, provides the weight assigned to the features.

6

intercept_ − array, shape = [n_class * (n_class-1)/2]

It represents the independent term (constant) in decision function.

7

fit_status_ − int

The output would be 0 if it is correctly fitted. The output would be 1 if it is incorrectly fitted.

8

classes_ − array of shape = [n_classes]

It gives the labels of the classes.

序号 属性和说明
1个

support_-类数组,形状= [n_SV]

它返回支持向量的索引。

2

support_vectors_-类数组,形状= [n_SV,n_features]

它返回支持向量。

3

n_support_-类似于数组,dtype = int32,形状= [n_class]

它代表每个类的支持向量的数量。

4

dual_coef_ −数组,形状= [n_class-1,n_SV]

这些是决策函数中支持向量的系数。

5

coef_ −数组,形状= [n_class *(n_class-1)/ 2,n_features]

此属性仅在线性核的情况下可用,提供分配给要素的权重。

6

intercept_ -阵列,形状= [n_class *(n_class-1)/ 2]

它代表决策功能中的独立项(常数)。

7

fit_status_-整数

如果正确安装,输出将为0。 如果安装不正确,输出将为1。

8

classes_-形状数组= [n_classes]

它给出了类别的标签。

Implementation Example

实施实例

Like other classifiers, SVC also has to be fitted with following two arrays −

像其他分类器一样,SVC还必须配备以下两个数组-

  • An array X holding the training samples. It is of size [n_samples, n_features].

    存放训练样本的数组X。 它的大小为[n_samples,n_features]。

  • An array Y holding the target values i.e. class labels for the training samples. It is of size [n_samples].

    保存目标值的数组Y ,即训练样本的类别标签。 它的大小为[n_samples]。

Following Python script uses sklearn.svm.SVC class −

以下Python脚本使用sklearn.svm.SVC类-


import numpy as np
X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
y = np.array([1, 1, 2, 2])
from sklearn.svm import SVC
SVCClf = SVC(kernel = 'linear',gamma = 'scale', shrinking = False,)
SVCClf.fit(X, y)

Output

输出量


SVC(C = 1.0, cache_size = 200, class_weight = None, coef0 = 0.0,
   decision_function_shape = 'ovr', degree = 3, gamma = 'scale', kernel = 'linear',
   max_iter = -1, probability = False, random_state = None, shrinking = False,
   tol = 0.001, verbose = False)

Example

Now, once fitted, we can get the weight vector with the help of following python script −

现在,一旦拟合,我们就可以在以下python脚本的帮助下获得权重向量-


SVCClf.coef_

Output

输出量


array([[0.5, 0.5]])

Example

Similarly, we can get the value of other attributes as follows −

类似地,我们可以获取其他属性的值,如下所示:


SVCClf.predict([[-0.5,-0.8]])

Output

输出量


array([1])

Example


SVCClf.n_support_

Output

输出量


array([1, 1])

Example


SVCClf.support_vectors_

Output

输出量


array(
   [
      [-1., -1.],
      [ 1., 1.]
   ]
)

Example


SVCClf.support_

Output

输出量


array([0, 2])

Example


SVCClf.intercept_

Output

输出量


array([-0.])

Example


SVCClf.fit_status_

Output

输出量


0

NuSVC (NuSVC)

NuSVC is Nu Support Vector Classification. It is another class provided by scikit-learn which can perform multi-class classification. It is like SVC but NuSVC accepts slightly different sets of parameters. The parameter which is different from SVC is as follows −

NuSVC是Nu支持向量分类。 它是scikit-learn提供的另一个类,可以执行多类分类。 就像SVC一样,但是NuSVC接受略有不同的参数集。 与SVC不同的参数如下-

  • nu − float, optional, default = 0.5

    nu-浮动,可选,默认= 0.5

It represents an upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. Its value should be in the interval of (o,1].

它代表训练误差分数的上限和支持向量分数的下限。 其值应在(o,1]的间隔内。

Rest of the parameters and attributes are same as of SVC.

其余参数和属性与SVC相同。

实施实例 (Implementation Example)

We can implement the same example using sklearn.svm.NuSVC class also.

我们也可以使用sklearn.svm.NuSVC类实现相同的示例。


import numpy as np
X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]])
y = np.array([1, 1, 2, 2])
from sklearn.svm import NuSVC
NuSVCClf = NuSVC(kernel = 'linear',gamma = 'scale', shrinking = False,)
NuSVCClf.fit(X, y)

输出量 (Output)


NuSVC(cache_size = 200, class_weight = None, coef0 = 0.0,
   decision_function_shape = 'ovr', degree = 3, gamma = 'scale', kernel = 'linear',
   max_iter = -1, nu = 0.5, probability = False, random_state = None,
   shrinking = False, tol = 0.001, verbose = False)

We can get the outputs of rest of the attributes as did in the case of SVC.

我们可以像SVC一样获得其余属性的输出。

线性SVC (LinearSVC)

It is Linear Support Vector Classification. It is similar to SVC having kernel = ‘linear’. The difference between them is that LinearSVC implemented in terms of liblinear while SVC is implemented in libsvm. That’s the reason LinearSVC has more flexibility in the choice of penalties and loss functions. It also scales better to large number of samples.

这是线性支持向量分类。 它类似于具有内核=“线性”的SVC。 它们之间的区别在于LinearSVC是根据liblinear实现的,而SVC是在libsvm中实现的。 这就是LinearSVC在罚分和损失函数选择方面具有更大灵活性的原因。 它还可以更好地扩展到大量样本。

If we talk about its parameters and attributes then it does not support ‘kernel’ because it is assumed to be linear and it also lacks some of the attributes like support_, support_vectors_, n_support_, fit_status_ and, dual_coef_.

如果我们谈论它的参数和属性,那么它就不支持“内核”,因为它被认为是线性的,并且还缺少一些属性,例如support_,support_vectors_,n_support_,fit_status_dual_coef_

However, it supports penalty and loss parameters as follows −

但是,它支持惩罚损失参数,如下所示:

  • penalty − string, L1 or L2(default = ‘L2’)

    惩罚-字符串,L1或L2(默认='L2')

    This parameter is used to specify the norm (L1 or L2) used in penalization (regularization).

    此参数用于指定惩罚(正则化)中使用的标准(L1或L2)。

  • loss − string, hinge, squared_hinge (default = squared_hinge)

    loss-字符串,铰链,squared_hinge(默认值= squared_hinge)

    It represents the loss function where ‘hinge’ is the standard SVM loss and ‘squared_hinge’ is the square of hinge loss.

    它表示损耗函数,其中“铰链”是标准SVM损耗,“ squared_hinge”是铰链损耗的平方。

实施实例 (Implementation Example)

Following Python script uses sklearn.svm.LinearSVC class −

以下Python脚本使用sklearn.svm.LinearSVC类-


from sklearn.svm import LinearSVC
from sklearn.datasets import make_classification
X, y = make_classification(n_features = 4, random_state = 0)
LSVCClf = LinearSVC(dual = False, random_state = 0, penalty = 'l1',tol = 1e-5)
LSVCClf.fit(X, y)

输出量 (Output)


LinearSVC(C = 1.0, class_weight = None, dual = False, fit_intercept = True,
   intercept_scaling = 1, loss = 'squared_hinge', max_iter = 1000,
   multi_class = 'ovr', penalty = 'l1', random_state = 0, tol = 1e-05, verbose = 0)

(Example)

Now, once fitted, the model can predict new values as follows −

现在,一旦拟合,模型可以预测新值,如下所示:


LSVCClf.predict([[0,0,0,0]])

输出量 (Output)


[1]

(Example)

For the above example, we can get the weight vector with the help of following python script −

对于上面的示例,我们可以借助以下python脚本获取权重向量-


LSVCClf.coef_

输出量 (Output)


[[0. 0. 0.91214955 0.22630686]]

(Example)

Similarly, we can get the value of intercept with the help of following python script −

同样,我们可以在以下python脚本的帮助下获取拦截的值-


LSVCClf.intercept_

输出量 (Output)


[0.26860518]

支持向量机回归 (Regression with SVM)

As discussed earlier, SVM is used for both classification and regression problems. Scikit-learn’s method of Support Vector Classification (SVC) can be extended to solve regression problems as well. That extended method is called Support Vector Regression (SVR).

如前所述,SVM用于分类和回归问题。 Scikit-learn的支持向量分类(SVC)方法也可以扩展为解决回归问题。 该扩展方法称为支持向量回归(SVR)。

SVM和SVR之间的基本相似之处 (Basic similarity between SVM and SVR)

The model created by SVC depends only on a subset of training data. Why? Because the cost function for building the model doesn’t care about training data points that lie outside the margin.

SVC创建的模型仅取决于训练数据的子集。 为什么? 因为构建模型的成本函数并不关心位于边距之外的训练数据点。

Whereas, the model produced by SVR (Support Vector Regression) also only depends on a subset of the training data. Why? Because the cost function for building the model ignores any training data points close to the model prediction.

而SVR(支持向量回归)产生的模型也仅取决于训练数据的子集。 为什么? 因为用于构建模型的成本函数会忽略任何接近模型预测的训练数据点。

Scikit-learn provides three classes namely SVR, NuSVR and LinearSVR as three different implementations of SVR.

Scikit-learn提供了三个类,即SVR,NuSVR和LinearSVR,作为SVR的三种不同实现。

SVR (SVR)

It is Epsilon-support vector regression whose implementation is based on libsvm. As opposite to SVC There are two free parameters in the model namely ‘C’ and ‘epsilon’.

这是Epsilon支持的向量回归,其实现基于libsvm 。 与SVC相反,模型中有两个自由参数,即'C''epsilon'

  • epsilon − float, optional, default = 0.1

    epsilon-浮动,可选,默认= 0.1

It represents the epsilon in the epsilon-SVR model, and specifies the epsilon-tube within which no penalty is associated in the training loss function with points predicted within a distance epsilon from the actual value.

它代表epsilon-SVR模型中的epsilon,并指定在epsilon-tube中训练损失函数中与从实际值算起的距离epsilon中预测的点无关的惩罚。

Rest of the parameters and attributes are similar as we used in SVC.

其余的参数和属性与我们在SVC中使用的相似。

实施实例 (Implementation Example)

Following Python script uses sklearn.svm.SVR class −

以下Python脚本使用sklearn.svm.SVR类-


from sklearn import svm
X = [[1, 1], [2, 2]]
y = [1, 2]
SVRReg = svm.SVR(kernel = ’linear’, gamma = ’auto’)
SVRReg.fit(X, y)

输出量 (Output)


SVR(C = 1.0, cache_size = 200, coef0 = 0.0, degree = 3, epsilon = 0.1, gamma = 'auto',
   kernel = 'linear', max_iter = -1, shrinking = True, tol = 0.001, verbose = False)

(Example)

Now, once fitted, we can get the weight vector with the help of following python script −

现在,一旦拟合,我们就可以在以下python脚本的帮助下获得权重向量-


SVRReg.coef_

输出量 (Output)


array([[0.4, 0.4]])

(Example)

Similarly, we can get the value of other attributes as follows −

类似地,我们可以获取其他属性的值,如下所示:


SVRReg.predict([[1,1]])

输出量 (Output)


array([1.1])

Similarly, we can get the values of other attributes as well.

同样,我们也可以获取其他属性的值。

NuSVR (NuSVR)

NuSVR is Nu Support Vector Regression. It is like NuSVC, but NuSVR uses a parameter nu to control the number of support vectors. And moreover, unlike NuSVC where nu replaced C parameter, here it replaces epsilon.

NuSVR是Nu支持向量回归。 就像NuSVC一样,但是NuSVR使用参数nu来控制支持向量的数量。 而且,与NuSVC的nu替换了C参数不同,此处它替换了epsilon

实施实例 (Implementation Example)

Following Python script uses sklearn.svm.SVR class −

以下Python脚本使用sklearn.svm.SVR类-


from sklearn.svm import NuSVR
import numpy as np
n_samples, n_features = 20, 15
np.random.seed(0)
y = np.random.randn(n_samples)
X = np.random.randn(n_samples, n_features)
NuSVRReg = NuSVR(kernel = 'linear', gamma = 'auto',C = 1.0, nu = 0.1)^M
NuSVRReg.fit(X, y)

输出量 (Output)


NuSVR(C = 1.0, cache_size = 200, coef0 = 0.0, degree = 3, gamma = 'auto',
   kernel = 'linear', max_iter = -1, nu = 0.1, shrinking = True, tol = 0.001,
   verbose = False)

(Example)

Now, once fitted, we can get the weight vector with the help of following python script −

现在,一旦拟合,我们就可以在以下python脚本的帮助下获得权重向量-


NuSVRReg.coef_

输出量 (Output)


array(
   [
      [-0.14904483, 0.04596145, 0.22605216, -0.08125403, 0.06564533,
      0.01104285, 0.04068767, 0.2918337 , -0.13473211, 0.36006765,
      -0.2185713 , -0.31836476, -0.03048429, 0.16102126, -0.29317051]
   ]
)

Similarly, we can get the value of other attributes as well.

同样,我们也可以获取其他属性的值。

线性SVR (LinearSVR)

It is Linear Support Vector Regression. It is similar to SVR having kernel = ‘linear’. The difference between them is that LinearSVR implemented in terms of liblinear, while SVC implemented in libsvm. That’s the reason LinearSVR has more flexibility in the choice of penalties and loss functions. It also scales better to large number of samples.

它是线性支持向量回归。 它类似于具有内核=“线性”的SVR。 它们之间的区别是,在LinearSVRliblinear方面实施,而SVC在LIBSVM实现。 这就是LinearSVR在罚分和损失函数选择方面更具灵活性的原因。 它还可以更好地扩展到大量样本。

If we talk about its parameters and attributes then it does not support ‘kernel’ because it is assumed to be linear and it also lacks some of the attributes like support_, support_vectors_, n_support_, fit_status_ and, dual_coef_.

如果我们谈论它的参数和属性,那么它就不支持“内核”,因为它被认为是线性的,并且还缺少一些属性,例如support_,support_vectors_,n_support_,fit_status_dual_coef_

However, it supports ‘loss’ parameters as follows −

但是,它支持以下“损失”参数-

  • loss − string, optional, default = ‘epsilon_insensitive’

    loss-字符串,可选,默认='epsilon_insensitive'

It represents the loss function where epsilon_insensitive loss is the L1 loss and the squared epsilon-insensitive loss is the L2 loss.

它表示损失函数,其中epsilon_insensitive损失是L1损失,平方的epsilon_insensitive损失是L2损失。

实施实例 (Implementation Example)

Following Python script uses sklearn.svm.LinearSVR class −

以下Python脚本使用sklearn.svm.LinearSVR类-


from sklearn.svm import LinearSVR
from sklearn.datasets import make_regression
X, y = make_regression(n_features = 4, random_state = 0)
LSVRReg = LinearSVR(dual = False, random_state = 0,
loss = 'squared_epsilon_insensitive',tol = 1e-5)
LSVRReg.fit(X, y)

输出量 (Output)


LinearSVR(
   C=1.0, dual=False, epsilon=0.0, fit_intercept=True,
   intercept_scaling=1.0, loss='squared_epsilon_insensitive',
   max_iter=1000, random_state=0, tol=1e-05, verbose=0
)

(Example)

Now, once fitted, the model can predict new values as follows −

现在,一旦拟合,模型可以预测新值,如下所示:


LSRReg.predict([[0,0,0,0]])

输出量 (Output)


array([-0.01041416])

(Example)

For the above example, we can get the weight vector with the help of following python script −

对于上面的示例,我们可以借助以下python脚本获取权重向量-


LSRReg.coef_

输出量 (Output)


array([20.47354746, 34.08619401, 67.23189022, 87.47017787])

(Example)

Similarly, we can get the value of intercept with the help of following python script −

同样,我们可以在以下python脚本的帮助下获取拦截的值-


LSRReg.intercept_

输出量 (Output)


array([-0.01041416])

翻译自: https://www.tutorialspoint.com/scikit_learn/scikit_learn_support_vector_machines.htm

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值