
\c           @  s
  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l	 m
 Z
 d  d l Z d  d l 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 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  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% 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* 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/ d  d  l m0 Z0 d  d! l1 m2 Z2 d  d" l3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 d  d# l: m; Z; m< Z< m= Z= d  d$ l> m? Z? d  d% l@ mA ZA d  d& lB mC ZC d  d' lD mE ZE d  d( lF mG ZG d  d) lH mI ZI d  d* lH mJ ZJ d  d+ lK mL ZL d  d, lM mN ZN mO ZO mP ZP d  d- l mQ ZQ d  d. lR mS ZS d  d/ lT mU ZU mV ZV mW ZW d  d0 lX mY ZY d  d1 lZ m[ Z[ m\ Z\ m] Z] d a_ d2 d3 d4 d5 g Z` d4 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF d2 d3 dG dH dI dJ dK g Za dL dM dN dO dP dQ dR dS dT g	 Zb dM dN g Zc dU   Zd dV   Ze e- dW ef eg f  dX    Zh dY   Zi dZ   Zj d[   Zk d\   Zl d]   Zm d^   Zn d_ d`  Zo da   Zp db eq f dc     YZr dd   Zs de   Zt eO df  Zu dg   Zv dh   Zw e- dW ef eg f  di    Zx e- dW ef eg f  dj    Zy e- dW ef eg f  dk    Zz e- dW ef eg e{ f  dl    Z| dm   Z} e- dn    Z~ do   Z e- dW ef eg f  dp    Z e- dW ef eg f  dq    Z dr   Z e- dW ef eg f  ds    Z e- dt    Z e- du    Z e- dv    Z e- dW ef eg f  e dw   Z e- dW ef eg f  dx    Z e- dW ef eg f  dy    Z dz   Z e- d{    Z e- d|    Z e- d}    Z e- dW ef eg f  d~    Z e- dW ef  d    Z e- d    Z e- dW ef eg f  d    Z e- dW ef eg f  e d   Z e- dW ef  d    Z e- dW ef  d    Z e- e d   Z e d  Z e- dW ef eg f  e d   Z e- d    Z e- dW ef eg f  d    Z e- d    Z d   Z d   Z e- dW ef eg f  d    Z e- dW ef eg f  e d   Z e- d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef  d    Z e- dW ef  d    Z e- dW ef eg f  d    Z d   Z d   Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z e- dW ef eg f  d    Z d   Z d S(   i(   t   print_functionN(   t   deepcopy(   t   partial(   t   sparse(   t   rankdata(   t   zip(   t   IS_PYPYt	   _IS_32BIT(   t   _joblib(   t   Memory(   t   assert_raisest	   _get_args(   t   assert_raises_regex(   t   assert_raise_message(   t   assert_equal(   t   assert_not_equal(   t   assert_almost_equal(   t   assert_true(   t   assert_false(   t	   assert_in(   t   assert_array_equal(   t   assert_allclose(   t   assert_allclose_dense_sparse(   t   assert_warns_message(   t   META_ESTIMATORS(   t   set_random_state(   t   assert_greater(   t   assert_greater_equal(   t   SkipTest(   t   ignore_warnings(   t   assert_dict_equal(   t   create_memmap_backed_data(   t   is_scalar_nan(   t   LinearDiscriminantAnalysis(   t   clonet   ClusterMixint   BaseEstimatort   is_classifiert   is_regressort   is_outlier_detector(   t   accuracy_scoret   adjusted_rand_scoret   f1_score(   t   BaseRandomProjection(   t   SelectKBest(   t
   BaseLibSVM(   t   BaseSGD(   t   make_pipeline(   t   DataConversionWarning(   t   SkipTestWarning(   t   train_test_split(   t
   rbf_kernelt   linear_kernelt   pairwise_distances(   t   shuffle(   t	   signature(   t   has_fit_parametert   _num_samplest   LARGE_SPARSE_SUPPORTED(   t   StandardScaler(   t	   load_irist   load_bostont
   make_blobst   PLSCanonicalt   PLSRegressiont   CCAt   PLSSVDt   DecisionTreeRegressort
   ElasticNett   ExtraTreeRegressort   ExtraTreesRegressort   GaussianProcessRegressort   TransformedTargetRegressort   KNeighborsRegressort   KernelRidget   Larst   Lassot	   LassoLarst   LinearRegressiont   MultiTaskElasticNett   MultiTaskElasticNetCVt   MultiTaskLassot   MultiTaskLassoCVt   OrthogonalMatchingPursuitt   RANSACRegressort   RadiusNeighborsRegressort   RandomForestRegressort   Ridget   RidgeCVt   Imputert   SimpleImputert   MissingIndicatort   MaxAbsScalert   MinMaxScalert   RobustScalerR;   t   PowerTransformert   QuantileTransformerc         c  s   t  Vt Vt Vt Vt Vt Vt Vt t d t Vt	 Vt
 V|  t d g k rY t Vn  |  t k rm t Vn  t Vt | d  r t Vn  t Vt Vd  S(   Nt   readonly_memmapt   SpectralEmbeddingt   sparsify(   t   check_estimators_dtypest   check_fit_score_takes_yt   check_dtype_objectt"   check_sample_weights_pandas_seriest   check_sample_weights_listt   check_sample_weights_invariancet!   check_estimators_fit_returns_selfR   t   Truet   check_complex_datat$   check_estimators_empty_data_messagest   CROSS_DECOMPOSITIONt   check_pipeline_consistencyt	   ALLOW_NANt   check_estimators_nan_inft!   check_estimators_overwrite_paramst   hasattrt   check_sparsify_coefficientst   check_estimator_sparse_datat   check_estimators_pickle(   t   namet	   estimator(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _yield_non_meta_checksV   s&    c         c  s   t  Vt Vt Vt Vt Vt t d t Vt V|  d	 k rO |  d
 k rO t Vn  t	 Vt
 Vd | j   j   k ry t Vn  t Vt Vd  S(   NRa   t   MultinomialNBt   ComplementNBt   LabelPropagationt   LabelSpreadingt   DecisionTreeClassifiert   ExtraTreeClassifiert   class_weight(   Rz   R{   R|   R}   (   R~   R   (   t"   check_classifier_data_not_an_arrayt   check_classifiers_one_labelt   check_classifiers_classest'   check_estimators_partial_fit_n_featurest   check_classifiers_trainR   Rk   t#   check_classifiers_regression_targett   check_supervised_y_2dt   check_supervised_y_no_nant   check_estimators_unfittedt
   get_paramst   keyst   check_class_weight_classifierst'   check_non_transformer_estimators_n_itert    check_decision_proba_consistency(   Rw   t
   classifier(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _yield_classifier_checks{   s"    	t   categoryc         C  s   t  |  } t j j d  } | j d d  } t j d t j  } t | |  } d } y | j | |  Wn= t	 k
 r } t
 |  | k r t	 d j |     q n Xt	 d j |     d  S(   Nix  i
   i   sG   Input contains NaN, infinity or a value too large for dtype('float64').sQ   Estimator {0} raised error as expected, but does not match expected error messagesI   Estimator {0} should have raised error on fitting array y with NaN value.(   R"   t   npt   randomt   RandomStatet   randnt   fullt   inft"   multioutput_estimator_convert_y_2dt   fitt
   ValueErrort   strt   format(   Rw   t   estimator_origRx   t   rngt   Xt   yt   errmsgt   e(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR      s    		c         c  s`   t  Vt t  d t Vt Vt Vt Vt Vt V|  d k rC t Vn  |  d k rW t	 Vn  t
 Vd  S(   NRa   RA   RG   (   t   check_regressors_trainR   Rk   t!   check_regressor_data_not_an_arrayR   t%   check_regressors_no_decision_functionR   R   t   check_regressors_intR   R   (   Rw   t	   regressor(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _yield_regressor_checks   s    c         c  sk   |  d k r t  Vn  |  d k r> t Vt t d	 t Vt Vn  d
 d d d d g } |  | k rg t Vn  d  S(   Nt   AdditiveChi2Samplert	   Binarizert
   NormalizerR?   R@   RA   RB   t   FunctionTransformerRa   t   Isomapt	   KernelPCAt   LocallyLinearEmbeddingt   RandomizedLassot   LogisticRegressionCV(   R   R   R   R?   R@   RA   RB   (   R   R   R   R   (   t#   check_transformer_data_not_an_arrayt   check_transformer_generalR   Rk   t   check_transformers_unfittedt   check_transformer_n_iter(   Rw   t   transformert   external_solver(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _yield_transformer_checks   s    			c         c  s8   t  V|  d k r/ t Vt t d t Vt Vn  t Vd  S(   Nt   WardAgglomerationt   FeatureAgglomerationRa   (   R   R   (   t&   check_clusterer_compute_labels_predictt   check_clusteringR   Rk   R   R   (   Rw   t	   clusterer(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _yield_clustering_checks   s    c         c  sM   t  | d  r t Vn  t  | d  rI t Vt t d t Vt Vt Vn  d  S(   Nt   fit_predictt   predictRa   (   Rs   t   check_outliers_fit_predictt   check_outliers_trainR   Rk   R   R   (   Rw   Rx   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _yield_outliers_checks   s    c         c  s<  x t  |  |  D] } | Vq Wt |  rM x t |  |  D] } | Vq; Wn  t |  r{ x t |  |  D] } | Vqi Wn  t | d  r x t |  |  D] } | Vq Wn  t | t  r x t	 |  |  D] } | Vq Wn  t
 |  rx t |  |  D] } | Vq Wn  t Vt Vt Vt Vt Vt Vt Vt Vt Vd  S(   Nt	   transform(   Ry   R%   R   R&   R   Rs   R   t
   isinstanceR#   R   R'   R   t   check_fit2d_predict1dt   check_methods_subset_invariancet   check_fit2d_1samplet   check_fit2d_1featuret   check_fit1dt   check_get_params_invariancet   check_set_paramst   check_dict_unchangedt   check_dont_overwrite_parameters(   Rw   Rx   t   check(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _yield_all_checks   s4    	c         C  s   t  |  t  r> |  j } |    } t | |   t | |  n |  } t |  j } xT t | |  D]C } y | | |  Wqc t k
 r } t j t	 |  t
  qc Xqc Wd S(   s  Check if estimator adheres to scikit-learn conventions.

    This estimator will run an extensive test-suite for input validation,
    shapes, etc.
    Additional tests for classifiers, regressors, clustering or transformers
    will be run if the Estimator class inherits from the corresponding mixin
    from sklearn.base.

    This test can be applied to classes or instances.
    Classes currently have some additional tests that related to construction,
    while passing instances allows the testing of multiple options.

    Parameters
    ----------
    estimator : estimator object or class
        Estimator to check. Estimator is a class object or instance.

    N(   R   t   typet   __name__t&   check_parameters_default_constructiblet   check_no_attributes_set_in_initR   R   t   warningst   warnR   R1   (   t	   EstimatorRw   Rx   R   t	   exception(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   check_estimator  s    		i   c         C  s}   t  d  k ry t   } | j | j } } t | | d d \ } } | |   | |   } } t   j |  } | | f a  n  t  S(   Nt   random_statei    (   t   BOSTONt   NoneR=   t   datat   targetR6   R;   t   fit_transform(   t	   n_samplest   bostonR   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _boston_subset7  s    	c         C  sr  |  j    } d | k rM |  j j d k rM t |  t  rM |  j d d  n  d | k r |  j d  k	 r |  j d t d |  j   n  |  j j d k r |  j d d  n  |  j j d k r |  j d d	  n  |  j j d  k r |  j d d	  q n  d | k r|  j d d  n  d | k re|  j	 d k rF|  j d d  qe|  j d t d |  j	   n  d | k r|  j d d  n  d | k r|  j d d  n  d | k r|  j d d  n  |  j j d k r|  j d d  n  |  j j d k rd	 |  _
 n  |  j j d k r*|  j d d  n  t |  t  rL|  j d d  n  t |  t  rn|  j d d  n  d  S(!   Nt   n_itert   TSNEi   t   max_itert	   LinearSVRt	   LinearSVCi   t   NMFid   t   MLPClassifiert   MLPRegressort   n_resamplingt   n_estimatorsR   t
   max_trialsi
   t   n_initi   t   decision_function_shapet   ovot	   SelectFdrt   alphag      ?t   TheilSenRegressort   IsolationForestt	   behaviourt   newt   n_componentst   ki   (   R   R   (   R   R   (   R   t	   __class__R   R   R.   t
   set_paramsR   R   t   minR   t   max_subpopulationR+   R,   (   Rx   t   params(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   set_checking_parametersC  sF    t
   NotAnArrayc           B  s#   e  Z d  Z d   Z d d  Z RS(   su   An object that is convertible to an array

    Parameters
    ----------
    data : array_like
        The data.
    c         C  s   | |  _  d  S(   N(   R   (   t   selfR   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   __init__  s    c         C  s   |  j  S(   N(   R   (   R   t   dtype(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt	   __array__  s    N(   R   t
   __module__t   __doc__R  R   R  (    (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s   	c         C  s   t  t |  d t   S(   s  Returns True if estimator has a _pairwise attribute set to True.

    Parameters
    ----------
    estimator : object
        Estimator object to test.

    Returns
    -------
    out : bool
        True if _pairwise is set to True and False otherwise.
    t	   _pairwise(   t   boolt   getattrt   False(   Rx   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _is_pairwise  s    c         C  s"   t  |  d d  } t | d k  S(   s   Returns True if estimator accepts pairwise metric.

    Parameters
    ----------
    estimator : object
        Estimator object to test.

    Returns
    -------
    out : bool
        True if _pairwise is set to True and False otherwise.
    t   metrict   precomputedN(   R  R   R  (   Rx   R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _is_pairwise_metric  s    c         C  s9   t  |  r t |  d d St |  r5 | |  |   S|  S(   NR  t	   euclidean(   R  R5   R
  (   R   Rx   t   kernel(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   pairwise_estimator_convert_X  s
    c         c  s  |  j  d k s t  d |  j   f Vx4 d d d d d d g D] } | |  j |  f Vq? Wt r	|  j d  } | j j d  | _ | j j d  | _ d	 | f Vx_ d d g D]N } |  j |  } | j j d  | _ | j	 j d  | _	 | d
 | f Vq Wn  d S(   s^  Generate sparse matrices with {32,64}bit indices of diverse format

        Parameters
        ----------
        X_csr: CSR Matrix
            Input matrix in CSR format

        Returns
        -------
        out: iter(Matrices)
            In format['dok', 'lil', 'dia', 'bsr', 'csr', 'csc', 'coo',
             'coo_64', 'csc_64', 'csr_64']
    t   csrt   dokt   lilt   diat   bsrt   csct   coot   int64t   coo_64t   _64N(
   R   t   AssertionErrort   copyt   asformatR:   t   rowt   astypet   colt   indicest   indptr(   t   X_csrt   sparse_formatt   X_cooR   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _generate_sparse_matrix  s    c      
   C  sQ  t  j j d  } | j d d  } d | | d k  <t | |  } t j |  } d | j d  j t  j  } t	 d t
   t |  } Wd  QXt | |  } xt |  D]\ } } t	 d t
 t f  8 |  d k r t |  j d	 t  } n t |  } Wd  QXy t	 d t
 t f   | j | |  Wd  QXt | d
  rt| j |  } t | j | j d f  n  t | d  r| j |  }	 t |	 j | j d d f  n  Wq t t f k
 r%}
 d t |
  j   k rId | k rd } t | |  | f   q"t d |     qIq t k
 rH}
 t d |     q Xq Wd  S(   Ni    i(   i
   g?i   R   t   ScalerR;   t	   with_meanR   t   predict_probaR   t   64s   Estimator %s doesn't seem to support %s matrix, and is not failing gracefully, e.g. by using check_array(X, accept_large_sparse=False)s   Estimator %s doesn't seem to fail gracefully on sparse data: error message state explicitly that sparse input is not supported if this is not the case.s   Estimator %s doesn't seem to fail gracefully on sparse data: it should raise a TypeError if sparse input is explicitly not supported.(   R'  R;   (   R   R   R   t   randR  R   t
   csr_matrixR  t   intR   t   DeprecationWarningR"   R   R&  t   FutureWarningR   R	  R   Rs   R   R   t   shapeR)  t	   TypeErrorR   t   reprt   lowerR  t   printt	   Exception(   Rw   R   R   R   R#  R   Rx   t   matrix_formatt   predt   probsR   t   msg(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRu     sF    $	c      
   C  sA  t  |  } t | d  r=y d d  l } t j d d g d d g d d g d d g d d g d d g d d g d d g g  } | j t | |   } | j d d d d d d d d g  } | j d g d  } y | j | | d | Wn& t	 k
 rt	 d j
 |     n XWq=t k
 r9t d	   q=Xn  d  S(
   Nt   sample_weightii   i   i   i   i   sP   Estimator {0} raises error if 'sample_weight' parameter is of type pandas.SeriessU   pandas is not installed: not testing for input of type pandas.Series to class weight.(   R"   R8   t   pandasR   t   arrayt	   DataFrameR  t   SeriesR   R   R   t   ImportErrorR   (   Rw   R   Rx   t   pdR   R   t   weights(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRg     s     *-'	c         C  s   t  | d  r t |  } t j j d  } t | j d d  |  } t j d  d } t | |  } d g d } | j	 | | d | n  d  S(   NR:  i    t   sizei
   i   (   i
   i   (
   R8   R"   R   R   R   R  t   uniformt   arangeR   R   (   Rw   R   Rx   t   rndR   R   R:  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRh   .  s    	c   	      C  s  t  | d  rt | d  o$ | j rt |  } t |  } t | d d t | d d t j d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g g d	 t j d
  } t j d d d d d d d d d d d d d d d d g d	 t j d  } | j | d | d t j	 d t
 |   | j | d | d d  xj d d g D]Y } t | |  rt | |  |  } t | |  |  } t | | d d |  qqWn  d  S(   NR:  R  R   i    i   i   i   i   R  t   floatR-  R   R0  R   R   t   err_msgsA   For %s sample_weight=None is not equivalent to sample_weight=ones(   R8   Rs   R  R"   R   R   R<  R  R   t   onest   lenR   R  R   (	   Rw   R   t
   estimator1t
   estimator2R   R   t   methodt   X_pred1t   X_pred2(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRi   >  s,    
*$$<0+c         C  si  t  j j d  } t | j d d  |  } | j t  } | d  d   d f d j t  j  } t |  } t	 | |  } | j
 | |  t | d  r | j |  n  t | d  r | j |  n  y | j
 | | j t   Wn+ t k
 r} d t |  k r  qn X|  t k rUi d d	 6| d <d
 } t t | | j
 | |  n | j
 | |  d  S(   Ni    i(   i
   i   R   R   s   Unknown label typet   bart   foos%   argument must be a string or a number(   i    i    (   R   R   R   R  R+  R  t   objectR-  R"   R   R   Rs   R   R   R5  R   t   SUPPORT_STRINGR   R1  (   Rw   R   R   R   R   Rx   R   R9  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRf   `  s*    &
c         C  s   t  j j d  d t  j j d  } | j d d  } t  j j d  d t  j j d  } t |  } t t d | j | |  d  S(   Ni
   y              ?ii   s   Complex data not supported(   R   R   t   samplet   reshapeR"   R   R   R   (   Rw   R   R   R   Rx   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRl     s    &&	c         C  s  |  d k r d  St  j j d  } |  d k rG d | j d d  } n d | j d d  } t | |  } | d  d   d f j t  j  } t |  } t | |  } t	 | d  r d	 | _
 n  t	 | d
  r d	 | _ n  t	 | d  r d	 | _ n  t | d	  | j | |  xe d d d d g D]Q } t	 | |  r*| j j   } t | |  |  t | j | d |  q*q*Wd  S(   Nt   SpectralCoclusteringi    RT   i   RB  i   i   R   i   t
   n_clusterst   n_bestR   R   t   decision_functionR)  s$   Estimator changes __dict__ during %s(   RU  (   RT   (   i   i   (   i   i   (   R   R   R   RC  R  R  R-  R"   R   Rs   R   RV  RW  R   R   t   __dict__R  R  R   (   Rw   R   RE  R   R   Rx   RL  t   dict_before(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s2    "c         C  s   |  j  d  p |  j d  S(   Nt   _(   t
   startswitht   endswith(   t   attr(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   is_public_parameter  s    c         C  s  t  | j d  r d  St |  } t j j d  } d | j d d  } t | |  } | d  d   d f j t j	  } t
 | |  } t  | d  r d | _ n  t  | d  r d | _ n  t | d  | j j   } | j | |  | j } g  | j   D] } t |  r| ^ q}	 g  |	 D] } | | j   k r'| ^ q'}
 t |
 d	 d
 j |
   g  |	 D]  } | | | | k	 rm| ^ qm} t | d d
 j |   d  S(   Nt   deprecated_originali    i   RB  i   R   i   RV  s   Estimator adds public attribute(s) during the fit method. Estimators are only allowed to add private attributes either started with _ or ended with _ but %s addeds   , s   Estimator changes public attribute(s) during the fit method. Estimators are only allowed to change attributes started or ended with _, but %s changed(   i   i   (   Rs   R  R"   R   R   R   RC  R  R  R-  R   R   RV  R   RY  R  R   R   R_  R   t   join(   Rw   R   Rx   RE  R   R   t   dict_before_fitt   dict_after_fitt   keyt   public_keys_after_fitt   attrs_added_by_fitt   attrs_changed_by_fit(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s:    "	c         C  s  t  j j d  } d | j d d  } t | |  } | d  d   d f j t  j  } t |  } t | |  } t	 | d  r d | _
 n  t	 | d  r d | _ n  t | d  | j | |  xL d d	 d
 d g D]8 } t	 | |  r t t d t | |  | d  q q Wd  S(   Ni    i   RB  i   R   i   RV  R   R   RX  R)  s   Reshape your data(   i   i   (   R   R   R   RC  R  R  R-  R"   R   Rs   R   RV  R   R   R   R   R  (   Rw   R   RE  R   R   Rx   RL  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s"    "	c         C  s   |  |  } | j  d } g  | D] } |  | j d |   ^ q  } t |  t k r{ | d } t t d   |   } n  t j |  r | j } g  | D] } | j ^ q } n  t	 j
 |  t	 j
 |  f S(   Ni   i    c         S  s   |  d S(   Ni    (    (   t   x(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   <lambda>  s    (   R0  RT  R   t   tuplet   listt   mapR   t   issparset   AR   t   ravel(   t   funcR   t   result_fullt
   n_featurest   batcht   result_by_batchRh  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   _apply_on_subsets  s    (
	c   
      C  sy  t  j j d  } d | j d d  } t | |  } | d  d   d f j t  j  } t |  } t | |  } t	 | d  r d | _
 n  t	 | d  r d | _ n  t | d  | j | |  x d d	 d
 d d g D] } d j d | d |   } |  | f d d d d g k r(t |   n  t	 | |  r t t | |  |  \ } }	 t | |	 d d d | q q Wd  S(   Ni    i   RB  i   R   i   RV  R   R   RX  t   score_samplesR)  s=   {method} of {name} is not invariant when applied to a subset.RL  Rw   t   SVCt	   SparsePCAt   MiniBatchSparsePCAt   BernoulliRBMt   atolgHz>RG  (   i   i   (   Rw  RX  (   Rx  R   (   Ry  R   (   Rz  Rv  (   R   R   R   RC  R  R  R-  R"   R   Rs   R   RV  R   R   R   R   Ru  R  R   (
   Rw   R   RE  R   R   Rx   RL  R9  Rq  Rt  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s4    "	c           s  t  j j d  } d | j d d  } | d  d   d f j t  j  } t |  } t | |  } t | d  r d | _	 n  t | d  r d | _
 n  t | d  d d	 d
 d d d g } y | j | |  Wn8 t k
 r  t   f d   | D  r   qn Xd  S(   Ni    i   RB  i   i
   R   RV  s   1 samples   n_samples = 1s   n_samples=1s
   one samples   1 classs	   one classc         3  s!   |  ] } | t     k Vq d  S(   N(   R2  (   t   .0R9  (   R   (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pys	   <genexpr>T  s    (   i   i
   (   R   R   R   RC  R  R-  R"   R   Rs   R   RV  R   R   R   t   all(   Rw   R   RE  R   R   Rx   t   msgs(    (   R   s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   <  s"    "c           sX  t  j j d  } d | j d d  } t | |  } | d  d   d f j t  j  } t |  } t | |  } t	 | d  r d | _
 n  t	 | d  r d | _ n  |  d k r d | _ n  |  d	 k r d
 | _ n  t | |  } t | d  d d d g } y | j | |  Wn8 t k
 rS  t   f d   | D  rT   qTn Xd  S(   Ni    i   RB  i
   i   R   RV  t   RandomizedLogisticRegressionRT   g      ?s   1 feature(s)s   n_features = 1s   n_features=1c         3  s!   |  ] } | t     k Vq d  S(   N(   R2  (   R|  R9  (   R   (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pys	   <genexpr>v  s    (   i
   i   (   R   R   R   RC  R  R  R-  R"   R   Rs   R   RV  t   sample_fractiont   residual_thresholdR   R   R   R}  (   Rw   R   RE  R   R   Rx   R~  (    (   R   s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   X  s,    "c         C  s   t  j j d  } d | j d d  } | j t  j  } t |  } t | |  } t | d  rp d | _	 n  t | d  r d | _
 n  t | d  t t | j | |  d  S(   Ni    i   RB  i   R   i   RV  (   R   R   R   RC  R  R-  R"   R   Rs   R   RV  R   R
   R   R   (   Rw   R   RE  R   R   Rx   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   z  s    c         C  s   t  d d d d d d g d d d g g d d d d d	 d
  \ } } t   j |  } | | j   8} | r t | | g  \ } } n  t |  | | |  t |  | | j   | j    d  S(   NR   i   t   centersi    i   R   Rr  i   t   cluster_stdg?(   R>   R;   R   R   R   t   _check_transformert   tolist(   Rw   R   Ra   R   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    *c         C  s   t  d d d d d d g d d d g g d d d d d	 d
  \ } } t   j |  } | | j   d
 8} t |  } t t j |   } t |  | | |  d  S(   NR   i   R  i    i   R   Rr  i   R  g?(   R>   R;   R   R   R   R   t   asarrayR  (   Rw   R   R   R   t   this_Xt   this_y(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    *c         C  sT   t    \ } } t |  } t t t f d d j |    | j |  Wd  QXd  S(   NR9  sw   The unfitted transformer {} does not raise an error when transform is called. Perhaps use check_is_fitted in transform.(   R   R"   R
   t   AttributeErrorR   R   R   (   Rw   R   R   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s
    c      	   C  s  |  d k r+ t  r+ |  d } t |   n  t j |  j \ } } t |  } t |  |  t k r t j | | f } | d  d  d  d f c d 9<n | } | j	 | |  t |  }	 |	 j
 | d | }
 t |
 t  rx9 |
 D] } t | j d |  q Wn t |
 j d |  t | d	  r|  t k ra| j | |  } | j
 | d | } n$ | j |  } | j
 | d | } t |
 t  rt | t  rx t |
 | |  D]I \ } } } t | | d
 d d d | t | | d
 d d d | qWn` t |
 | d d | d
 d t |
 | d
 d d d | t t |  |  t t |  |  t | d  rt t d d j |    | j | j  Wd  QXqn  d  S(   NRA   R   R   s%    is non deterministic on 32bit Pythoni   i   R   i    R   R{  g{Gz?RG  s9   fit_transform and transform outcomes not consistent in %ss7   consecutive fit_transform outcomes not consistent in %st   TR9  s   The transformer {} does not raise an error when the number of features in transform is different from the number of features in fit.(   RA   R   R   (   R   R   R   R  R0  R"   R   Rn   t   c_R   R   R   Rj  R   Rs   R   R   R   R9   R
   R   R   R  (   Rw   t   transformer_origR   R   R9  R   Rr  R   t   y_t   transformer_clonet   X_predt   x_predRN  t   X_pred3t   x_pred2t   x_pred3(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR    s^    

""	c         C  sb  |  d k r+ t  r+ |  d } t |   n  t d d d d d d g d	 d	 d	 g g d
 d d d d d  \ } } | | j   8} t | | d t } t |  } t | |  } t |  t	 |  } | j
 | |  | j
 | |  d d g } xi | D]a } t | | d   }	 |	 d  k	 r t | |  }
 |	 | |  } |
 | |  } t | |  q q Wd  S(   NRA   R   R   s%    is non deterministic on 32bit PythonR   i   R  i    i   R   Rr  i   R  g?R  t   scoreR   (   RA   R   R   (   R   R   R>   R   R  R3   R"   R   R   R/   R   R  R   R   (   Rw   R   R9  R   R   Rx   t   pipelinet   funcst	   func_nameRp  t   func_pipelinet   resultt   result_pipe(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRo      s*    
*
c         C  s8  t  j j d  } | j d d  } t | |  } t  j d  d } t |  } t | |  } t |  d d d d d	 g } x | D] } t	 | | d   } | d  k	 r | | |  g  t |  j j   D] }	 |	 j ^ q }
 |
 d d
 k r |
 d }
 n  t |
 d d k d | t |  j |
 f  q q Wd  S(   Ni    RB  i
   i   R   R  t   partial_fitR   R   R   i   R   t   YsJ   Expected y or Y as second argument for method %s of %s. Got arguments: %r.(   i
   i   (   R   R  (   R   R   R   RC  R  RD  R"   R   R   R  R   R7   t
   parameterst   valuesRw   R   R   R   (   Rw   R   RE  R   R   Rx   R  R  Rp  t   pt   args(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRe   "  s$    
+c         C  s0  t  j j d  } d | j d d  j t  j  } t | |  } | j t  j  } | j t  j  } | j t  j	  } | d  d   d f } t
 | |  } d d d d	 g } xy | | | | g D]e }	 t |  }
 t |
 d
  |
 j |	 |  x3 | D]+ } t |
 |  r t |
 |  |	  q q Wq Wd  S(   Ni    i   RB  i   i   R   R   RX  R)  i   (   i   i   (   R   R   R   RC  R  t   float32R  t   float64R  t   int32R   R"   R   R   Rs   R  (   Rw   R   RE  t
   X_train_32t
   X_train_64t   X_train_int_64t   X_train_int_32R   t   methodst   X_trainRx   RL  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRd   >  s     "c         C  s   t  |  } t | d  t j d  j d d  } t t d d j |    | j | g   Wd  QXt j d  j d d  } t	 | t j
 d d d g   } d } t t | | j | |  d  S(   Ni   i    i   R9  so   The estimator {} does not raise an error when an empty data is used to train. Perhaps use check_array in train.sE   0 feature\(s\) \(shape=\(3, 0\)\) while a minimum of \d* is required.(   R"   R   R   t   emptyRT  R
   R   R   R   R   R<  R   (   Rw   R   R   t   X_zero_samplest   X_zero_featuresR   R9  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRm   U  s    !c      
   C  sc  t  j j d  } t | j d d  |  } | j d d  } t  j | d <| j d d  } t  j | d <t  j d  } d | d *t | |  } d } d } d }	 x| | g D]}
 t	 d	 t
 t f  t |  } t | d
  y | j |
 |  Wn t k
 r`} d t |  k rd t |  k rt | | |  t j d t j  |  qnK t k
 r} t | | |  t j d t j  |  n Xt | |   | j | |  t | d  ry | j |
  Wn t k
 r@} d t |  k rd t |  k rt | | |  t j d t j  |  qqt k
 ru} t | | |  t j d t j  qXt | |   n  t | d  rUy | j |
  Wn t k
 r} d t |  k rRd t |  k rRt |	 | |  t j d t j  |  qRqUt k
 rB} t |	 | |  t j d t j  qUXt |	 |   n  Wd  QXq Wd  S(   Ni    RB  i
   i   i   s/   Estimator doesn't check for NaN and inf in fit.s3   Estimator doesn't check for NaN and inf in predict.s5   Estimator doesn't check for NaN and inf in transform.R   i   R   t   NaNt   fileR   R   (   i
   i   (   i
   i   (   i    i    (   i
   i   (   i    i    (   R   R   R   R  RC  t   nanR   RH  R   R   R.  R/  R"   R   R   R   R2  R4  t	   tracebackt	   print_exct   syst   stdoutR5  R  Rs   R   R   (   Rw   R   RE  t   X_train_finitet   X_train_nant   X_train_infR   t   error_string_fitt   error_string_predictt   error_string_transformR  Rx   R   t   exc(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRq   l  sl    	
$
$$c         C  s  d d d d g } t  d d d d d d g d	 d	 d	 g g d
 d d d d d  \ } } | | j   8} t | | d t } |  t k r t j j d  } | j | j	 d d t
 } t j | j d  | <n  t |  } t | |  } t |  | j | |  t   } x9 | D]1 }	 t | |	  rt | |	  |  | |	 <qqWt j |  }
 | j j d  r~d |
 k s~t  n  t j |
  } t   } x9 | D]1 }	 t | |	  rt | |	  |  | |	 <qqWx4 | D], }	 t | |	  |  } t | |	 |  qWd S(   s&   Test that we can pickle all estimatorsR   R   RX  R)  R   i   R  i    i   R   Rr  i   R  g?R  i*   i
   t   replaceis   sklearn.t   versionN(   R>   R   R  R3   Rp   R   R   R   t   choiceRB  R	  R  RT  R"   R   R   R   t   dictRs   R  t   picklet   dumpsR  R\  R  t   loadsR   (   Rw   R   t   check_methodsR   R   R   t   maskRx   R  RL  t   pickled_estimatort   unpickled_estimatort   unpickled_result(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRv     s:    		*
	 	 c      	   C  s   t  | d  s d  St |  } t d d d d  \ } } | | j   8} yH t |  r t j |  } | j | | d | n | j | |  Wn t k
 r d  SXt	 t
 d d j |   + | j | d  d   d  d	  f |  Wd  QXd  S(
   NR  R   i2   R   i   t   classesR9  sj   The estimator {} does not raise an error when the number of features changes between calls to partial_fit.i(   Rs   R"   R>   R   R%   R   t   uniqueR  t   NotImplementedErrorR
   R   R   (   Rw   R   Rx   R   R   R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s     	c      
   C  s  t  |  } t d d d d  \ } } t | | d d \ } } t   j |  } t j j d  } t j | | j	 d d d d	 d
 d  g  } | r t
 | | | g  \ } } } n  | j \ } }	 t | d  r | j d d	  n  t |  |  d k r$| j d d  | j d d  n  | j |  | j | j    | j }
 t |
 j | f  t t |
 |  d  |  d k rd  St |  t j d t   | j |  } Wd  QXt |
 |  t |
 j t j d  t j d  g  t | j t j d  t j d  g  | j |  } t j |  } t | t j | d | d d   | d d k snt  t | d  rt | d  } t  | d | d  n  d  S(   NR   i2   R   i   i   t   lowit   highi   RB  i   i   RV  t   AffinityPropagationt
   preferenceiR   id   g?t   SpectralClusteringt   recordR  R  i    i(   i   i   (   i    i(!   R"   R>   R6   R;   R   R   R   R   t   concatenateRC  R   R0  Rs   R   R   R   R  t   labels_R   R   R)   R   t   catch_warningsRk   R   R   R   R  R  RD  R  R  R   (   Rw   t   clusterer_origRa   R   R   R   R   t   X_noiseR   Rr  R7  t   pred2t   labelst   labels_sortedRV  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     sH    -!
	
((c         C  s   t  d d d d  \ } } t |  } t | d  r t | d  rX | j d d  n  | j |  j |  } | j d t  | j |  j |  } t | |  n  d S(   s1   Check that predict is invariant of compute_labelsR   i   R   i    t   compute_labelsN(   R>   R"   Rs   R   R   R   R	  R   (   Rw   R  R   R   R   RM  RN  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   ;  s    c      	   C  sj  d } d } t  j j d  } | j d d
  } | j d d  } t  j d  } t d t t f   t |  } y | j	 | |  Wn t
 k
 r }	 d t |	  k r t | | |	  t j d	 t j  |	  qd  Sn< t k
 r}
 t | | |
  t j d	 t j  |
  n Xy t | j |  |  Wn) t k
 r_}
 t | | |
  |
  n XWd  QXd  S(   Ns6   Classifier can't train when only one class is present.s8   Classifier can't predict when only one class is present.i    RB  i
   i   R   t   classR  (   i
   i   (   i
   i   (   R   R   R   RC  RH  R   R.  R/  R"   R   R   R2  R4  R  R  R  R  R5  R   R   (   Rw   t   classifier_origR  R  RE  R  t   X_testR   R   R   R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   L  s2    	
c         C  s   t  d d d d  \ } } t | | d d \ } } t   j |  } | | d k } | | d k } |  d k r | | j   8} | | j   8} n  | r t | | | | g  \ } } } } n  xU| | f | | f g D];\ } } t j |  }	 t |	  }
 | j	 \ } } t
 |  } t | |  } t |  t t d
 d j |    | j | | d   Wd  QX| j | |  | j | j   | j    t | d  st  | j |  } t | j	 | f  |  d k rt t | |  d  n  t |  r@t t d
 d j |    | j | j d d   Wd  QXn2 t t d
 d j |    | j | j  Wd  QXt | d  ry-| j |  } |
 d k rt | j	 | f  | j   d k j t j  } t | |  n  |
 d k r1t  | t!  r1t | j	 | |
 f  t t j" | d d |  n  t |  r{t t d
 d j |    | j | j d d   Wd  QXn2 t t d
 d j |    | j | j  Wd  QXWqt# k
 rqXn  t | d  r | j$ |  } t | j	 | |
 f  t t j" | d d |  t% t j& | d d t j' |   t |  rt t d
 d j |    | j$ | j d d   Wd  QXn2 t t d
 d j |    | j$ | j  Wd  QXt | d  r| j( |  } t% | t j) |  d d d t t j* |  t j* |   qq q Wd  S(    NR   i,  R   i    i   i   t   BernoulliNBRz   R{   R9  s   The classifier {} does not raise an error when incorrect/malformed input data for fit is passed. The number of training examples is not the same as the number of labels. Perhaps use check_X_y in fit.it   classes_g(\?sw   The classifier {} does not raise an error when shape of Xin predict is not equal to (n_test_samples,n_training_samples)i   s   The classifier {} does not raise an error when the number of features in predict is different from the number of features in fit.RX  i   t   axiss   The classifier {} does not raise an error when the  shape of X in decision_function is not equal to (n_test_samples, n_training_samples) in fit.s   The classifier {} does not raise an error when the number of features in decision_function is different from the number of features in fit.R)  s   The classifier {} does not raise an error when the shape of Xin predict_proba is not equal to (n_test_samples, n_training_samples).s   The classifier {} does not raise an error when the number of features in predict_proba is different from the number of features in fit.t   predict_log_probai   R{  g&.>(   R  Rz   R{   (   R  Rz   R{   (+   R>   R6   R;   R   R   R   R   R  RI  R0  R"   R  R   R
   R   R   R   R  Rs   R  R   R   R   R(   R
  RT  R  RX  Ro  R  R-  R   R   R-   t   argmaxR  R)  R   t   sumRH  R  t   logt   argsort(   Rw   R  Ra   t   X_mt   y_mt   y_bt   X_bR   R   R  t	   n_classesR   Rr  R   t   y_predt   decisiont   dec_predt   y_probt
   y_log_prob(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   n  s    '%
""%"c         C  s  t  d d d d  \ } } t | d d } | rB t |  } n  | j \ } } t |  } t |  | j |  | j | j    | j |  } | j | f k s t	  | j
 j d k s t	  t t j |  t j d d g   | j |  }	 |	 j
 t j
 d	  k st	  | j |  }
 |
 j
 t j
 d	  k sEt	  t t | j | j  | j |  }	 |	 j | f k st	  |	 d k j t j  } d | | d k <t | |  t t | j | j  | j |  } | j | f k st	  | | j } t | |	  t t | j | j  t | d
  rt | d  rd } | j d
 |  | j |  | j |  } t t j | d k  |  x: d d g D]) } | j d
 |  t t | j |  qWn  d  S(   NR   i,  R   i    i   t   iii   RF  t   contaminationt   noveltyg?g      gffffff@(   R>   R6   R   R0  R"   R   R   R  R   R  R  t   kindR   R   R  R<  RX  Rv  R
   R   R  R  R-  t   offset_R   Rs   R   R   t   mean(   Rw   R   Ra   R   R[  R   Rr  Rx   R  R  R  R  t   y_scorest   y_decR  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     sN    
%c         C  s   t  d d d d d d  \ } } | | j   8} t | |  } t |  } t | |  } | r| t | | g  \ } } n  t |  | j | |  | k s t  d S(   s*   Check if self is returned when calling fitR   i    R   i	   Rr  i   N(	   R>   R   R  R"   R   R   R   R   R  (   Rw   R   Ra   R   R   Rx   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRj   &  s    !
c         C  s   t    \ } } t |  } d } t | d  rO t t t f | | j |  n  t | d  r} t t t f | | j |  n  t | d  r t t t f | | j |  n  t | d  r t t t f | | j	 |  n  d S(   s  Check that predict raises an exception in an unfitted estimator.

    Unfitted estimators should raise either AttributeError or ValueError.
    The specific exception type NotFittedError inherits from both and can
    therefore be adequately raised for that purpose.
    R   R   RX  R)  R  N(
   R   R"   Rs   R   R  R   R   RX  R)  R  (   Rw   R   R   R   Rx   R9  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   9  s    
c      	   C  sz  d |  k r d  St  j j d  } t | j d d  |  } t  j d  d } t |  } t |  | j | |  | j	 |  } t |  t
 j d t  J } t
 j d t  t
 j d t  | j | | d  d   t  j f  Wd  QX| j	 |  } d	 d
 j g  | D] }	 t |	  ^ q }
 |  t k r]t t |  d |
  t d |
 k  n  t | j   | j    d  S(   Nt	   MultiTaski    RB  i
   i   R  t   alwayst   ignores)   expected 1 DataConversionWarning, got: %ss   , sP   DataConversionWarning('A column-vector y was passed when a 1d array was expected(   i
   i   (   R   R   R   R  RC  RD  R"   R   R   R   R   R  Rk   t   simplefilterR0   t   RuntimeWarningt   newaxisRa  R   t   MULTI_OUTPUTR   RI  R   R   Ro  (   Rw   R   RE  R   R   Rx   R  t   wt	   y_pred_2dt   w_xR9  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   Z  s,    

))c         C  s7  t  j |  } t |  } | d k r< |  |  j   k }  n  t |  | j |  |  | j |   } t | d  r| j |   } |  j	 \ } }	 t
 | t  j  s t  t |  d k r.| j   d k j t  j  }
 | j |
 } t | | d d | d j t t |   d j t t |   f qt | d d	  d	 k rt  j | d
 d j t  } | j | } t | | d d | d j t t |   d j t t |   f qn  | d k rt t  j |  t  j |   n  t | | j d d | d j t t |   d j t t | j   f d  S(   NR  RX  i   i    RG  sK   decision_function does not match classifier for %r: expected '%s', got '%s's   , R   t   ovrR  i   R{   s=   Unexpected classes_ attribute for %r: expected '%s', got '%s'(   R   R  R"   R  R   R   R   Rs   RX  R0  R   t   ndarrayR  RI  Ro  R  R-  R  R   Ra  Rl  R   R  R  (   R   R   Rw   R  R  R   R  R  R   Rr  R  t   dec_expt
   decision_yt   y_exp(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   check_classifiers_predictionsz  s>    
 #"c         C  s   |  d k r | S| S(   NR|   R}   (   R|   R}   (    (   Rw   R   t   y_names(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   choose_check_classifiers_labels  s    c         C  s  t  d d d d d d  \ } } t | | d d \ } } t   j |  } | | j   d 8} | | d k } | | d k } t | |  } t | |  } d	 d
 d g } d	 d
 g } t j | |  } t j | |  }	 xt | | | f | | |	 f g D]T \ }
 } } xB | | j d  g D]+ } t	 |  | |  } t
 |
 | |  |  q#Wq Wd d g } t j | |  }	 t	 |  | |	  } t
 | | |  |  d  S(   NR   i   R   i    R  g?i   i   t   onet   twot   threet   Oii   (   R>   R6   R;   R   R   R  R   t   takeR  R  R  (   Rw   R  t   X_multiclasst   y_multiclasst   X_binaryt   y_binaryt   labels_multiclasst   labels_binaryt   y_names_multiclasst   y_names_binaryR   R   R  t	   y_names_iR  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s.    c         C  sT  t    \ } } t | d  |  } t j j d  } | j d d | j d } t | |  } t j j d  } t |  } t |  } t	 |  t	 |  |  t
 k r t j | d | | j d d t |  g  } | j } n | } | j | |  | j |  }	 | j | | j t j   | j |  }
 t |	 |
 d d d |  d  S(	   Ni2   i    i   RB  i   R{  g{Gz?RG  (   R   R  R   R   R   t   randintR0  R   R"   R   Rn   t   vstackRI  R  R   R   R  RF  R   (   Rw   t   regressor_origR   R[  RE  R   t   regressor_1t   regressor_2R  t   pred1R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s&    

2c   	      C  s  t    \ } } t | |  } t   j | j d d   } | j   } t |  } t | |  } |  t k r t	 j
 j d  } t	 j | d | | j d d t |  g  } | j } n | } | r t | | | g  \ } } } n  t | d  rt | d  rd | _ n  |  d	 k r/d | _ n  t t d
 d j |    | j | | d   Wd  QXt |  | j | |  | j | j   | j    | j |  } t | j | j  |  d k rt | j | |  d  n  d  S(   Nii   i    i   RB  t   alphasR   g{Gz?t   PassiveAggressiveRegressorR9  s   The classifier {} does not raise an error when incorrect/malformed input data for fit is passed. The number of training examples is not the same as the number of labels. Perhaps use check_X_y in fit.R?   RA   RT   g      ?(   R?   RA   RT   (   R   R  R;   R   RT  Ro  R"   R   Rn   R   R   R   R  R  RI  R  R   Rs   R   t   CR
   R   R   R   R   R  R   R   R0  R   R  (	   Rw   R  Ra   R   R   R   RE  R  R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s6    2!
c   
      C  s   t  j j d  } | j d d
  } t |  } t | | d  d   d f  } t | d  rj d | _ n  | j | |  d d d	 g } xK | D]C } t	 | | d   } | d  k r q n  | }	 t t |	 | |  q Wd  S(   Ni    RB  i
   i   R   i   RX  R)  R  (   i
   i   (   R   R   R   t   normalR"   R   Rs   R   R   R  R   R   R.  (
   Rw   R  R   R   R   R   R  R  Rp  R9  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    c         C  s  |  d k r t  d   n  |  j d  r3 t   n  xd d g D]} t d | d d d	 d
  \ } } t | | d d d d \ } } } } t |  r t | |  } t | |  } n  t t j |   } | d k r i d d 6d d 6}	 n i d d 6d d 6d d 6}	 t	 |  j
 d |	  }
 t |
 d  rH|
 j
 d d  n  t |
 d  rj|
 j
 d d  n  t |
 d  r|
 j
 d d  n  t |
  |
 j | |  |
 j |  } t t j | d k  d  q@ Wd  S(   Nt   NuSVCs0   Not testing NuSVC class weight as it is ignored.t   NBi   i   R  R   i    R  i   t	   test_sizeg      ?i  g-C6?i   R   R   id   R   t   min_weight_fraction_leafg{Gz?gףp=
?(   R   R]  R>   R2   R
  R3   RI  R   R  R"   R   Rs   R   R   R   R   R  (   Rw   R  t	   n_centersR   R   R  R  t   y_traint   y_testR   R   R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   .  s6    	!	
c   
      C  s   t  |  } t | d  r. | j d d  n  t | d  rP | j d d  n  t |  | j | |  | j |  } | j d d  | j | |  | j |  }	 t t | |	 d d t | | d d  d  S(	   NR   id   R   i  R   t   balancedt   averaget   weighted(   R"   Rs   R   R   R   R   R   R*   (
   Rw   R  R  R%  R  R&  RA  R   R  t   y_pred_balanced(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt'   check_class_weight_balanced_classifiers[  s    
c   
      C  s  t  j d d g d d g d d g d d g d d g g  } t  j d d d d d g  } |   } t | d  r | j d d	  n  t | d
  r | j d
 d	  n  t |  | j d d  | j | |  j j   } t |  } t	 t t  j
 |    } i | t  j | d k  | d 6| t  j | d k  | d 6} | j d |  | j | |  j j   }	 t | |	  d S(   s4   Test class weights with non-contiguous class labels.g      i    gg      ?g        i   iR   i  R   R   R'  N(   R   R<  Rs   R   R   R   t   coef_R  RI  RF  R  R  R   (
   Rw   t
   ClassifierR   R   R   t   coef_balancedR   R  R   t   coef_manual(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt-   check_class_weight_balanced_linear_classifiero  s$    !	
!!c      	   C  s   t  d d d d  \ } } | | j   8} t | | d t } t |  } t | |  } t |  | j   } t |  } | j	 | |  | j   } xV | j
   D]H \ } }	 | | }
 t t j |
  t j |	  d |  | |	 |
 f  q Wd  S(   NR   i    R   i	   R  sT   Estimator %s should not change or mutate  the parameter %s from %s to %s during fit.(   R>   R   R  R3   R"   R   R   R   R   R   t   itemsR   R   t   hash(   Rw   R   R   R   Rx   R   t   original_paramst
   new_paramst
   param_namet   original_valuet	   new_value(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRr     s    

c         C  s0  t  t |  j d  r d St t |  j  } t rj x0 d g D]" } | | k rA | j |  qA qA Wn  g  d   t |  j D D] } | D] } | ^ q q } t t |   t |  t |  } t	 | d |  t
 |  f  t |  t t |   t d g  } t	 | d |  t
 |  f  d S(   s   Check setting during init. R`  Nt   objc         s  s   |  ] } t  |  Vq d  S(   N(   R   (   R|  t   parent(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pys	   <genexpr>  s    sa   Estimator %s should not set any attribute apart from parameters during init. Found attributes %s.R   sa   Estimator %s should store all parameters as an attribute during init. Did not find attributes %s.(   Rs   R   R  R   R   t   removet   __mro__t   sett   varsR   t   sorted(   Rw   Rx   t   init_paramsRd  t   params_parentt   paramt   parents_init_paramst   invalid_attr(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s&    &)c         C  s:  t  j d d g d d g d d g d d g d d g d d g d d g d d g d d g g	  } d d d d d d d d d g	 } t |  } | j | |  | j |  } | j   t j | j  s t	  | j |  } t
 | |  t j t j |   } t j | j  st	  | j |  } t
 | |  d  S(   Niii   i   i   (   R   R<  R"   R   R   Rc   R   Rm  R,  R  R   R  R  R  (   Rw   R   R   R   t   estt	   pred_origR7  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRt     s    <$!
c         C  s   t  j d d g d d g d d g d d g d d g d d g g  } t | |  } d d d d d d g } t | |  } t |  | | |  d  S(   Ni   i    i   i   (   R   R<  R  R   t"   check_estimators_data_not_an_array(   Rw   R   R   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s
    Ec         C  sJ   t  d d  \ } } t | |  } t | |  } t |  | | |  d  S(   NR   i2   (   R   R  R   RF  (   Rw   R   R   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    c   
      C  s   |  t  k r t d   n  t |  } t |  } t |  t |  t t j |   } t t j |   } | j | |  | j |  } | j | |  | j |  }	 t	 | |	 d d d |  d  S(   Nso   Skipping check_estimators_data_not_an_array for cross decomposition module as estimators are not deterministic.R{  g{Gz?RG  (
   Rn   R   R"   R   R   R   R  R   R   R   (
   Rw   R   R   R   t   estimator_1t   estimator_2R  t   X_R  R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyRF    s    

c         C  s]  t    } t d t t f  9|  t k r: | |  } n	 |   } t |  t |  | j   | k so t  t	 | j
 d | j
  } yA d   } g  t |  j j   D] } | |  r | ^ q } Wn t t f k
 r d  SX| j   } |  t k r| d } n  xH| D]@}	 t |	 j |	 j d |	 j t |  j f  t t |	 j  t t t t t t d   t j t  j! t" g	  |	 j | j#   k r|	 j d  k st  qn  t$ | t%  r|	 j d k rqn  | |	 j }
 t& |
 t j'  rt( |
 |	 j  qt) |
  r1|
 |	 j k sOt |	 j   q|
 |	 j k st |	 j   qWWd  QXd  S(	   NR   R`  c         S  s1   |  j  d k o0 |  j |  j k o0 |  j |  j k S(   s)   Identify hyper parameters of an estimatorR   (   Rw   R  t   VAR_KEYWORDt   VAR_POSITIONAL(   R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   param_filter0  s    i   s(   parameter %s for %s has no default valuet   tolR   (   RM  R   (*   R!   R   R.  R/  R   R"   R2  R   R  R  R  R7   R  R  R1  R   R   R   t   defaultR  Rw   R   R   R   R   R-  RF  R  Rj  R   R   R  t   typest   FunctionTypeR	   R   t
   issubclassR.   R   R  R   R    (   Rw   R   R   Rx   t   initRL  R  R?  R   t
   init_paramt   param_value(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     sL    		

	!c         C  s&   d |  j  j k r" t j | d  S| S(   NR  ii   (   ii   (   R   R   R   RT  (   Rx   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   _  s    c      
   C  s   d d d d d d d d d	 d
 g
 } | t  7} |  | k r> d  S|  d k re t |  j d d  } n t |  } t | d  r t   } | j | j } } t | |  } t | d  |  d k r | j	 |  n | j	 | |  | j
 d k s t  n  d  S(   NRW   t   SVRt   NuSVRR   t   RidgeClassifierRw  R   R   R   t   LogisticRegressionRM   R   g        R   i    R  i   (   Rn   R"   R   Rs   R<   R   R   R   R   R   t   n_iter_R  (   Rw   R   t   not_run_check_n_iterRx   t   irisR   R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   g  s&    		
	c         C  sG  t  |  } t | d  rC|  t k r d d d g d d d g d d d g d d d g g } d d g d	 d
 g d d g d d g g } nY t d d d d d d g d d d g g d d d d d d  \ } } | | j   d 8} t | d  | j | |  |  t k r0x1 | j D] } t | d  qWqCt | j d  n  d  S(   NR   g        g      ?g       @g      @g      @g?gɿg?g?g      g333333?R   i   R  i    i   R   Rr  i   R  (	   R"   Rs   Rn   R>   R   R   R   RY  R   (   Rw   R   Rx   R   R  t   iter_(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    6-*c           sp   d t  f d     Y} t |  } | j d t  } | j d t    t t   f d   | j   D   d  S(   NR  c           B  s)   e  Z d  Z d   Z d   Z d   Z RS(   s   Mock classifier
        c         S  s   d  S(   N(    (   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR    s    c         S  s   |  S(   N(    (   R   R   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    c         S  s   | S(   N(    (   R   R   (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    (   R   R  R  R  R   R   (    (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR    s   		t   deepc         3  s!   |  ] } |   j    k Vq d  S(   N(   R1  (   R|  t   item(   t   deep_params(    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pys	   <genexpr>  s    (   R$   R"   R   R	  Rk   R   R}  R1  (   Rw   R   R  R   t   shallow_params(    (   R_  s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    c         C  sv  t  |  } | j d t  } d } | j |   | j d t  } t t | j    t | j    |  x6 | j   D]( \ } } | | | k sx t |   qx Wt	 j
 t	 j
 d  g } t |  }	 x| j   D]}
 | |
 } x~| D]v} | |	 |
 <y | j |	   Wn t t f k
 r} | j j } t j d j |   d j |  } | } | j d t  } y\ t t | j    t | j     x0 | j   D]" \ } } | | | k st  qWWq`t k
 rt j |  q`Xq X| j d t  } t t |	 j    t | j    |  x6 | j   D]( \ } } |	 | | k s4t |   q4Wq W| |	 |
 <q Wd  S(   NR]  s>   get_params result does not match what was passed to set_paramssY   {} occurred during set_params. It is recommended to delay parameter validation until fit.s9   Estimator's parameters changed after set_params raised {}(   R"   R   R	  R   R   R<  R   R1  R  R   R   R   R   R1  R   R   R   R   R   R   (   Rw   R   Rx   t   orig_paramsR9  t   curr_paramsR   t   vt   test_valuest   test_paramsR5  t   default_valuet   valueR   t   e_typet   change_warning_msgt   params_before_exception(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     sL    ( 


	$c         C  sK   t    } | j | j } } t |  } d } t t | | j | |  d  S(   Ns   Unknown label type: (   R=   R   R   R"   R   R   R   (   Rw   R   R   R   R   R   R9  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s
    	c   	      C  s   d d g } t  d d d d d d d | d	 d
 d t  \ } } t j j d d  d } t |  } t | d  r t | d  r | j | |  | j |  d  d   d f } | j	 |  } t
 t |  t |   n  d  S(   Ni   i   R   id   R   i    Rr  R  R  g      ?R6   i   RX  R)  i   (   i   i   (   i   i   (   R>   Rk   R   R   R   R"   Rs   R   R)  RX  R   R   (	   Rw   R   R  R   R   R  Rx   t   at   b(    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR     s    c   
      C  s~  t  d d d d  \ } } t | d d } | j \ } } t |  } t |  | j |  } | j | f k sy t  | j j d k s t  t	 t
 j |  t
 j d d g   t | d	  r | j |  j |  } t	 | |  n  t | d
  rzd }	 | j d
 |	  | j |  } t t
 j | d k  |	  x: d d g D]) }	 | j d
 |	  t t | j |  qJWn  d  S(   NR   i,  R   i    i   R  ii   R   R  g?g      gffffff@(   R>   R6   R0  R"   R   R   R  R  R  R   R   R  R<  Rs   R   R   R   R   R  R
   R   (
   Rw   R   R   R[  R   Rr  Rx   R  t   y_pred_2R  (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyR   	  s(    
%(   t
   __future__R    RO  R   R  R  R  R  R   t	   functoolsR   t   numpyR   t   scipyR   t   scipy.statsR   t   sklearn.externals.six.movesR   t   sklearn.utilsR   R   R   t   sklearn.utils._joblibR	   t   sklearn.utils.testingR
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R    t   sklearn.discriminant_analysisR!   t   sklearn.baseR"   R#   R$   R%   R&   R'   t   sklearn.metricsR(   R)   R*   t   sklearn.random_projectionR+   t   sklearn.feature_selectionR,   t   sklearn.svm.baseR-   t(   sklearn.linear_model.stochastic_gradientR.   t   sklearn.pipelineR/   t   sklearn.exceptionsR0   R1   t   sklearn.model_selectionR2   t   sklearn.metrics.pairwiseR3   R4   R5   R6   t   sklearn.utils.fixesR7   t   sklearn.utils.validationR8   R9   R:   t   sklearn.preprocessingR;   t   sklearn.datasetsR<   R=   R>   R   R   Rn   R  Rp   RR  Ry   R   R.  R/  R   R   R   R   R   R   R   R   R   RQ  R   R
  R  R  R&  Ru   Rg   Rh   Ri   t   UserWarningRf   Rl   R   R_  R   R   Ru  R   R   R   R   R	  R   R   R   R  Ro   Re   Rd   Rm   Rq   Rv   R   R   R   R   R   Rk   R   Rj   R   R   R  R  R   R   R   R   R   R+  R0  Rr   R   Rt   R   R   RF  R   R   R   R   R   R   R   R   R   (    (    (    s=   lib/python2.7/site-packages/sklearn/utils/estimator_checks.pyt   <module>   s&  .						%							'	D		
	"	1"!#	
(	3	&"	M"G1<"sD! -		",-"#"		J	$5