
    Q3j                        d dl Z d dlmZmZ d dlmZmZ d dlZd dl	m
Z d dlmZmZmZ d dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZm Z m!Z! d dl"m#Z#m$Z$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 g dZ8d Z9 G d dee      Z: G d dee:e      Z;d Z<	 	 	 	 	 ddZ=y)    N)ABCMetaabstractmethod)IntegralReal)BaseEstimatorClassifierMixin_fit_context)ConvergenceWarningNotFittedError)LabelEncoder)
_liblinear)_libsvm)_libsvm_sparse)check_arraycheck_random_statecolumn_or_1dcompute_class_weight
deprecated)HiddenInterval
StrOptions)_align_api_if_sparse)safe_sparse_dot)SCIPY_VERSION_BELOW_1_12)available_if)_ovr_decision_functioncheck_classification_targets)_check_large_sparse_check_sample_weight_num_samplescheck_consistent_lengthcheck_is_fittedvalidate_data)c_svcnu_svc	one_classepsilon_svrnu_svrc           	         | j                   d   dz   }g }t        j                  t        j                  dg|g            }t	        |      D ]  }|||   ||dz      ddf   }t	        |dz   |      D ]  }|||   ||dz      ddf   }	t
        r*| |dz
  g||   ||dz      f   }
| |g||   ||dz      f   }n'| |dz
  ||   ||dz      f   }
| |||   ||dz      f   }|j                  t        |
|      t        ||	      z            |S )zGenerate primal coefficients from dual coefficients
    for the one-vs-one multi class LibSVM in the case
    of a linear kernel.r      N)shapenpcumsumhstackranger   appendr   )	dual_coef	n_supportsupport_vectorsn_classcoefsv_locsclass1sv1class2sv2alpha1alpha2s               >/DATA/.local/lib/python3.12/site-packages/sklearn/svm/_base.py_one_vs_one_coefr>   0   sa    ooa 1$G Dii		A3	"234G.gfo
0CCQFGFQJ0F!'&/GFQJ4G"G"JKC'"FQJ<76TU:CV1V#VW"F8WV_wvPQz?R-R#RS #6A:wvRSAT/T#TU"676?WVaZ=P+P#PQ KK4vs7SST! 1 !( K    c                       e Zd ZU dZ eh d      eg eeddd      g eddh       eed	dd      g eeddd
      g eed	dd
      g eed	dd      g eed	dd      g eed	dd      gdgd e	 edh            g eeddd
      g edh      e
dgdg eeddd      gdgdZe
ed<   g dZed        Z fdZ ed      d*d       Zd Zd Zd Zd Zd Zd  Zd! Zd" Zd# Zd$ Zd% Zd& Zed'        Z d( Z!ed)        Z" xZ#S )+
BaseLibSVMzBase class for estimators that use libsvm as backing library.

    This implements support vector machine classification and regression.

    Parameter documentation is in the derived `SVC` class.
    >   rbfpolylinearsigmoidprecomputedr   Nleft)closedscaleauto        neitherright      ?booleanr   balancedverboserandom_statekerneldegreegammacoef0tolCnuepsilon	shrinkingprobability
cache_sizeclass_weightrQ   max_iterrS   _parameter_constraints)rD   rC   rB   rE   rF   c                 :   | j                   t        vr t        dt        d| j                   d      || _        || _        || _        || _        || _        || _        || _	        || _
        |	| _        |
| _        || _        || _        || _        || _        || _        y )Nzimpl should be one of z, z
 was given)_implLIBSVM_IMPL
ValueErrorrU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rQ   ra   rS   )selfrU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rQ   ra   rS   s                   r=   __init__zBaseLibSVM.__init__{   s    & ::[(<GT  

"&$( (r?   c                     t         |          }| j                  dk(  |j                  _        | j                  dk7  |j                  _        |S NrF   )super__sklearn_tags__rU   
input_tagspairwisesparserg   tags	__class__s     r=   rl   zBaseLibSVM.__sklearn_tags__   s?    w')#';;-#? !%!=r?   T)prefer_skip_nested_validationc           	      
   t        | j                        }t        j                  |      }|r| j                  dk(  rt        d      |xr t        | j                         | _        t        | j                        rt        ||       n#t        | ||t        j                  ddd      \  }}| j                  |      }t        j                  |g n|t        j                        }t        j                  | j                         }| j"                  | _        | j                   dv rL| j                   d	k(  rd
}nd}| j"                  dk7  r"t'        j(                  d| d| dt*               nd| _        t-        |      }|dk7  r4||j.                  d   k7  r"t1        dd|d|j.                  d   dz         | j                  dk(  rG||j.                  d   k7  r5t1        dj3                  |j.                  d   |j.                  d               |j.                  d   dkD  r8|j.                  d   |k7  r&t1        d|j.                  d|j.                  d      t        | j                        rdn| j                  }	|	dk(  rd| _        nt7        | j8                  t:              r| j8                  dk(  rg|r3|j=                  |      j?                         |j?                         dz  z
  n|jA                         }
|
dk7  rd|j.                  d   |
z  z  nd| _        nR| j8                  dk(  rCd|j.                  d   z  | _        n+t7        | j8                  tB              r| j8                  | _        | j                  r| jD                  n| jF                  }| jH                  rtK        dd !       |jM                  t        jN                  d"      jP                        } ||||||	|#       tS        |d$      r|j.                  n|f| _*        | jV                  jY                         | _-        | j\                  | _/        | j                   dv r?ta        | jb                        dk(  r'| xjV                  d%z  c_+        | j\                   | _.        | j                  r| j^                  jd                  n| j^                  }t        jf                  | jZ                        ji                         }t        jf                  |      ji                         }|r|st1        d&      | j                   dv r| jj                  | _6        | S | jj                  jo                         | _6        | S )'a  Fit the SVM model according to the given training data.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)                 or (n_samples, n_samples)
            Training vectors, where `n_samples` is the number of samples
            and `n_features` is the number of features.
            For kernel="precomputed", the expected shape of X is
            (n_samples, n_samples).

        y : array-like of shape (n_samples,)
            Target values (class labels in classification, real numbers in
            regression).

        sample_weight : array-like of shape (n_samples,), default=None
            Per-sample weights. Rescale C per sample. Higher weights
            force the classifier to put more emphasis on these points.

        Returns
        -------
        self : object
            Fitted estimator.

        Notes
        -----
        If X and y are not C-ordered and contiguous arrays of np.float64 and
        X is not a sparse CSR format, X and/or y may be copied.

        If X is a dense array, then the other methods will not support sparse
        matrices as input.
        rF   z-Sparse precomputed kernels are not supported.rZ   csrF)dtypeorderaccept_sparseaccept_large_sparserv   r$   r%   nu_scvNuSVCSVCr   zsThe `probability` parameter was deprecated in 1.9 and will be removed in version 1.11. Use `CalibratedClassifierCV(z!(), ensemble=False)` instead of `z(probability=True)`   r   z"X and y have incompatible shapes.
zX has z samples, but y has .r*   zDPrecomputed matrix must be a square matrix. Input is a {}x{} matrix.z.sample_weight and X have incompatible shapes: z vs zT
Note: Sparse matrices cannot be indexed w/boolean masks (use `indices=True` in CV).rK   rI   rN   rJ   z[LibSVM] endi)random_seedr+   rR   zxThe dual coefficients or intercepts are not finite. The input data may contain large values and need to be preprocessed.)8r   rS   spissparserU   	TypeErrorcallable_sparser!   r#   r,   float64_validate_targetsasarrayre   indexrd   r^   _effective_probabilitywarningswarnFutureWarningr    r+   rf   format_gamma
isinstancerW   strmultiplymeanvarr   _sparse_fit
_dense_fitrQ   printrandintiinfomaxhasattr
shape_fit_
intercept_copy_intercept_
dual_coef__dual_coef_lenclasses_dataisfiniteall	_num_itern_iter_item)rg   Xysample_weightrndro   solver_typeest_dep	n_samplesrU   X_varfitseedr1   intercept_finitenessdual_coef_finitenesss                   r=   r   zBaseLibSVM.fit   sr   D !!2!23Qdkk]2KLL;ht{{&;";DKK #Aq) jj#$)DAq ""1%

'B]"**
 "''

3 '+&6&6#::,,zzX%!</33:) <##*)+>@ " /4+ !O	!	QWWQZ 757@!''!*MN 
 ;;-'I,C,,2F1771:qwwqz,J 
 q!A%-*=*=a*@I*M
 !&&	1  #+4;;"7T[[]" DK

C(zzW$DJA,,.!&&(q@PQPUPUPW<AQJcQWWQZ%%78Cv%!AGGAJ.

D)**DK"&,,dDOO<<*"%{{288C=,,-Aq-f$G &-Q%8!''yl
  ??//1??::,,T]]1Cq1HOOr!O#.DO-1\\D$$))t?O?O	!{{4+;+;<@@B!{{9599;$)=!  ::,,>>DL   >>..0DLr?   c                 Z    t        |d      j                  t        j                  d      S )zxValidation of y and class_weight.

        Default implementation for SVR and one-class; overridden in BaseSVC.
        Tr   F)r   )r   astyper,   r   )rg   r   s     r=   r   zBaseLibSVM._validate_targetsJ  s%    
 AD)00%0HHr?   c                     | j                   dv sJ | j                   dk(  r(t        j                  d| j                  z  t               y y )Nr   r*   r*   znSolver terminated early (max_iter=%i).  Consider pre-processing your data with StandardScaler or MinMaxScaler.)fit_status_r   r   ra   r
   rg   s    r=   _warn_from_fit_statusz BaseLibSVM._warn_from_fit_statusQ  sL    6)))q MM359]]C #	 !r?   c                     t        | j                        rB|| _        | j                  |      }|j                  d   |j                  d   k7  rt        d      t        j                  | j                         t        j                  ||fi d|d|dt        | dt        j                  d            d|d	| j                  d
| j                  d| j                  d| j                   d| j"                  d| j$                  d| j&                  d| j(                  d| j*                  d| j,                  d| j.                  d|\	  | _        | _        | _        | _        | _        | _        | _        | _        | _         | jC                          y )Nr   r*   z(X.shape[0] should be equal to X.shape[1]svm_typer   r`   class_weight_rU   rZ   r[   r^   rV   r]   rY   r_   rX   rW   r\   ra   r   )"r   rU   _BaseLibSVM__Xfit_compute_kernelr+   rf   libsvmset_verbosity_wraprQ   r   getattrr,   emptyrZ   r[   r   rV   r]   rY   r_   rX   r   r\   ra   support_support_vectors_
_n_supportr   r   _probA_probBr   r   r   )rg   r   r   r   r   rU   r   s          r=   r   zBaseLibSVM._dense_fit[  s   DKK  DK$$Q'AwwqzQWWQZ' !KLL!!$,,/ JJ
 !
 (	

 !D
 
 ff
 ww
 33
 ;;
 nn
 
 
 **
 ++
  LL!
" ]]#
$ $%

	
M!OOOKKN, 	""$r?   c                 >   t        j                  |j                  t         j                  d      |_        |j	                          | j
                  j                  |      }t        j                  | j                         t        j                  |j                  d   |j                  |j                  |j                  |||| j                  | j                  | j                   | j"                  | j$                  t'        | dt        j(                  d            || j*                  | j,                  | j.                  t1        | j2                        t1        | j4                        | j6                  |      \	  | _        | _        }| _        | _        | _         | _!        | _"        | _#        | jI                          tK        | d      rtM        | jN                        dz
  }	nd}	| j:                  j                  d   }
t        jP                  t        jR                  |
      |	      }|
s%tU        tW        jX                  g g            | _-        y t        jR                  d|j\                  dz   |j\                  |	z        }tU        tW        jX                  |||f|	|
f            | _-        y )NrZ   rv   rw   r*   r   r   r   )/r,   r   r   r   sort_indices_sparse_kernelsr   libsvm_sparser   rQ   libsvm_sparse_trainr+   indicesindptrrV   r   rX   rY   rZ   r   r   r[   r_   r\   intr]   r   ra   r   r   r   r   r   r   r   r   r   r   r   r   tilearanger   r   	csr_arrayr   size)rg   r   r   r   r   rU   r   kernel_typedual_coef_datar4   n_SVdual_coef_indicesdual_coef_indptrs                r=   r   zBaseLibSVM._sparse_fit  s   AFF"**C@	**008((6 --GGAJFFIIHHKKKKJJHHFFD/288A;7GGOOLL++,MM+

	
M!OOKKN2 	""$4$$--(1,GG$$**1-GGBIIdOW=22<<3EFDO!yy$))A-/@/E/E/O  3#%68HIdODOr?   c                 |    | j                  |      }| j                  r| j                  n| j                  } ||      S )a  Perform regression on samples in X.

        For a one-class model, +1 (inlier) or -1 (outlier) is returned.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            For kernel="precomputed", the expected shape of X is
            (n_samples_test, n_samples_train).

        Returns
        -------
        y_pred : ndarray of shape (n_samples,)
            The predicted values.
        )_validate_for_predictr   _sparse_predict_dense_predict)rg   r   predicts      r=   r   zBaseLibSVM.predict  s7      &&q)*.,,$&&D<O<Oqzr?   c                    | j                  |      }|j                  dk(  rt        |dd      }| j                  }t	        | j                        rKd}|j
                  d   | j                  d   k7  r*t        d|j
                  d   | j                  d   fz        t        j                  | j                        }t        j                  || j                  | j                  | j                  | j                   | j"                  | j$                  | j&                  ||| j(                  | j*                  | j,                  | j.                        S )	Nr*   rZ   F)rw   ry   rF   r   MX.shape[1] = %d should be equal to %d, the number of samples at training time)r   rU   rV   rX   rW   r_   )r   ndimr   rU   r   r+   r   rf   re   r   rd   r   r   r   r   r   r   r   r   r   rV   rX   r   r_   )rg   r   rU   r   s       r=   r   zBaseLibSVM._dense_predict  s     #66Q;ASeDADKK "FwwqzT__Q// =wwqz4??1#567  $$TZZ0~~MM!!OOKKKK;;**++
 	
r?   c                    | j                   }t        |      rd}| j                  j                  |      }d}t	        j
                  |j                  |j                  |j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  t        j                  | j                        || j                  | j                  | j                   | j"                  |t%        | dt'        j(                  d            | j*                  | j,                  | j.                  | j0                  | j2                  | j4                  | j6                        S )NrF   rK   r   r   )rU   r   r   r   r   libsvm_sparse_predictr   r   r   r   r   r   re   rd   rV   r   rX   rY   r   r,   r   r[   r\   r]   r   r   r   r   )rg   r   rU   r   rZ   s        r=   r   zBaseLibSVM._sparse_predict   s   F"F**00822FFIIHH!!&&!!))!!((!!djj)KKKKJJHHD/288A;7GGLLNN''OOKKKK/
 	
r?   c                     t        | j                        rg| j                  || j                        }t        j                  |      r|j                         }t        j                  |t        j                  d      }|S )z0Return the data transformed by a callable kernelrZ   r   )	r   rU   r   r   r   toarrayr,   r   r   rg   r   rU   s      r=   r   zBaseLibSVM._compute_kernel$  sW    DKK  [[DKK0F{{6")

63?Ar?   c                    | j                  |      }| j                  |      }| j                  r| j                  |      }n| j	                  |      }| j
                  dv r)t        | j                        dk(  r|j                          S |S )af  Evaluates the decision function for the samples in X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)

        Returns
        -------
        X : array-like of shape (n_samples, n_class * (n_class-1) / 2)
            Returns the decision function of the sample for each class
            in the model.
        r{   r   )	r   r   r   _sparse_decision_function_dense_decision_functionrd   r   r   ravel)rg   r   dec_funcs      r=   _decision_functionzBaseLibSVM._decision_function/  s     &&q)  #<<55a8H44Q7H ::,,T]]1Cq1HNN$$$r?   c                    t        |t        j                  dd      }| j                  }t	        |      rd}t        j                  || j                  | j                  | j                  | j                  | j                  | j                  | j                  t        j                  | j                         || j"                  | j$                  | j&                  | j(                        S )NrZ   F)rv   rw   ry   rF   r   rU   rV   r_   rX   rW   )r   r,   r   rU   r   r   decision_functionr   r   r   r   r   r   r   re   r   rd   rV   r_   rX   r   r   s      r=   r   z#BaseLibSVM._dense_decision_functionM  s    3ERF"F''MM!!OOKKKK &&tzz2;;**++
 	
r?   c                    t        j                  |j                  t         j                  d      |_        | j                  }t        |d      rd}| j                  j                  |      }t        j                  |j                  |j                  |j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  t        j                  | j                         || j"                  | j$                  | j&                  | j(                  | j*                  t-        | dt        j.                  d            | j0                  | j2                  | j4                  | j6                  | j8                  | j:                  | j<                        S )NrZ   r   __call__rF   r   r   )r,   r   r   r   rU   r   r   r   r   libsvm_sparse_decision_functionr   r   r   r   r   re   rd   rV   r   rX   rY   rZ   r   r   r[   r\   r]   r   r   r   r   rg   r   rU   r   s       r=   r   z$BaseLibSVM._sparse_decision_functione  s8   AFF"**C@6:&"F**008<<FFIIHH!!&&!!))!!((!!djj)KKKKJJHHFFD/288A;7GGLLNN''OOKKKK/
 	
r?   c           	      j   t        |        t        | j                        s t        | |dt        j
                  ddd      }| j                  rCt        j                  |      st        t        j                  |            }|j                          t        j                  |      rB| j                  s6t        | j                        s!t        dt        |       j                  z        | j                  dk(  rI|j                  d   | j                   d   k7  r*t        d	|j                  d   | j                   d   fz        | j"                  }| j                  s\|j$                  dkD  rM| j&                  j)                         |j                  d   k7  r#t        d
| j*                  j                   d      |S )Nru   rZ   F)rx   rv   rw   ry   resetz3cannot use sparse input in %r trained on dense datarF   r*   r   r   zThe internal representation of z was altered)r"   r   rU   r#   r,   r   r   r   r   r   r   r   rf   type__name__r+   r   r   r   
n_support_sumrr   )rg   r   svs      r=   r   z BaseLibSVM._validate_for_predict  sd   $#jj$)A <<;;q>(a9NN;;q>$,,x7LEt*%%& 
 ;;-'wwqzT__Q// =wwqz4??1#567  ""||!0C0C0ERS0T1$..2I2I1J,W  r?   c                     | j                   dk7  rt        d      | j                         }t        j                  |      rd|j
                  j                  _        |S d|j                  _        |S )zWeights assigned to the features when `kernel="linear"`.

        Returns
        -------
        ndarray of shape (n_features, n_classes)
        rD   z2coef_ is only available when using a linear kernelF)rU   AttributeError	_get_coefr   r   r   flags	writeablerg   r5   s     r=   coef_zBaseLibSVM.coef_  s`     ;;(" !UVV~~ ;;t(-DIIOO%  $)DJJ r?   c                 B    t        | j                  | j                        S N)r   r   r   r   s    r=   r  zBaseLibSVM._get_coef  s    t//1F1FGGr?   c                     	 t        |        t        j	                  | j
                        }|dv r| j                  S t        j                  | j                  d   g      S # t        $ r t        w xY w)z)Number of support vectors for each class.r   r   )	r"   r   r  re   r   rd   r   r,   array)rg   r   s     r=   r  zBaseLibSVM.n_support_  sk    	!D! $$TZZ0v??" 88T__Q/011  	!  	!s   A A/r  )$r   
__module____qualname____doc__r   r   r   r   r   r   dictrb   __annotations__r   r   rh   rl   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr
  r  r  __classcell__rr   s   @r=   rA   rA   V   s    JK
 Haf=>()T3V4
 4tI>?sD;<tS$w78c3w78T3V<=[!6*l^*D#EFai@A#ZL14>;hD@A'(+$D 6 JO%) %)N 5] 6]~I-%^>@( 
D"
H	<
0!
F'R  ,H 2 2r?   rA   )	metaclassc                   ^    e Zd ZU dZi ej
                   eddh      gdgdZeed<   dD ]  Z	ej                  e	        e fd       Zd	 Zd
 Z fdZd Z ee      d        Z ee      d        Zd Zd Zd Z ed      ed               Z ed      ed               Z fdZ xZS )BaseSVCz!ABC for LibSVM-based classifiers.ovrovorO   )decision_function_shape
break_tiesrb   )r\   r[   c                 ^    || _         || _        t        |   |||||||d||	|
||||       y )NrK   rT   )r  r  rk   rh   )rg   rU   rV   rW   rX   rY   rZ   r[   r]   r^   r_   r`   rQ   ra   r  rS   r  rr   s                    r=   rh   zBaseSVC.__init__  sS    ( (?$$#!%% 	 	
r?   c                 D   t        |d      }t        |       t        j                  |d      \  }}t	        | j
                  ||      | _        t        |      dk  rt        dt        |      z        || _	        t        j                  |t        j                  d      S )	NTr   )return_inverse)classesr   r   z>The number of classes has to be greater than one; got %d classrZ   r   )r   r   r,   uniquer   r`   r   r   rf   r   r   r   )rg   r   y_clss       r=   r   zBaseSVC._validate_targets  s    !$'$Q'2d3Q1$2C2CSTVWs8a<Pc( 
 zz!2::S99r?   c                     | j                  |      }| j                  dk(  r<t        | j                        dkD  r$t	        |dk  | t        | j                              S |S )a4  Evaluate the decision function for the samples in X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input samples.

        Returns
        -------
        X : ndarray of shape (n_samples, n_classes * (n_classes-1) / 2)
            Returns the decision function of the sample for each class
            in the model.
            If decision_function_shape='ovr', the shape is (n_samples,
            n_classes).

        Notes
        -----
        If decision_function_shape='ovo', the function values are proportional
        to the distance of the samples X to the separating hyperplane. If the
        exact distances are required, divide the function values by the norm of
        the weight vector (``coef_``). See also `this question
        <https://stats.stackexchange.com/questions/14876/
        interpreting-distance-from-hyperplane-in-svm>`_ for further details.
        If decision_function_shape='ovr', the decision function is a monotonic
        transformation of ovo decision function.
        r  r   r   )r   r  r   r   r   )rg   r   decs      r=   r   zBaseSVC.decision_function  sU    6 %%a(''50S5G!5K)#'C4T]]9KLL
r?   c                    t        |        | j                  r| j                  dk(  rt        d      | j                  rN| j                  dk(  r?t	        | j
                        dkD  r't        j                  | j                  |      d      }nt        | )  |      }| j
                  j                  t        j                  |t        j                              S )a  Perform classification on samples in X.

        For a one-class model, +1 or -1 is returned.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features) or                 (n_samples_test, n_samples_train)
            For kernel="precomputed", the expected shape of X is
            (n_samples_test, n_samples_train).

        Returns
        -------
        y_pred : ndarray of shape (n_samples,)
            Class labels for samples in X.
        r  z>break_ties must be False when decision_function_shape is 'ovo'r  r   r*   )axisrz   )r"   r  r  rf   r   r   r,   argmaxr   rk   r   taker   intp)rg   r   r   rr   s      r=   r   zBaseSVC.predict>  s    " 	??t;;uDP 
 OO,,5DMM"Q&		$003!<A"A}}!!"**Qbgg">??r?   c                     | j                   dk(  s| j                   st        d      | j                  dvrt        d      y)Nr   z5predict_proba is not available when probability=Falser{   z0predict_proba only implemented for SVC and NuSVCT)r^   r  rd   r   s    r=   _check_probazBaseSVC._check_probac  sF    |+43C3C G  ::00 !STTr?   c                     | j                  |      }| j                  j                  dk(  s| j                  j                  dk(  rt	        d      | j
                  r| j                  n| j                  } ||      S )a  Compute probabilities of possible outcomes for samples in X.

        The model needs to have probability information computed at training
        time: fit with attribute `probability` set to True.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            For kernel="precomputed", the expected shape of X is
            (n_samples_test, n_samples_train).

        Returns
        -------
        T : ndarray of shape (n_samples, n_classes)
            Returns the probability of the sample for each class in
            the model. The columns correspond to the classes in sorted
            order, as they appear in the attribute :term:`classes_`.

        Notes
        -----
        The probability model is created using cross validation, so
        the results can be slightly different than those obtained by
        predict. Also, it will produce meaningless results on very small
        datasets.
        r   zApredict_proba is not available when fitted with probability=False)r   r   r   r   r   r   _sparse_predict_proba_dense_predict_proba)rg   r   
pred_probas      r=   predict_probazBaseSVC.predict_probal  sq    6 &&q);;q DKK$4$4$9 S  +/,,D&&D<U<U 	 !}r?   c                 J    t        j                  | j                  |            S )a  Compute log probabilities of possible outcomes for samples in X.

        The model need to have probability information computed at training
        time: fit with attribute `probability` set to True.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or                 (n_samples_test, n_samples_train)
            For kernel="precomputed", the expected shape of X is
            (n_samples_test, n_samples_train).

        Returns
        -------
        T : ndarray of shape (n_samples, n_classes)
            Returns the log-probabilities of the sample for each class in
            the model. The columns correspond to the classes in sorted
            order, as they appear in the attribute :term:`classes_`.

        Notes
        -----
        The probability model is created using cross validation, so
        the results can be slightly different than those obtained by
        predict. Also, it will produce meaningless results on very small
        datasets.
        )r,   logr2  )rg   r   s     r=   predict_log_probazBaseSVC.predict_log_proba  s    8 vvd((+,,r?   c                    | j                  |      }| j                  }t        |      rd}t        j	                  | j
                        }t        j                  || j                  | j                  | j                  | j                  | j                  | j                  | j                  ||| j                  | j                   | j"                  | j$                        }|S )NrF   r   )r   rU   r   re   r   rd   r   r2  r   r   r   r   r   r   r   rV   r_   rX   r   )rg   r   rU   r   pprobs        r=   r0  zBaseSVC._dense_predict_proba  s      #F"F$$TZZ0$$MM!!OOKKKK;;**++
" r?   c                    t        j                  |j                  t         j                  d      |_        | j                  }t        |      rd}| j                  j                  |      }t        j                  |j                  |j                  |j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  t        j                  | j                         || j"                  | j$                  | j&                  | j(                  | j*                  t-        | dt        j.                  d            | j0                  | j2                  | j4                  | j6                  | j8                  | j:                  | j<                        S )NrZ   r   rF   r   r   )r,   r   r   r   rU   r   r   r   r   libsvm_sparse_predict_probar   r   r   r   r   re   rd   rV   r   rX   rY   rZ   r   r   r[   r\   r]   r   r   r   r   r   s       r=   r/  zBaseSVC._sparse_predict_proba  s6   AFF"**C@F"F**00888FFIIHH!!&&!!))!!((!!djj)KKKKJJHHFFD/288A;7GGLLNN''OOKKKK/
 	
r?   c                 |   | j                   j                  d   dk(  r"t        | j                   | j                        }|S t	        | j                   | j
                  | j                        }t        j                  |d         r%t        j                  |      j                         }|S t        j                  |      }|S )Nr   r*   )r   r+   r   r   r>   r   r   r   vstacktocsrr,   r	  s     r=   r  zBaseSVC._get_coef  s    ??  #q("4??D4I4IJD  $$2G2GD {{47#yy,,.  yyr?   zAttribute `probA_` was deprecated in version 1.9 and will be removed in 1.11 as the `probability=True` option for SVC and NuSVC was deprecated and will be removed in 1.11.c                     | j                   S zParameter learned in Platt scaling when `probability=True`.

        Returns
        -------
        ndarray of shape  (n_classes * (n_classes - 1) / 2)
        )r   r   s    r=   probA_zBaseSVC.probA_       {{r?   zAttribute `probB_` was deprecated in version 1.9 and will be removed in 1.11 as the `probability=True` option for SVC and NuSVC was deprecated and will be removed in 1.11.c                     | j                   S r>  )r   r   s    r=   probB_zBaseSVC.probB_  r@  r?   c                 `    t         |          }| j                  dk7  |j                  _        |S rj   )rk   rl   rU   rm   ro   rp   s     r=   rl   zBaseSVC.__sklearn_tags__  s*    w')!%!=r?   )r   r  r  r  rA   rb   r   r  r  unused_parampopr   rh   r   r   r   r-  r   r2  r5  r0  r/  r  r   r  r?  rB  rl   r  r  s   @r=   r  r    s   +$

+
+$$.u~$>#? k$D 
 *""<0 * %
 %
N:@@J ,"  "H ,-  -:6!
F  	'
   	'
   r?   r  c           
      j   ddiddddddd	iidd
idddddddiiddddidd}| dk(  r||    S | dk7  rt        d| z        |j                  |d      }|d|z  }n@|j                  |d      }|
d|d|d}n"|j                  |d      }|d|d|d|}n|S t        d|d|d|d|      )a  Find the liblinear magic number for the solver.

    This number depends on the values of the following attributes:
      - multi_class
      - penalty
      - loss
      - dual

    The same number is also internally used by LibLinear to determine
    which solver to use.
    F   r      )FT)l1l2rJ  T      r   r*               )logistic_regressionhingesquared_hingeepsilon_insensitivesquared_epsilon_insensitivecrammer_singerrV  r  z<`multi_class` must be one of `ovr`, `crammer_singer`, got %rNzloss='%s' is not supportedzThe combination of penalty='z' and loss='z' is not supportedz' are not supported when dual=zUnsupported set of arguments: z, Parameters: penalty=z, loss=z, dual=)rf   get)	multi_classpenaltylossdual_solver_type_dict_solver_penerror_string_solver_dual
solver_nums	            r=   _get_liblinear_solver_typera  !  s(   " (-aj8KLq	"!&
!12EF $tRj1(,b.C'D && --		J[X
 	
 $''d3K3d:"w5 D" 
 &))$5J! CJ4QUW 
 "!
$	. r?   c                    |dvrVt               }|j                  |      }|j                  }t        |      dk  rt	        d|d   z        t        ||||      }n't        j                  dt        j                        }|}t        j                  |       t        |      }|rt        dd	       d
}|r|dk  rt	        d|z        |}t        j                  |       t        j                  |       t        j                  |       t        j                   |       rt#        |        t        j$                  |t        j                        j'                         }t        j(                  |d      }t+        || t        j                        }t-        ||||      }t        j.                  | |t        j                   |       ||
||||	|j1                  t        j2                  d      j4                        ||      \  }}t5        |      }||	k\  rt7        j8                  dt:               |r|ddddf   }||dddf   z  }n|}d}|||fS )a  Used by Logistic Regression (and CV) and LinearSVC/LinearSVR.

    Preprocessing is done in this function before supplying it to liblinear.

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Training vector, where `n_samples` is the number of samples and
        `n_features` is the number of features.

    y : array-like of shape (n_samples,)
        Target vector relative to X

    C : float
        Inverse of cross-validation parameter. The lower the C, the higher
        the penalization.

    fit_intercept : bool
        Whether or not to fit an intercept. If set to True, the feature vector
        is extended to include an intercept term: ``[x_1, ..., x_n, 1]``, where
        1 corresponds to the intercept. If set to False, no intercept will be
        used in calculations (i.e. data is expected to be already centered).

    intercept_scaling : float
        Liblinear internally penalizes the intercept, treating it like any
        other term in the feature vector. To reduce the impact of the
        regularization on the intercept, the `intercept_scaling` parameter can
        be set to a value greater than 1; the higher the value of
        `intercept_scaling`, the lower the impact of regularization on it.
        Then, the weights become `[w_x_1, ..., w_x_n,
        w_intercept*intercept_scaling]`, where `w_x_1, ..., w_x_n` represent
        the feature weights and the intercept weight is scaled by
        `intercept_scaling`. This scaling allows the intercept term to have a
        different regularization behavior compared to the other features.

    class_weight : dict or 'balanced', default=None
        Weights associated with classes in the form ``{class_label: weight}``.
        If not given, all classes are supposed to have weight one. For
        multi-output problems, a list of dicts can be provided in the same
        order as the columns of y.

        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))``

    penalty : {'l1', 'l2'}
        The norm of the penalty used in regularization.

    dual : bool
        Dual or primal formulation,

    verbose : int
        Set verbose to any positive number for verbosity.

    max_iter : int
        Number of iterations.

    tol : float
        Stopping condition.

    random_state : int, RandomState instance or None, default=None
        Controls the pseudo random number generation for shuffling the data.
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    multi_class : {'ovr', 'crammer_singer'}, default='ovr'
        `ovr` trains n_classes one-vs-rest classifiers, while `crammer_singer`
        optimizes a joint objective over all classes.
        While `crammer_singer` is interesting from a theoretical perspective
        as it is consistent it is seldom used in practice and rarely leads to
        better accuracy and is more expensive to compute.
        If `crammer_singer` is chosen, the options loss, penalty and dual will
        be ignored.

    loss : {'logistic_regression', 'hinge', 'squared_hinge',             'epsilon_insensitive', 'squared_epsilon_insensitive},             default='logistic_regression'
        The loss function used to fit the model.

    epsilon : float, default=0.1
        Epsilon parameter in the epsilon-insensitive loss function. Note
        that the value of this parameter depends on the scale of the target
        variable y. If unsure, set epsilon=0.

    sample_weight : array-like of shape (n_samples,), default=None
        Weights assigned to each sample.

    Returns
    -------
    coef_ : ndarray of shape (n_features, n_features + 1)
        The coefficient vector got by minimizing the objective function.

    intercept_ : float
        The intercept term added to the vector.

    n_iter_ : array of int
        Number of iterations run across for each class.
    )rT  rU  r   zeThis solver needs samples of at least 2 classes in the data, but the data contains only one class: %rr   )r!  r   r   rz   z[LibLinear]r   r   g      zqIntercept scaling is %r but needs to be greater than 0. To disable fitting an intercept, set fit_intercept=False.W)requirementsr   z@Liblinear failed to converge, increase the number of iterations.NrR   rK   )r   fit_transformr   r   rf   r   r,   r   r   	liblinearr   r   r   r   r   r   r   r   r   r   requirer   ra  
train_wrapr   r   r   r   r   r
   )r   r   rZ   fit_interceptintercept_scalingr`   rY  r[  rQ   ra   rY   rS   rX  rZ  r\   r   ency_indr   r   r   biasr   	raw_coef_r   
n_iter_maxr
  r   s                               r=   _fit_liblinearrp  Z  s/   h IIn!!!$<<x=1'{+ 
 -(a}
 "**5  )
\
*Cm$ D!,.?@  %D
g&$$W-  ) 
{{1~A JJuBJJ/557EJJu3/E(LM,['4NK"--	
A	BHHSM%%&Iw$ WJXN	

 !SbS&!&1b5)99

*g%%r?   )Nr  rQ  g?N)>r   abcr   r   numbersr   r   numpyr,   scipy.sparsero   r   sklearn.baser   r   r	   sklearn.exceptionsr
   r   sklearn.preprocessingr   sklearn.svmr   rf  r   r   r   r   sklearn.utilsr   r   r   r   r   sklearn.utils._param_validationr   r   r   sklearn.utils._sparser   sklearn.utils.extmathr   sklearn.utils.fixesr   sklearn.utils.metaestimatorsr   sklearn.utils.multiclassr   r   sklearn.utils.validationr   r   r    r!   r"   r#   re   r>   rA   r  ra  rp   r?   r=   <module>r     s     ' "   E E A . / * 7  I H 6 1 8 5  H#LC
2' C
2LBozW BJ
6J 	!D&r?   