
\c           @  s  d  d l  m Z d  d l Z d  d l j Z d  d l Z d  d l m	 Z	 m
 Z
 d d l m Z m Z d d l m Z d d l m Z m Z d d	 l m 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  m! Z! d d l m" Z" d d l# m$ Z$ d d l% m& Z& d d l% m' Z' d d d d d g Z( d   Z) d e$ j* e	 e  f d     YZ+ d e$ j* e	 e+ e  f d     YZ, d   Z- e. d d  d! e. d"  Z/ d S(#   i(   t   print_functionN(   t   ABCMetat   abstractmethodi   (   t   libsvmt	   liblinear(   t   libsvm_sparsei   (   t   BaseEstimatort   ClassifierMixin(   t   LabelEncoder(   t   _ovr_decision_function(   t   check_arrayt   check_consistent_lengtht   check_random_state(   t   column_or_1dt	   check_X_y(   t   compute_class_weight(   t   safe_sparse_dot(   t   check_is_fittedt   _check_large_sparse(   t   check_classification_targets(   t   six(   t   ConvergenceWarning(   t   NotFittedErrort   c_svct   nu_svct	   one_classt   epsilon_svrt   nu_svrc         C  s,  |  j  d d } g  } t j t j d g | g   } x t |  D] } | | | | | d  d d  f } x t | d |  D] } | | | | | d  d d  f }	 |  | d | | | | d  f }
 |  | | | | | d  f } | j t |
 |  t | |	   q WqE W| S(   s   Generate primal coefficients from dual coefficients
    for the one-vs-one multi class LibSVM in the case
    of a linear kernel.i    i   N(   t   shapet   npt   cumsumt   hstackt   ranget   appendR   (   t	   dual_coeft	   n_supportt   support_vectorst   n_classt   coeft   sv_locst   class1t   sv1t   class2t   sv2t   alpha1t   alpha2(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   _one_vs_one_coef   s    	!((&"t
   BaseLibSVMc           B  s   e  Z d  Z d d d d d g Z e d    Z e d    Z 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 RS(   s   Base 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.
    t   lineart   polyt   rbft   sigmoidt   precomputedc         C  s   |  j  t k r+ t d t |  j  f   n  | d k rL d } t |   n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |	 |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   Ns&   impl should be one of %s, %s was giveni    sX   The gamma value of 0.0 is invalid. Use 'auto' to set gamma to a value of 1 / n_features.(   t   _implt   LIBSVM_IMPLt
   ValueErrort   kernelt   degreet   gammat   coef0t   tolt   Ct   nut   epsilont	   shrinkingt   probabilityt
   cache_sizet   class_weightt   verboset   max_itert   random_state(   t   selfR8   R9   R:   R;   R<   R=   R>   R?   R@   RA   RB   RC   RD   RE   RF   t   msg(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   __init__I   s*    														c         C  s   |  j  d k S(   NR4   (   R8   (   RG   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt	   _pairwiseg   s    c         C  s  t  |  j  } t j |  } | rB |  j d k rB t d   n  | oU t |  j  |  _ t | | d t	 j
 d d d d d t \ } } |  j |  } t	 j | d k r g  n | d t	 j
 } t j |  j  } | d	 k r'| j d
 | j d
 k r't d d | j d
 | j d
 f   n  |  j d k r_| j d
 | j d k r_t d   n  | j d
 d
 k r| j d
 | j d
 k rt d | j | j f   n  |  j d k r| r| j |  j   | j   d	 } n | j   } |  j d k r4| d
 k r(d | j d | |  _ qd |  _ qt |  j  oP|  j d  k } | rt	 j | d  rt j d t  n  d | j d |  _ n2 |  j d k rd | j d |  _ n |  j |  _ |  j }	 t |	  rd }	 n  |  j r|  j n |  j }
 |  j rt  d d d n  | j! t	 j" d  j#  } |
 | | | | |	 d | | j |  _$ |  j% j&   |  _' |  j( |  _) |  j d! k rt* |  j+  d	 k r|  j% d 9_% |  j( |  _( n  |  S("   s5  Fit the SVM model according to the given training data.

        Parameters
        ----------
        X : {array-like, sparse matrix}, shape (n_samples, n_features)
            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, shape (n_samples,)
            Target values (class labels in classification, real numbers in
            regression)

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

        Returns
        -------
        self : object

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

        If X is a dense array, then the other methods will not support sparse
        matrices as input.
        R4   s-   Sparse precomputed kernels are not supported.t   dtypet   orderR=   t   accept_sparset   csrt   accept_large_sparsei   i    s"   X and y have incompatible shapes.
s   X has %s samples, but y has %s.i   s(   X.shape[0] should be equal to X.shape[1]s   sample_weight and X have incompatible shapes: %r vs %r
Note: Sparse matrices cannot be indexed w/boolean masks (use `indices=True` in CV).t   scalet   auto_deprecatedg      ?R0   s   The default value of gamma will change from 'auto' to 'scale' in version 0.22 to account better for unscaled features. Set gamma explicitly to 'auto' or 'scale' to avoid this warning.t   autos   [LibSVM]t   endt    t   it   random_seedR   R   iN(   RP   RQ   (   R0   R4   (   R   R   (,   R   RF   t   spt
   isspmatrixR8   t	   TypeErrort   callablet   _sparseR   R   t   float64t   Falset   _validate_targetst   asarrayt   NoneR6   t   indexR5   R   R7   R:   t   multiplyt   meant   vart   _gammat   iscloset   warningst   warnt   FutureWarningt   _sparse_fitt
   _dense_fitRD   t   printt   randintt   iinfot   maxt
   shape_fit_t
   intercept_t   copyt   _intercept_t
   dual_coef_t   _dual_coef_t   lent   classes_(   RG   t   Xt   yt   sample_weightt   rndt   sparset   solver_typet   X_vart   kernel_uses_gammaR8   t   fitt   seed(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR   l   sl     &")-&		
			$c         C  s.   t  j d  |  _ t | d t j t  j  S(   sx   Validation of y and class_weight.

        Default implementation for SVR and one-class; overridden in BaseSVC.
        i    Rh   (   R   t   emptyt   class_weight_R   t   Truet   astypeR\   (   RG   Ry   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR^      s    c         C  sB   |  j  d k s t  |  j  d k r> t j d |  j t  n  d  S(   Ni    i   sn   Solver terminated early (max_iter=%i).  Consider pre-processing your data with StandardScaler or MinMaxScaler.(   i    i   (   t   fit_status_t   AssertionErrorRg   Rh   RE   R   (   RG   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   _warn_from_fit_status   s    	c      #   C  s7  t  |  j  rS | |  _ |  j |  } | j d | j d k rS t d   qS n  t j |  j  t j	 | | d | d | d |  j
 d | d |  j d	 |  j d
 |  j d |  j d |  j d |  j d |  j d |  j d |  j d |  j d |  j d | \ |  _ |  _ |  _ |  _ |  _ |  _ |  _ |  _ |  j   d  S(   Ni    i   s(   X.shape[0] should be equal to X.shape[1]t   svm_typeRz   RC   R8   R=   R>   RA   R9   R@   R<   RB   R;   R:   R?   RE   RV   (   RZ   R8   t   _BaseLibSVM__Xfitt   _compute_kernelR   R7   R   t   set_verbosity_wrapRD   R   R   R=   R>   RA   R9   R@   R<   RB   R;   Re   R?   RE   t   support_t   support_vectors_t
   n_support_Rt   Rq   t   probA_t   probB_R   R   (   RG   Rx   Ry   Rz   R}   R8   RV   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyRk      s     		Bc         C  s  t  j | j d t  j d d | _ | j   |  j j |  } t j |  j	  t j
 | j d | j | j | j | | | |  j |  j |  j |  j |  j |  j | |  j |  j |  j t |  j  t |  j  |  j |  \ |  _ |  _ } |  _ |  _ |  _ |  _  |  _! |  j"   t# |  d  r7t$ |  j%  d }	 n d }	 |  j j d }
 t  j& t  j' |
  |	  } t  j' d | j( d | j( |	  } t) j* | | | f |	 |
 f  |  _+ d  S(   NRK   RL   R=   i   Rw   i    (,   R   R_   t   dataR\   t   sort_indicest   _sparse_kernelsRa   R   R   RD   t   libsvm_sparse_trainR   t   indicest   indptrR9   Re   R;   R<   R=   R   R>   RB   R?   t   intR@   RA   RE   R   R   Rq   R   R   R   R   R   t   hasattrRv   Rw   t   tilet   aranget   sizeRW   t
   csr_matrixRt   (   RG   Rx   Ry   Rz   R}   R8   RV   t   kernel_typet   dual_coef_dataR%   t   n_SVt   dual_coef_indicest   dual_coef_indptr(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyRj     s,    $
"6
c         C  s4   |  j  |  } |  j r! |  j n |  j } | |  S(   s  Perform regression on samples in X.

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

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

        Returns
        -------
        y_pred : array, shape (n_samples,)
        (   t   _validate_for_predictR[   t   _sparse_predictt   _dense_predict(   RG   Rx   t   predict(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR   6  s    c         C  s#  | j  \ } } |  j |  } | j d k rH t | d d d t } n  |  j } t |  j  r d } | j  d |  j d k r t d | j  d |  j d f   q n  t	 j
 |  j  } t j | |  j |  j |  j |  j |  j |  j |  j d | d	 | d
 |  j d |  j d |  j d |  j S(   Ni   RL   R=   RO   R4   i    sM   X.shape[1] = %d should be equal to %d, the number of samples at training timeR   R8   R9   R;   R:   RB   (   R   R   t   ndimR
   R]   R8   RZ   Rp   R7   R6   Ra   R5   R   R   R   R   R   Ru   Rs   R   R   R9   R;   Re   RB   (   RG   Rx   t	   n_samplest
   n_featuresR8   R   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR   I  s"    	$c         C  s   |  j  } t |  r d } n  |  j j |  } d } t j | j | j | j |  j	 j |  j	 j |  j	 j |  j
 j |  j t j |  j  | |  j |  j |  j |  j | |  j |  j |  j |  j |  j |  j |  j |  j  S(   NR4   g        (   R8   RZ   R   Ra   R   t   libsvm_sparse_predictR   R   R   R   Ru   Rs   R6   R5   R9   Re   R;   R<   R   R>   R?   R@   RA   R   R   R   (   RG   Rx   R8   R   R=   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR   `  s"    						c         C  sg   t  |  j  rc |  j | |  j  } t j |  rB | j   } n  t j | d t j d d } n  | S(   s0   Return the data transformed by a callable kernelRK   RL   R=   (	   RZ   R8   R   RW   t   issparset   toarrayR   R_   R\   (   RG   Rx   R8   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR   w  s    !c         C  s{   |  j  |  } |  j |  } |  j r9 |  j |  } n |  j |  } |  j d k rw t |  j  d k rw | j   S| S(   sb  Evaluates the decision function for the samples in X.

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

        Returns
        -------
        X : array-like, shape (n_samples, n_class * (n_class-1) / 2)
            Returns the decision function of the sample for each class
            in the model.
        R   R   i   (   R   R   (	   R   R   R[   t   _sparse_decision_functiont   _dense_decision_functionR5   Rv   Rw   t   ravel(   RG   Rx   t   dec_func(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   _decision_function  s    	$c         C  s   t  | d t j d d d t } |  j } t |  r? d } n  t j | |  j |  j	 |  j
 |  j |  j |  j |  j d t j |  j  d | d |  j d	 |  j d
 |  j d |  j S(   NRK   RL   R=   RO   R4   R   R8   R9   RB   R;   R:   (   R
   R   R\   R]   R8   RZ   R   t   decision_functionR   R   R   Ru   Rs   R   R   R6   Ra   R5   R9   RB   R;   Re   (   RG   Rx   R8   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s    			c         C  s   t  j | j d t  j d d | _ |  j } t | d  rE d } n  |  j j |  } t j	 | j | j
 | j |  j j |  j j
 |  j j |  j j |  j t j |  j  | |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j  S(   NRK   RL   R=   t   __call__R4   (   R   R_   R   R\   R8   R   R   Ra   R   t   libsvm_sparse_decision_functionR   R   R   Ru   Rs   R6   R5   R9   Re   R;   R<   R=   R   R>   R?   R@   RA   R   R   R   (   RG   Rx   R8   R   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s"    $					c      
   C  sS  t  |  d  t | d d d t j d d d t } |  j r_ t j |  r_ t j |  } n  |  j ru | j	   n  t j
 |  r |  j r t |  j  r t d t |   j   n  | j \ } } |  j d	 k r| j d
 |  j d k rOt d | j d
 |  j d f   qOn3 | |  j d
 k rOt d | |  j d
 f   n  | S(   NR   RM   RN   RK   RL   R=   RO   s3   cannot use sparse input in %r trained on dense dataR4   i   i    sM   X.shape[1] = %d should be equal to %d, the number of samples at training timesN   X.shape[1] = %d should be equal to %d, the number of features at training time(   R   R
   R   R\   R]   R[   RW   RX   R   R   R   RZ   R8   R7   t   typet   __name__R   Rp   (   RG   Rx   R   R   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s(    		)$c         C  s[   |  j  d k r t d   n  |  j   } t j |  rK t | j j _ n t | j _ | S(   NR0   s2   coef_ is only available when using a linear kernel(	   R8   t   AttributeErrort	   _get_coefRW   R   R]   R   t   flagst	   writeable(   RG   R&   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   coef_  s    c         C  s   t  |  j |  j  S(   N(   R   Ru   R   (   RG   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s    N(   R   t
   __module__t   __doc__R   R   RI   t   propertyRJ   R`   R   R^   R   Rk   Rj   R   R   R   R   R   R   R   R   R   R   (    (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR/   <   s&   x	
			#								t   BaseSVCc           B  s   e  Z d  Z e d    Z d   Z d   Z d   Z d   Z e	 d    Z
 d   Z e	 d    Z d	   Z d
   Z d   Z d   Z RS(   s!   ABC for LibSVM-based classifiers.c         C  sz   | |  _  t t |   j d | d | d | d | d | d | d | d d	 d
 | d |	 d |
 d | d | d | d |  d  S(   NR8   R9   R:   R;   R<   R=   R>   R?   g        R@   RA   RB   RC   RD   RE   RF   (   t   decision_function_shapet   superR   RI   (   RG   R8   R9   R:   R;   R<   R=   R>   R@   RA   RB   RC   RD   RE   R   RF   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyRI     s    	$c         C  s   t  | d t } t |  t j | d t \ } } t |  j | |  |  _ t |  d k  rz t	 d t |    n  | |  _
 t j | d t j d d S(   NRh   t   return_inversei   s>   The number of classes has to be greater than one; got %d classRK   RL   R=   (   R   R   R   R   t   uniqueR   RC   R   Rv   R7   Rw   R_   R\   (   RG   Ry   t   y_t   cls(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR^     s    
	c         C  sW   |  j  |  } |  j d k rS t |  j  d k rS t | d k  | t |  j   S| S(   s  Evaluates the decision function for the samples in X.

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

        Returns
        -------
        X : array-like, 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.
        t   ovri   i    (   R   R   Rv   Rw   R	   (   RG   Rx   t   dec(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s    $ c         C  s:   t  t |   j |  } |  j j t j | d t j  S(   s  Perform classification on samples in X.

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

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

        Returns
        -------
        y_pred : array, shape (n_samples,)
            Class labels for samples in X.
        RK   (   R   R   R   Rw   t   takeR   R_   t   intp(   RG   Rx   Ry   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR   0  s    c         C  s:   |  j  s t d   n  |  j d k r6 t d   n  d  S(   Ns6   predict_proba is not available when  probability=FalseR   R   s0   predict_proba only implemented for SVC and NuSVC(   R   R   (   RA   R   R5   (   RG   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   _check_probaG  s    	c         C  s   |  j    |  j S(   s  Compute 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, shape (n_samples, n_features)
            For kernel="precomputed", the expected shape of X is
            [n_samples_test, n_samples_train]

        Returns
        -------
        T : array-like, 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 `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   t   _predict_proba(   RG   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   predict_probaO  s    
c         C  sg   |  j  |  } |  j j d k s3 |  j j d k rB t d   n  |  j rT |  j n |  j } | |  S(   Ni    sA   predict_proba is not available when fitted with probability=False(   R   R   R   R   R   R[   t   _sparse_predict_probat   _dense_predict_proba(   RG   Rx   t
   pred_proba(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR   m  s
    $c         C  s   |  j    |  j S(   s  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, shape (n_samples, n_features)
            For kernel="precomputed", the expected shape of X is
            [n_samples_test, n_samples_train]

        Returns
        -------
        T : array-like, 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 `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   t   _predict_log_proba(   RG   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   predict_log_probav  s    
c         C  s   t  j |  j |   S(   N(   R   t   logR   (   RG   Rx   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s    c         C  s   |  j  |  } |  j } t |  r- d } n  t j |  j  } t j | |  j |  j	 |  j
 |  j |  j |  j |  j d | d | d |  j d |  j d |  j d |  j } | S(   NR4   R   R8   R9   RB   R;   R:   (   R   R8   RZ   R6   Ra   R5   R   R   R   R   R   Ru   Rs   R   R   R9   RB   R;   Re   (   RG   Rx   R8   R   t   pprob(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s    		c         C  s   t  j | j d t  j d d | _ |  j } t |  rB d } n  |  j j |  } t j	 | j | j
 | j |  j j |  j j
 |  j j |  j j |  j t j |  j  | |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j |  j  S(   NRK   RL   R=   R4   (   R   R_   R   R\   R8   RZ   R   Ra   R   t   libsvm_sparse_predict_probaR   R   R   Ru   Rs   R6   R5   R9   Re   R;   R<   R=   R   R>   R?   R@   RA   R   R   R   (   RG   Rx   R8   R   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s"    $					c         C  s   |  j  j d d k r. t |  j  |  j  } nU t |  j  |  j |  j  } t j | d  rt t j |  j	   } n t
 j |  } | S(   Ni    i   (   Rt   R   R   R   R.   R   RW   R   t   vstackt   tocsrR   (   RG   R&   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s    (   R   R   R   R   RI   R^   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyR     s   									c   	      C  s  i i i d t  6d 6i d t  6d t 6d 6d 6i i d t 6d 6d 6i i d	 t  6d 6i d
 t  6d t 6d 6d 6i i d t 6d 6d 6i i d t  6d t 6d 6d 6d d 6} |  d k r | |  S|  d k r t d |    n  | j | d  } | d k rd | } ni | j | d  } | d k r6d | | f } n8 | j | d  } | d k rjd | | | f } n | St d | | | | f   d S(   s  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.
    i   t   l1i    i   t   l2t   logistic_regressioni   t   hingei   i   i   t   squared_hingei   t   epsilon_insensitivei   i   t   squared_epsilon_insensitivei   t   crammer_singerR   s<   `multi_class` must be one of `ovr`, `crammer_singer`, got %rs   loss='%s' is not supporteds>   The combination of penalty='%s' and loss='%s' is not supportedsL   The combination of penalty='%s' and loss='%s' are not supported when dual=%ssJ   Unsupported set of arguments: %s, Parameters: penalty=%r, loss=%r, dual=%rN(   R]   R   R7   t   getR`   (	   t   multi_classt   penaltyt   losst   dualt   _solver_type_dictt   _solver_pent   error_stringt   _solver_dualt
   solver_num(    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   _get_liblinear_solver_type  sB    
R   R   g?c         C  s  | d k rk t    } | j |  } | j } t |  d k  rV t d | d   n  t | | |  } n t j d d t j } | } t	 j
 |  t |  } | r t d d d	 n  d
 } | r | d k r t d |   q | } n  t j
 |  t j
 |  t	 j
 |  t j |   r2t |   n  t j | d t j j   } t j | d d } | d k rt j |  j d  } n+ t j | d t j d d } t | |   t | | | |  } t	 j |  | t j |   | |
 | | | |	 | j t j d  j  | |  \ } } t |  } | |	 k rIt  j! d t"  n  | r| d d  d d  f } | | d d  d f } n | } d } | | | f S(   s  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}, shape (n_samples, n_features)
        Training vector, where n_samples in the number of samples and
        n_features is the number of features.

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

    C : float
        Inverse of cross-validation parameter. Lower the C, the more
        the penalization.

    fit_intercept : bool
        Whether or not to fit the intercept, that is to add a intercept
        term to the decision function.

    intercept_scaling : float
        LibLinear internally penalizes the intercept and this term is subject
        to regularization just like the other terms of the feature vector.
        In order to avoid this, one should increase the intercept_scaling.
        such that the feature vector becomes [x, intercept_scaling].

    class_weight : {dict, 'balanced'}, optional
        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 : str, {'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, optional (default=None)
        The seed of the pseudo random number generator to use when shuffling
        the data.  If int, random_state is the seed used by the random number
        generator; If RandomState instance, random_state is the random number
        generator; If None, the random number generator is the RandomState
        instance used by `np.random`.

    multi_class : str, {'ovr', 'crammer_singer'}
        `ovr` trains n_classes one-vs-rest classifiers, while `crammer_singer`
        optimizes a joint objective over all classes.
        While `crammer_singer` is interesting from an 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 : str, {'logistic_regression', 'hinge', 'squared_hinge',
                 'epsilon_insensitive', 'squared_epsilon_insensitive}
        The loss function used to fit the model.

    epsilon : float, optional (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, optional
        Weights assigned to each sample.

    Returns
    -------
    coef_ : ndarray, 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_ : int
        Maximum number of iterations run across all classes.
    R   R   i   se   This solver needs samples of at least 2 classes in the data, but the data contains only one class: %ri    RK   s   [LibLinear]RS   RT   g      sq   Intercept scaling is %r but needs to be greater than 0. To disable fitting an intercept, set fit_intercept=False.t   requirementst   WRL   R=   RU   s@   Liblinear failed to converge, increase the number of iterations.Nig        (   R   R   (#   R   t   fit_transformRw   Rv   R7   R   R   R   R\   R   R   R   Rl   R   R   RW   R   R   R_   R   t   requireR`   t   onesR   t   arrayR   R   t
   train_wrapRX   Rm   Rn   Ro   Rg   Rh   R   (   Rx   Ry   R=   t   fit_interceptt   intercept_scalingRC   R   R   RD   RE   R<   RF   R   R   R?   Rz   t   enct   y_indRw   R   R{   t   biasR}   t	   raw_coef_t   n_iter_R   Rq   (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   _fit_liblinear
  s\    `				
(0   t
   __future__R    t   numpyR   t   scipy.sparseR|   RW   Rg   t   abcR   R   RT   R   R   R   t   baseR   R   t   preprocessingR   t   utils.multiclassR	   t   utilsR
   R   R   R   R   R   t   utils.extmathR   t   utils.validationR   R   R   t	   externalsR   t
   exceptionsR   R   R6   R.   t   with_metaclassR/   R   R   R`   R   (    (    (    s/   lib/python2.7/site-packages/sklearn/svm/base.pyt   <module>   s6   	!" %	>