sklearnのsvm.SVC

15696 ワード

svmはsklearnのベクトルマシンをサポートするパッケージで、比較的よく使われていますが、使用中に各パラメータの意味を熟知せず、常にデフォルトパラメータでマシン学習を行うと、SVMの最適化ができないのは残念なことです.理解を深め、呼び出しを容易にするために、既存の理解に基づいて、公式ドキュメントと結びつけて、その中のパラメータをいくつか記録して、自分でよく勉強しやすくして、読者にいくつかの粗浅な紹介をして、もし理解の間違いがあるならば、読者に指摘してもらいたいです.
svmのサポートベクトル分類SVCについて説明します.すべてのパラメータは以下の通りです.
class sklearn.svm.SVC(
            C=1.0, 
            kernel='rbf', 
            degree=3, 
            gamma='auto', 
            coef0=0.0, 
            shrinking=True, 
            probability=False, 
            tol=0.001, 
            cache_size=200, 
            class_weight=None, 
            verbose=False, 
            max_iter=-1, 
            decision_function_shape='ovr', 
            random_state=None)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
各パラメータの使用方法については、次のように説明します.
C : float, optional (default=1.0)

            ,     10 n  , 10 -510 -4  。。。。10 0101000,1000python     pow10,n) n=-5~inf
    C  ,         ,        0,          ,             ,                ,      。
    C  ,         ,      ,      。

1
2
3
4
5
6
kernel : string, optional (default=’rbf’)

    svc    kernel  。
       : ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’       。     ‘rbf’ 。

1
2
3
4
5
degree : int, optional (default=3)

       kernel  ‘poly’ ,             ,        。
       kernel  ‘poly’,   ,      ‘poly’   。

1
2
3
4
gamma : float, optional (default=’auto’)

     kernel ‘rbf’, ‘poly’ ‘sigmoid’  kernel  。
         ,    ‘auto’ ,  ,kernel     :1/n_features

1
2
3
4
5
coef0 : float, optional (default=0.0)

    kernel      。
        kernel ‘poly’ ‘sigmoid’   ,   0

1
2
3
4
5
probability : boolean, optional (default=False)
            。
       fit()     ,             ,   False

1
2
3
shrinking : boolean, optional (default=True)

                    ,              ,         ,        ,                 。   ,             ( a=C),          ,          ,          ,        。   Shrinking  。

    Shrinking          :              ,                  C。

1
2
3
4
5
6
tol : float, optional (default=1e-3)

                  ,   1e-30.001

1
2
3
4
cache_size : float, optional

             ,   200M。

1
2
3
4
class_weight : {dict, ‘balanced’}, optional

        。     ,           。
           。
    ##(            )##
    Set the parameter C of class i to class_weight[i]*C for SVC. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y))

1
2
3
4
5
6
7
verbose : bool, default: False

            。
                    。   False

1
2
3
4
max_iter : int, optional (default=-1)

              。
         -1,         。
    Hard limit on iterations within solver, or -1 for no limit.

1
2
3
4
5
6
decision_function_shape : ‘ovo’, ‘ovr’, default=’ovr’

    ##          ##
    Whether to return a one-vs-rest (‘ovr’) decision function of shape (n_samples, n_classes) as all other classifiers, or the original one-vs-one (‘ovo’) decision function of libsvm which has shape (n_samples, n_classes * (n_classes - 1) / 2).

    Changed in version 0.19: decision_function_shape is ‘ovr’ by default.

    New in version 0.17: decision_function_shape=’ovr’ is recommended.

    Changed in version 0.17: Deprecated decision_function_shape=’ovo’ and None.

1
2
3
4
5
6
7
8
9
10
11
random_state : int, RandomState instance or None, optional (default=None)

1
2
3
いくつかのプロパティの説明:
Attributes: 

support_ : array-like, shape = [n_SV]

    Indices of support vectors.

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

    Support vectors.

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

    Number of support vectors for each class.

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

    Coefficients of the support vector in the decision function. For multiclass, coefficient for all 1-vs-1 classifiers. The layout of the coefficients in the multiclass case is somewhat non-trivial. See the section about multi-class classification in the SVM section of the User Guide for details.

coef_ : array, shape = [n_class-1, n_features]

    Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.

    coef_ is a readonly property derived from dual_coef_ and support_vectors_.

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

    Constants in decision function.