B
    	\N                 @   sV  d dl mZ d dlZd dlm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d Z)G dd de$*e	eZ+G dd de$*e	e+eZ,dd  Z-d&d$d%Z.dS )'    )print_functionN)ABCMetaabstractmethod   )libsvm	liblinear)libsvm_sparse   )BaseEstimatorClassifierMixin)LabelEncoder)_ovr_decision_function)check_arraycheck_consistent_lengthcheck_random_state)column_or_1d	check_X_y)compute_class_weight)safe_sparse_dot)check_is_fitted_check_large_sparse)check_classification_targets)six)ConvergenceWarning)NotFittedErrorc_svcnu_svcZ	one_classZepsilon_svrZnu_svrc             C   s   | j d d }g }ttdg|g}xt|D ]}||| ||d  ddf }xt|d |D ]z}||| ||d  ddf }	| |d || ||d  f }
| ||| ||d  f }|t|
|t||	  qfW q2W |S )zGenerate primal coefficients from dual coefficients
    for the one-vs-one multi class LibSVM in the case
    of a linear kernel.r   r   N)shapenpZcumsumZhstackrangeappendr   )Z	dual_coefZ	n_supportZsupport_vectorsn_classcoefZsv_locsZclass1Zsv1Zclass2Zsv2Zalpha1Zalpha2 r#   /lib/python3.7/site-packages/sklearn/svm/base.py_one_vs_one_coef   s    	   r%   c               @   s   e Zd ZdZdddddgZedd Zed	d
 Zd*ddZ	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zed&d' Zd(d) Zd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.
    linearZpolyZrbfZsigmoidprecomputedc             C   s   | j tkrtdt| j f |dkr0d}t||| _|| _|| _|| _|| _|| _|| _	|| _
|	| _|
| _|| _|| _|| _|| _|| _d S )Nz&impl should be one of %s, %s was givenr   zXThe gamma value of 0.0 is invalid. Use 'auto' to set gamma to a value of 1 / n_features.)_implLIBSVM_IMPL
ValueErrorkerneldegreegammacoef0tolCnuepsilon	shrinkingprobability
cache_sizeclass_weightverbosemax_iterrandom_state)selfr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   msgr#   r#   r$   __init__I   s*    
zBaseLibSVM.__init__c             C   s
   | j dkS )Nr(   )r,   )r;   r#   r#   r$   	_pairwiseg   s    zBaseLibSVM._pairwiseNc             C   s  t | j}t|}|r*| jdkr*td|o8t| j | _t||t	j
dddd\}}| |}t	j|dkrpg n|t	j
d}t| j}|d	kr|jd
 |jd
 krtdd|jd
 |jd
 f  | jdkr|jd
 |jd krtd|jd
 d
kr$|jd
 |jd
 kr$td|j|jf | jdkr|rR|| | d	  }n| }| jdkr|d
krd|jd |  | _nd| _nHt| j o| jdk}|rt	|dstdt d|jd  | _n&| jdkrd|jd  | _n| j| _| j}	t|	rd}	| jr | jn| j}
| jr:tddd |t	 dj!}|
|||||	|d |j| _"| j#$ | _%| j&| _'| jdkrt(| j)d	kr|  j#d9  _#| j& | _&| S )a5  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.
        r(   z-Sparse precomputed kernels are not supported.r1   csrF)dtypeorderaccept_sparseaccept_large_sparseN)r@   r	   r   z"X and y have incompatible shapes.
zX has %s samples, but y has %s.r   z(X.shape[0] should be equal to X.shape[1]zsample_weight and X have incompatible shapes: %r vs %r
Note: Sparse matrices cannot be indexed w/boolean masks (use `indices=True` in CV).)scaleZauto_deprecatedrD   g      ?)r'   r(   zThe 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.autoz[LibSVM] )endi)random_seed)r   r   )*r   r:   sp
isspmatrixr,   	TypeErrorcallable_sparser   r   float64_validate_targetsasarrayr*   indexr)   r   r+   r.   ZmultiplyZmeanvar_gammaZisclosewarningswarnFutureWarning_sparse_fit
_dense_fitr8   printrandintiinfomax
shape_fit_
intercept_copy_intercept_
dual_coef__dual_coef_lenclasses_)r;   Xysample_weightrndsparsesolver_typeZX_varZkernel_uses_gammar,   fitZseedr#   r#   r$   rm   l   sl     



&


zBaseLibSVM.fitc             C   s    t d| _t|ddt jS )zxValidation of y and class_weight.

        Default implementation for SVR and one-class; overridden in BaseSVC.
        r   T)rW   )r   emptyclass_weight_r   ZastyperP   )r;   rh   r#   r#   r$   rQ      s    zBaseLibSVM._validate_targetsc             C   s.   | j dkst| j dkr*td| j t d S )N)r   r   r   znSolver terminated early (max_iter=%i).  Consider pre-processing your data with StandardScaler or MinMaxScaler.)fit_status_AssertionErrorrV   rW   r9   r   )r;   r#   r#   r$   _warn_from_fit_status   s    
z BaseLibSVM._warn_from_fit_statusc             C   s   t | jr6|| _| |}|jd |jd kr6tdt| j tj	||||| j
|| j| j| j| j| j| j| j| j| j| j| j|d\| _| _| _| _| _| _| _| _|   d S )Nr   r   z(X.shape[0] should be equal to X.shape[1])svm_typeri   r7   r,   r1   r2   r5   r-   r4   r0   r6   r/   r.   r3   r9   rI   )rN   r,   _BaseLibSVM__Xfit_compute_kernelr   r+   r   set_verbosity_wrapr8   rm   ro   r1   r2   r5   r-   r4   r0   r6   r/   rU   r3   r9   support_support_vectors_
n_support_rc   r`   probA_probB_rp   rr   )r;   rg   rh   ri   rl   r,   rI   r#   r#   r$   rZ      s     


,zBaseLibSVM._dense_fitc             C   s,  t j|jt jdd|_|  | j|}t| j	 t
|jd |j|j|j|||| j| j| j| j| j| j|| j| j| jt| jt| j| j|\| _| _}| _| _| _| _ | _!| "  t#| drt$| j%d }	nd}	| jjd }
t &t '|
|	}t 'd|j(d |j(|	 }t)*|||f|	|
f| _+d S )Nr1   )r@   rA   r   rf   r   ),r   rR   datarP   sort_indices_sparse_kernelsrS   r   rv   r8   Zlibsvm_sparse_trainr   indicesindptrr-   rU   r/   r0   r1   ro   r2   r6   r3   intr4   r5   r9   rw   rx   r`   ry   rz   r{   rp   rr   hasattrre   rf   ZtileZarangesizerK   
csr_matrixrc   )r;   rg   rh   ri   rl   r,   rI   kernel_typeZdual_coef_datar!   Zn_SVZdual_coef_indicesZdual_coef_indptrr#   r#   r$   rY     s,    $
zBaseLibSVM._sparse_fitc             C   s$   |  |}| jr| jn| j}||S )a  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,)
        )_validate_for_predictrO   _sparse_predict_dense_predict)r;   rg   predictr#   r#   r$   r   6  s    
zBaseLibSVM.predictc             C   s   |j \}}| |}|jdkr,t|ddd}| j}t| jrpd}|j d | jd krptd|j d | jd f t	| j
}tj|| j| j| j| j| j| j| j||| j| j| j| jdS )	Nr   r1   F)rA   rC   r(   r   zMX.shape[1] = %d should be equal to %d, the number of samples at training time)rs   r,   r-   r/   r.   r6   )r   ru   ndimr   r,   rN   r_   r+   r*   rS   r)   r   r   rw   rx   ry   rd   rb   rz   r{   r-   r/   rU   r6   )r;   rg   	n_samples
n_featuresr,   rs   r#   r#   r$   r   I  s"    



zBaseLibSVM._dense_predictc             C   s   | j }t|rd}| j|}d}t|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S )Nr(   g        )r,   rN   r~   rS   r   Zlibsvm_sparse_predictr|   r   r   rx   rd   rb   r*   r)   r-   rU   r/   r0   ro   r2   r3   r4   r5   ry   rz   r{   )r;   rg   r,   r   r1   r#   r#   r$   r   `  s"    
zBaseLibSVM._sparse_predictc             C   s@   t | jr<| || j}t|r*| }tj|tjdd}|S )z0Return the data transformed by a callable kernelr1   )r@   rA   )	rN   r,   rt   rK   issparseZtoarrayr   rR   rP   )r;   rg   r,   r#   r#   r$   ru   w  s    

zBaseLibSVM._compute_kernelc             C   sV   |  |}| |}| jr&| |}n
| |}| jdkrRt| jdkrR|  S |S )ab  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   r	   )	r   ru   rO   _sparse_decision_function_dense_decision_functionr)   re   rf   ravel)r;   rg   Zdec_funcr#   r#   r$   _decision_function  s    



zBaseLibSVM._decision_functionc             C   sh   t |tjddd}| j}t|r$d}tj|| j| j| j	| j
| j| j| jt| j|| j| j| j| jdS )Nr1   F)r@   rA   rC   r(   )rs   r,   r-   r6   r/   r.   )r   r   rP   r,   rN   r   decision_functionrw   rx   ry   rd   rb   rz   r{   r*   rS   r)   r-   r6   r/   rU   )r;   rg   r,   r#   r#   r$   r     s    


z#BaseLibSVM._dense_decision_functionc             C   s   t j|jt jdd|_| j}t|dr*d}| j|}t	|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 )Nr1   )r@   rA   __call__r(   )r   rR   r|   rP   r,   r   r~   rS   r   Zlibsvm_sparse_decision_functionr   r   rx   rd   rb   r*   r)   r-   rU   r/   r0   r1   ro   r2   r3   r4   r5   ry   rz   r{   )r;   rg   r,   r   r#   r#   r$   r     s"    

z$BaseLibSVM._sparse_decision_functionc             C   s   t | d t|dtjddd}| jr8t|s8t|}| jrF|  t	|rr| jsrt
| jsrtdt| j |j\}}| jdkr|jd | jd	 krtd
|jd | jd	 f n$|| jd krtd|| jd f |S )Nrw   r?   r1   F)rB   r@   rA   rC   z3cannot use sparse input in %r trained on dense datar(   r   r   zMX.shape[1] = %d should be equal to %d, the number of samples at training timezNX.shape[1] = %d should be equal to %d, the number of features at training time)r   r   r   rP   rO   rK   rL   r   r}   r   rN   r,   r+   type__name__r   r_   )r;   rg   r   r   r#   r#   r$   r     s(    



z BaseLibSVM._validate_for_predictc             C   s<   | j dkrtd|  }t|r0d|jj_nd|j_|S )Nr'   z2coef_ is only available when using a linear kernelF)r,   AttributeError	_get_coefrK   r   r|   flagsZ	writeable)r;   r"   r#   r#   r$   coef_  s    

zBaseLibSVM.coef_c             C   s   t | j| jS )N)r   rd   rx   )r;   r#   r#   r$   r     s    zBaseLibSVM._get_coef)N)r   
__module____qualname____doc__r~   r   r=   propertyr>   rm   rQ   rr   rZ   rY   r   r   r   ru   r   r   r   r   r   r   r#   r#   r#   r$   r&   <   s&   
x
#r&   c                   s   e Zd ZdZe fddZdd Zdd Z fdd	Zd
d Z	e
dd Zdd Ze
dd Zdd Zdd Zdd Zdd Z  ZS )BaseSVCz!ABC for LibSVM-based classifiers.c                s8   || _ tt| j|||||||d||	|
||||d d S )Ng        )r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   )decision_function_shapesuperr   r=   )r;   r,   r-   r.   r/   r0   r1   r2   r4   r5   r6   r7   r8   r9   r   r:   )	__class__r#   r$   r=     s    
zBaseSVC.__init__c             C   sj   t |dd}t| tj|dd\}}t| j||| _t|dk rRtdt| || _	tj
|tjddS )NT)rW   )Zreturn_inverser	   z>The number of classes has to be greater than one; got %d classr1   )r@   rA   )r   r   r   uniquer   r7   ro   re   r+   rf   rR   rP   )r;   rh   Zy_clsr#   r#   r$   rQ     s    zBaseSVC._validate_targetsc             C   s>   |  |}| jdkr:t| jdkr:t|dk | t| jS |S )a  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.
        ovrr	   r   )r   r   re   rf   r   )r;   rg   Zdecr#   r#   r$   r     s    
zBaseSVC.decision_functionc                s(   t t| |}| jtj|tjdS )a  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.
        )r@   )r   r   r   rf   Ztaker   rR   Zintp)r;   rg   rh   )r   r#   r$   r   0  s    zBaseSVC.predictc             C   s$   | j std| jdkr tdd S )Nz6predict_proba is not available when  probability=False)r   r   z0predict_proba only implemented for SVC and NuSVC)r5   r   r)   )r;   r#   r#   r$   _check_probaG  s    
zBaseSVC._check_probac             C   s   |    | jS )a  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   _predict_proba)r;   r#   r#   r$   predict_probaO  s    zBaseSVC.predict_probac             C   sD   |  |}| jjdks"| jjdkr*td| jr6| jn| j}||S )Nr   zApredict_proba is not available when fitted with probability=False)r   rz   r   r{   r   rO   _sparse_predict_proba_dense_predict_proba)r;   rg   Z
pred_probar#   r#   r$   r   m  s
    
zBaseSVC._predict_probac             C   s   |    | 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, 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   _predict_log_proba)r;   r#   r#   r$   predict_log_probav  s    zBaseSVC.predict_log_probac             C   s   t | |S )N)r   logr   )r;   rg   r#   r#   r$   r     s    zBaseSVC._predict_log_probac             C   sh   |  |}| j}t|rd}t| j}tj|| j| j	| j
| j| j| j| j||| j| j| j| jd}|S )Nr(   )rs   r,   r-   r6   r/   r.   )ru   r,   rN   r*   rS   r)   r   r   rw   rx   ry   rd   rb   rz   r{   r-   r6   r/   rU   )r;   rg   r,   rs   Zpprobr#   r#   r$   r     s    
zBaseSVC._dense_predict_probac             C   s   t j|jt jdd|_| j}t|r(d}| j|}t	|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 )Nr1   )r@   rA   r(   )r   rR   r|   rP   r,   rN   r~   rS   r   Zlibsvm_sparse_predict_probar   r   rx   rd   rb   r*   r)   r-   rU   r/   r0   r1   ro   r2   r3   r4   r5   ry   rz   r{   )r;   rg   r,   r   r#   r#   r$   r     s"    
zBaseSVC._sparse_predict_probac             C   s^   | j jd dkr t| j | j}n:t| j | j| j}t|d rPt|	 }n
t
|}|S )Nr   r   )rc   r   r   rx   r%   ry   rK   r   ZvstackZtocsrr   )r;   r"   r#   r#   r$   r     s    

zBaseSVC._get_coef)r   r   r   r   r   r=   rQ   r   r   r   r   r   r   r   r   r   r   r   __classcell__r#   r#   )r   r$   r     s   	r   c       	      C   s   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krpt d|  ||d}|dkrd| }nJ||d}|dkrd||f }n(||d}|dkrd|||f }n|S t d||||f dS )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l2r   T      r	   r               )logistic_regressionZhingeZsquared_hingeepsilon_insensitivesquared_epsilon_insensitivecrammer_singerr   r   z<`multi_class` must be one of `ovr`, `crammer_singer`, got %rNzloss='%s' is not supportedz>The combination of penalty='%s' and loss='%s' is not supportedzLThe combination of penalty='%s' and loss='%s' are not supported when dual=%szJUnsupported set of arguments: %s, Parameters: penalty=%r, loss=%r, dual=%r)r+   get)	multi_classpenaltylossdualZ_solver_type_dictZ_solver_penZerror_stringZ_solver_dualZ
solver_numr#   r#   r$   _get_liblinear_solver_type  s6    


r   r   r   皙?c             C   s  |dkrHt  }||}|j}t|dk r:td|d  t|||}ntjdtjd}|}t	
| t|}|r~tddd d	}|r|dkrtd
| n|}t
| t
| t	
| t| rt|  tj|tjd }tj|dd}|dkrt| jd }ntj|tjdd}t||  t||||}t	| |t| ||
||||	|tdj||\}}t|}||	krt dt! |r|ddddf }||dddf  }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}, 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   r	   zeThis solver needs samples of at least 2 classes in the data, but the data contains only one class: %rr   )r@   z[LibLinear]rF   )rG   g      zqIntercept scaling is %r but needs to be greater than 0. To disable fitting an intercept, set fit_intercept=False.W)ZrequirementsNr1   )r@   rA   rH   z@Liblinear failed to converge, increase the number of iterations.rJ   g        )"r   Zfit_transformrf   re   r+   r   r   rn   rP   r   rv   r   r[   r   r   rK   r   r   rR   r   ZrequireZonesr   Zarrayr   r   Z
train_wraprL   r\   r]   r^   rV   rW   r   )rg   rh   r1   Zfit_interceptZintercept_scalingr7   r   r   r8   r9   r0   r:   r   r   r3   ri   encZy_indrf   ro   rj   Zbiasrl   Z	raw_coef_Zn_iter_r   r`   r#   r#   r$   _fit_liblinear
  s\    `









r   )Nr   r   r   N)/Z
__future__r   Znumpyr   Zscipy.sparserk   rK   rV   abcr   r   rF   r   r   r   baser
   r   Zpreprocessingr   Zutils.multiclassr   Zutilsr   r   r   r   r   r   Zutils.extmathr   Zutils.validationr   r   r   Z	externalsr   
exceptionsr   r   r*   r%   Zwith_metaclassr&   r   r   r   r#   r#   r#   r$   <module>   s<   !   > X>  