ó
‡ˆ\c           @   sJ  d  Z  d d l Z d d l Z d d l Z d d l j 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 e j e j e j f Z  e j! d e ƒ e e
 ƒ d k Z" e# d „ Z$ e# d „ Z% e& e& d „ Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ e# e& d d e# e& e& e# d d e# d d „ Z1 e# d „ Z2 e# e& d d e# e& e& e# e# d d e# e# d d „ Z3 e# d  „ Z4 d! „  Z5 d" „  Z6 d# e& e# d$ „ Z7 d e8 d% „ Z9 d& „  Z: d S('   s   Utilities for input validationiÿÿÿÿN(   t   __version__(   t   LooseVersion(   t   ComplexWarningi   (   t   sixi   (   t	   signature(   t
   get_config(   t   NonBLASDotWarning(   t   NotFittedError(   t   DataConversionWarning(   t   Memoryt   ignores   0.14.0c         C   sË   t  ƒ  d r d St j |  ƒ }  |  j j d k } | rP t j |  j ƒ  ƒ rP nw | rÇ d } | rw t j |  ƒ j ƒ  s” | rÇ t j |  ƒ j	 ƒ  rÇ | r  d n d } t
 | j | |  j ƒ ƒ ‚ qÇ n  d S(   s-   Like assert_all_finite, but only for ndarray.t   assume_finiteNt   fcs0   Input contains {} or a value too large for {!r}.t   infinitys   NaN, infinity(   t   _get_configt   npt
   asanyarrayt   dtypet   kindt   isfinitet   sumt   isinft   anyt   allt
   ValueErrort   format(   t   Xt	   allow_nant   is_floatt   msg_errt   type_err(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   _assert_all_finite(   s    c         C   s)   t  t j |  ƒ r |  j n |  | ƒ d S(   sŠ   Throw a ValueError if X contains NaN or infinity.

    Parameters
    ----------
    X : array or sparse matrix

    allow_nan : bool
    N(   R   t   spt   issparset   data(   R   R   (    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   assert_all_finite;   s    	c         C   s3  t  |  t j ƒ s5 t  |  t j ƒ rf t j |  ƒ rf t |  d d d g d t j d | d | d t ƒSt j |  ƒ r¤ |  j	 t j
 t j g k r¤ | r  |  j ƒ  S|  S|  j	 t j
 t j g k ré | rå |  j |  j d rÞ d	 n d
 ƒ S|  S|  j	 j d k r|  j	 j d k rt j
 } n	 t j } |  j | ƒ Sd S(   së  Converts an array-like to an array of floats.

    The new dtype will be np.float32 or np.float64, depending on the original
    type. The function can create a copy or modify the argument depending
    on the argument copy.

    Parameters
    ----------
    X : {array-like, sparse matrix}

    copy : bool, optional
        If True, a copy of X will be created. If False, a copy may still be
        returned if X's dtype is not a floating point type.

    force_all_finite : boolean or 'allow-nan', (default=True)
        Whether to raise an error on np.inf and np.nan in X. The possibilities
        are:

        - True: Force all values of X to be finite.
        - False: accept both np.inf and np.nan in X.
        - 'allow-nan': accept only np.nan values in X. Values cannot be
          infinite.

        .. versionadded:: 0.20
           ``force_all_finite`` accepts the string ``'allow-nan'``.

    Returns
    -------
    XT : {array, sparse matrix}
        An array of type np.float
    t   csrt   csct   cooR   t   copyt   force_all_finitet	   ensure_2dt   F_CONTIGUOUSt   Ft   Ct   uibi   N(   t
   isinstanceR   t   matrixt   ndarrayR    R!   t   check_arrayt   float64t   FalseR   t   float32R'   t   flagsR   t   itemsizet   astype(   R   R'   R(   t   return_dtype(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   as_float_arrayG   s     %**$	c         C   s+   t  |  d ƒ p* t  |  d ƒ p* t  |  d ƒ S(   s'   Returns whether the input is array-liket   __len__t   shapet	   __array__(   t   hasattr(   t   x(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   _is_arraylikex   s    c         C   s  t  |  d ƒ r1 t |  j ƒ r1 t d |  ƒ ‚ n  t  |  d ƒ r‹ t  |  d ƒ r‹ t  |  d ƒ rr t j |  ƒ }  q‹ t d t |  ƒ ƒ ‚ n  t  |  d ƒ ró t |  j ƒ d k rÂ t d |  ƒ ‚ n  t	 |  j d t
 j ƒ ræ |  j d St |  ƒ Sn
 t |  ƒ Sd	 S(
   s)   Return number of samples in array-like x.t   fits1   Expected sequence or array-like, got estimator %sR:   R;   R<   s'   Expected sequence or array-like, got %si    s;   Singleton array %r cannot be considered a valid collection.N(   R=   t   callableR@   t	   TypeErrorR   t   asarrayt   typet   lenR;   R.   t   numberst   Integral(   R>   (    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   _num_samples   s      c         C   sV   t  |  ƒ d k r d Sd j d „  |  Dƒ ƒ } t  |  ƒ d k rN | d 7} n  d | S(   ss  Return a platform independent representation of an array shape

    Under Python 2, the `long` type introduces an 'L' suffix when using the
    default %r format for tuples of integers (typically used to store the shape
    of an array).

    Under Windows 64 bit (and Python 2), the `long` type is used by default
    in numpy shapes even when the integer dimensions are well below 32 bit.
    The platform specific type causes string messages or doctests to change
    from one platform to another which is not desirable.

    Under Python 3, there is no more `long` type so the `L` suffix is never
    introduced in string representation.

    >>> _shape_repr((1, 2))
    '(1, 2)'
    >>> one = 2 ** 64 / 2 ** 64  # force an upcast to `long` under Python 2
    >>> _shape_repr((one, 2 * one))
    '(1, 2)'
    >>> _shape_repr((1,))
    '(1,)'
    >>> _shape_repr(())
    '()'
    i    s   ()s   , c         s   s   |  ] } d  | Vq d S(   s   %dN(    (   t   .0t   e(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pys	   <genexpr>´   s    i   t   ,s   (%s)(   RE   t   join(   R;   t   joined(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   _shape_repr™   s    c         C   s‹   |  d k s t |  t j ƒ r` t t ƒ d k  rH t d |  d d ƒ }  q‡ t d |  d d ƒ }  n' t |  d ƒ s‡ t d j	 |  ƒ ƒ ‚ n  |  S(	   sü  Check that ``memory`` is joblib.Memory-like.

    joblib.Memory-like means that ``memory`` can be converted into a
    joblib.Memory instance (typically a str denoting the ``location``)
    or has the same interface (has a ``cache`` method).

    Parameters
    ----------
    memory : None, str or object with the joblib.Memory interface

    Returns
    -------
    memory : object with the joblib.Memory interface

    Raises
    ------
    ValueError
        If ``memory`` is not joblib.Memory-like.
    s   0.12t   cachedirt   verbosei    t   locationt   cachesg   'memory' should be None, a string or have the same interface as joblib.Memory. Got memory='{}' instead.N(
   t   NoneR.   R   t   string_typesR   t   joblib_versionR	   R=   R   R   (   t   memory(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   check_memory»   s    	c          G   s|   g  |  D] } | d k	 r t | ƒ ^ q } t j | ƒ } t | ƒ d k rx t d g  | D] } t | ƒ ^ qY ƒ ‚ n  d S(   s  Check that all arrays have consistent first dimensions.

    Checks whether all objects in arrays have the same shape or length.

    Parameters
    ----------
    *arrays : list or tuple of input objects.
        Objects that will be checked for consistent length.
    i   s>   Found input variables with inconsistent numbers of samples: %rN(   RS   RH   R   t   uniqueRE   R   t   int(   t   arraysR   t   lengthst   uniquest   l(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   check_consistent_lengthÜ   s
    +c          G   sª   g  } x“ |  D]‹ } t  j | ƒ r8 | j | j ƒ  ƒ q t | d ƒ sV t | d ƒ rf | j | ƒ q | d k r‚ | j | ƒ q | j t j | ƒ ƒ q Wt | Œ  | S(   sw  Make arrays indexable for cross-validation.

    Checks consistent length, passes through None, and ensures that everything
    can be indexed by converting sparse matrices to csr and converting
    non-interable objects to arrays.

    Parameters
    ----------
    *iterables : lists, dataframes, arrays, sparse matrices
        List of objects to ensure sliceability.
    t   __getitem__t   ilocN(	   R    R!   t   appendt   tocsrR=   RS   R   t   arrayR^   (   t	   iterablest   resultR   (    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt	   indexableî   s    
c         C   su  | d	 k r |  j } n  t } t | t j ƒ r< | g } n  t |  | ƒ | t k rd t d ƒ ‚ nˆ t | t t	 f ƒ rÈ t
 | ƒ d k rš t d ƒ ‚ n  |  j | k rì |  j | d ƒ }  t } qì n$ | t k	 rì t d j | ƒ ƒ ‚ n  | |  j k r|  j | ƒ }  n | r)| r)|  j ƒ  }  n  | rqt |  d ƒ sUt j d |  j ƒ qqt |  j d | d k ƒn  |  S(
   s®  Convert a sparse matrix to a given format.

    Checks the sparse format of spmatrix and converts if necessary.

    Parameters
    ----------
    spmatrix : scipy sparse matrix
        Input to validate and convert.

    accept_sparse : string, boolean or list/tuple of strings
        String[s] representing allowed sparse matrix formats ('csc',
        'csr', 'coo', 'dok', 'bsr', 'lil', 'dia'). If the input is sparse but
        not in the allowed format, it will be converted to the first listed
        format. True allows the input to be any format. False means
        that a sparse matrix input will raise an error.

    dtype : string, type or None
        Data type of result. If None, the dtype of the input is preserved.

    copy : boolean
        Whether a forced copy will be triggered. If copy=False, a copy might
        be triggered by a conversion.

    force_all_finite : boolean or 'allow-nan', (default=True)
        Whether to raise an error on np.inf and np.nan in X. The possibilities
        are:

        - True: Force all values of X to be finite.
        - False: accept both np.inf and np.nan in X.
        - 'allow-nan': accept only np.nan values in X. Values cannot be
          infinite.

        .. versionadded:: 0.20
           ``force_all_finite`` accepts the string ``'allow-nan'``.

    Returns
    -------
    spmatrix_converted : scipy sparse matrix.
        Matrix that is ensured to have an allowed type.
    sj   A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.i    s]   When providing 'accept_sparse' as a tuple or list, it must contain at least one string value.sj   Parameter 'accept_sparse' should be a string, boolean or list of strings. You provided 'accept_sparse={}'.R"   s,   Can't check %s sparse matrix for nan or inf.R   s	   allow-nanN(   RS   R   R3   R.   R   RT   t   _check_large_sparseRB   t   listt   tupleRE   R   R   t   asformatt   TrueR7   R'   R=   t   warningst   warnR   R"   (   t   spmatrixt   accept_sparseR   R'   R(   t   accept_large_sparset   changed_format(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   _ensure_sparse_format  s8    *		c         C   s^   t  |  d ƒ rZ |  j d  k	 rZ t  |  j d ƒ rZ |  j j d k rZ t d j |  ƒ ƒ ‚ n  d  S(   NR   R   t   cs   Complex data not supported
{}
(   R=   R   RS   R   R   R   (   Rc   (    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   _ensure_no_complex_datac  s    $	t   numericc         C   s  | d k r% t j d t ƒ t } n  |  } t | t j ƒ oF | d k } t |  d d ƒ } t	 | d ƒ ss d } n  d } t	 |  d ƒ r¯ t	 |  j
 d ƒ r¯ t j |  j
 ƒ } n  | rå | d k	 rÜ | j d k rÜ t j } qå d } n  t | t t f ƒ r(| d k	 r| | k rd } q(| d } n  | t t d	 f k rUt d
 j | ƒ ƒ ‚ n  | d k	 r‹t | t j ƒ r|| } q‘| j j } n d } | d k	 r§d | n d } t j |  ƒ rót |  ƒ t |  d | d | d | d | d | ƒ}  n{t j ƒ  ] y/ t j d t ƒ t j |  d | d | ƒ}  Wn& t k
 rWt d j |  ƒ ƒ ‚ n XWd QXt |  ƒ | r¿|  j d k r•t d j |  ƒ ƒ ‚ n  |  j d k r¿t d j |  ƒ ƒ ‚ q¿n  | rðt j |  j  t j! ƒ rðt j d t" ƒ n  | r|  j  j d k r|  j# t j ƒ }  n  | rO|  j d k rOt d |  j | f ƒ ‚ n  | rnt$ |  d | d	 k ƒn  t% |  j& ƒ } |	 d k rÃt' |  ƒ } | |	 k  rÃt d | | |	 | f ƒ ‚ qÃn  |
 d k r|  j d k r|  j& d } | |
 k  rt d | | |
 | f ƒ ‚ qn  | rc| d k	 rc|  j  | k rcd  | |  j  | f } t j | t( ƒ n  | r™t j) |  | ƒ r™t j |  d | d | ƒ}  n  | r| d k	 r|  j  h t* | ƒ k rd! d" j+ t, t- t. t* | ƒ ƒ ƒ ƒ |  j  | f } t j | t( d# d ƒn  |  S($   s«  Input validation on an array, list, sparse matrix or similar.

    By default, the input is checked to be a non-empty 2D array containing
    only finite values. If the dtype of the array is object, attempt
    converting to float, raising on failure.

    Parameters
    ----------
    array : object
        Input object to check / convert.

    accept_sparse : string, boolean or list/tuple of strings (default=False)
        String[s] representing allowed sparse matrix formats, such as 'csc',
        'csr', etc. If the input is sparse but not in the allowed format,
        it will be converted to the first listed format. True allows the input
        to be any format. False means that a sparse matrix input will
        raise an error.

        .. deprecated:: 0.19
           Passing 'None' to parameter ``accept_sparse`` in methods is
           deprecated in version 0.19 "and will be removed in 0.21. Use
           ``accept_sparse=False`` instead.

    accept_large_sparse : bool (default=True)
        If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by
        accept_sparse, accept_large_sparse=False will cause it to be accepted
        only if its indices are stored with a 32-bit dtype.

        .. versionadded:: 0.20

    dtype : string, type, list of types or None (default="numeric")
        Data type of result. If None, the dtype of the input is preserved.
        If "numeric", dtype is preserved unless array.dtype is object.
        If dtype is a list of types, conversion on the first type is only
        performed if the dtype of the input is not in the list.

    order : 'F', 'C' or None (default=None)
        Whether an array will be forced to be fortran or c-style.
        When order is None (default), then if copy=False, nothing is ensured
        about the memory layout of the output array; otherwise (copy=True)
        the memory layout of the returned array is kept as close as possible
        to the original array.

    copy : boolean (default=False)
        Whether a forced copy will be triggered. If copy=False, a copy might
        be triggered by a conversion.

    force_all_finite : boolean or 'allow-nan', (default=True)
        Whether to raise an error on np.inf and np.nan in array. The
        possibilities are:

        - True: Force all values of array to be finite.
        - False: accept both np.inf and np.nan in array.
        - 'allow-nan': accept only np.nan values in array. Values cannot
          be infinite.

        .. versionadded:: 0.20
           ``force_all_finite`` accepts the string ``'allow-nan'``.

    ensure_2d : boolean (default=True)
        Whether to raise a value error if array is not 2D.

    allow_nd : boolean (default=False)
        Whether to allow array.ndim > 2.

    ensure_min_samples : int (default=1)
        Make sure that the array has a minimum number of samples in its first
        axis (rows for a 2D array). Setting to 0 disables this check.

    ensure_min_features : int (default=1)
        Make sure that the 2D array has some minimum number of features
        (columns). The default value of 1 rejects empty datasets.
        This check is only enforced when the input data has effectively 2
        dimensions or is originally 1D and ``ensure_2d`` is True. Setting to 0
        disables this check.

    warn_on_dtype : boolean (default=False)
        Raise DataConversionWarning if the dtype of the input data structure
        does not match the requested dtype, causing a memory copy.

    estimator : str or estimator instance (default=None)
        If passed, include the name of the estimator in warning messages.

    Returns
    -------
    array_converted : object
        The converted and validated array.

    s¯   Passing 'None' to parameter 'accept_sparse' in methods check_array and check_X_y is deprecated in version 0.19 and will be removed in 0.21. Use 'accept_sparse=False'  instead.Ru   R   R   t   dtypesR<   t   Oi    s	   allow-nansB   force_all_finite should be a bool or "allow-nan". Got {!r} insteadt	   Estimators    by %st    Ro   R'   R(   Rp   t   errort   orders   Complex data not supported
{}
NsÄ   Expected 2D array, got scalar array instead:
array={}.
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.i   sÀ   Expected 2D array, got 1D array instead:
array={}.
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.s  Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).i   s*   Found array with dim %d. %s expected <= 2.R   sM   Found array with %d sample(s) (shape=%s) while a minimum of %d is required%s.i   sN   Found array with %d feature(s) (shape=%s) while a minimum of %d is required%s.s/   Data with input dtype %s was converted to %s%s.s4   Data with input dtype %s were all converted to %s%s.s   , t
   stacklevel(/   RS   Rl   Rm   t   DeprecationWarningR3   R.   R   RT   t   getattrR=   Rv   R   Rc   R   R2   Rh   Ri   Rk   R   R   t	   __class__t   __name__R    R!   Rt   Rr   t   catch_warningst   simplefilterR   RC   t   ndimt
   issubdtypeR   t   flexiblet   FutureWarningR7   R   RN   R;   RH   R   t   may_share_memoryt   setRL   t   mapt   strt   sorted(   Rc   Ro   Rp   R   R{   R'   R(   R)   t   allow_ndt   ensure_min_samplest   ensure_min_featurest   warn_on_dtypet	   estimatort
   array_origt   dtype_numerict
   dtype_origt   dtypes_origt   estimator_namet   contextt
   shape_reprt	   n_samplest
   n_featurest   msg(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyR1   j  s¶    _		!				
	

			!'
c         C   s½   | o	 t  s¹ d g } |  j ƒ  d k r6 d d g } n% |  j ƒ  d k rW d d	 g } n d
 Sx[ | D]P } t |  | ƒ j } | | k rb t  sŸ t d t ƒ ‚ n  t d | ƒ ‚ qb qb Wn  d
 S(   sL   Raise a ValueError if X has 64bit indices and accept_large_sparse=False
    t   int32R&   t   colt   rowR$   R%   t   bsrt   indicest   indptrNs]   Scipy version %s does not support large indices, please upgrade your scipy to 0.14.0 or abovesN   Only sparse matrices with 32-bit integer indices are accepted. Got %s indices.(   R$   R%   Rž   (   t   LARGE_SPARSE_SUPPORTEDt	   getformatR~   R   R   t   scipy_version(   R   Rp   t   supported_indicest
   index_keyst   keyt   indices_datatype(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyRg   e  s    	c         C   sù   | d k r t d ƒ ‚ n  t |  d | d | d | d | d | d | d | d	 |	 d
 | d | d | d | ƒ}  |
 r™ t | d d t d t d d ƒ} n t | d t ƒ} t | ƒ | râ | j j d k râ | j	 t
 j ƒ } n  t |  | ƒ |  | f S(   s”  Input validation for standard estimators.

    Checks X and y for consistent length, enforces X to be 2D and y 1D. By
    default, X is checked to be non-empty and containing only finite values.
    Standard input checks are also applied to y, such as checking that y
    does not have np.nan or np.inf targets. For multi-label y, set
    multi_output=True to allow 2D and sparse y. If the dtype of X is
    object, attempt converting to float, raising on failure.

    Parameters
    ----------
    X : nd-array, list or sparse matrix
        Input data.

    y : nd-array, list or sparse matrix
        Labels.

    accept_sparse : string, boolean or list of string (default=False)
        String[s] representing allowed sparse matrix formats, such as 'csc',
        'csr', etc. If the input is sparse but not in the allowed format,
        it will be converted to the first listed format. True allows the input
        to be any format. False means that a sparse matrix input will
        raise an error.

        .. deprecated:: 0.19
           Passing 'None' to parameter ``accept_sparse`` in methods is
           deprecated in version 0.19 "and will be removed in 0.21. Use
           ``accept_sparse=False`` instead.

    accept_large_sparse : bool (default=True)
        If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by
        accept_sparse, accept_large_sparse will cause it to be accepted only
        if its indices are stored with a 32-bit dtype.

        .. versionadded:: 0.20

    dtype : string, type, list of types or None (default="numeric")
        Data type of result. If None, the dtype of the input is preserved.
        If "numeric", dtype is preserved unless array.dtype is object.
        If dtype is a list of types, conversion on the first type is only
        performed if the dtype of the input is not in the list.

    order : 'F', 'C' or None (default=None)
        Whether an array will be forced to be fortran or c-style.

    copy : boolean (default=False)
        Whether a forced copy will be triggered. If copy=False, a copy might
        be triggered by a conversion.

    force_all_finite : boolean or 'allow-nan', (default=True)
        Whether to raise an error on np.inf and np.nan in X. This parameter
        does not influence whether y can have np.inf or np.nan values.
        The possibilities are:

        - True: Force all values of X to be finite.
        - False: accept both np.inf and np.nan in X.
        - 'allow-nan': accept only np.nan values in X. Values cannot be
          infinite.

        .. versionadded:: 0.20
           ``force_all_finite`` accepts the string ``'allow-nan'``.

    ensure_2d : boolean (default=True)
        Whether to raise a value error if X is not 2D.

    allow_nd : boolean (default=False)
        Whether to allow X.ndim > 2.

    multi_output : boolean (default=False)
        Whether to allow 2D y (array or sparse matrix). If false, y will be
        validated as a vector. y cannot have np.nan or np.inf values if
        multi_output=True.

    ensure_min_samples : int (default=1)
        Make sure that X has a minimum number of samples in its first
        axis (rows for a 2D array).

    ensure_min_features : int (default=1)
        Make sure that the 2D array has some minimum number of features
        (columns). The default value of 1 rejects empty datasets.
        This check is only enforced when X has effectively 2 dimensions or
        is originally 1D and ``ensure_2d`` is True. Setting to 0 disables
        this check.

    y_numeric : boolean (default=False)
        Whether to ensure that y has a numeric type. If dtype of y is object,
        it is converted to float64. Should only be used for regression
        algorithms.

    warn_on_dtype : boolean (default=False)
        Raise DataConversionWarning if the dtype of the input data structure
        does not match the requested dtype, causing a memory copy.

    estimator : str or estimator instance (default=None)
        If passed, include the name of the estimator in warning messages.

    Returns
    -------
    X_converted : object
        The converted and validated X.

    y_converted : object
        The converted and validated y.
    s   y cannot be NoneRo   Rp   R   R{   R'   R(   R)   RŒ   R   RŽ   R   R   R$   Rm   Rw   N(   RS   R   R1   Rk   R3   t   column_or_1dR   R   R   R7   R   R2   R^   (   R   t   yRo   Rp   R   R{   R'   R(   R)   RŒ   t   multi_outputR   RŽ   t	   y_numericR   R   (    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt	   check_X_y|  s(    m	
c         C   s•   t  j |  ƒ } t | ƒ d k r. t  j |  ƒ St | ƒ d k r| | d d k r| | ro t j d t d d ƒn  t  j |  ƒ St d j | ƒ ƒ ‚ d S(   sÞ    Ravel column or 1d numpy array, else raises an error

    Parameters
    ----------
    y : array-like

    warn : boolean, default False
       To control display of warnings.

    Returns
    -------
    y : array

    i   i   s„   A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().R|   s   bad input shape {0}N(	   R   R;   RE   t   ravelRl   Rm   R   R   R   (   R©   Rm   R;   (    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyR¨     s    "	c         C   s€   |  d k s |  t j k r( t j j j St |  t j t j f ƒ rS t j j	 |  ƒ St |  t j j	 ƒ rl |  St
 d |  ƒ ‚ d S(   s  Turn seed into a np.random.RandomState instance

    Parameters
    ----------
    seed : None | int | instance of RandomState
        If seed is None, return the RandomState singleton used by np.random.
        If seed is an int, return a new RandomState instance seeded with seed.
        If seed is already a RandomState instance, return it.
        Otherwise raise ValueError.
    s=   %r cannot be used to seed a numpy.random.RandomState instanceN(   RS   R   t   randomt   mtrandt   _randR.   RF   RG   t   integert   RandomStateR   (   t   seed(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   check_random_state   s    c         C   s   | t  |  j ƒ j k S(   sê  Checks whether the estimator's fit method supports the given parameter.

    Parameters
    ----------
    estimator : object
        An estimator to inspect.

    parameter : str
        The searched parameter.

    Returns
    -------
    is_parameter: bool
        Whether the parameter was found to be a named parameter of the
        estimator's fit method.

    Examples
    --------
    >>> from sklearn.svm import SVC
    >>> has_fit_parameter(SVC(), "sample_weight")
    True

    (   R   R@   t
   parameters(   R   t	   parameter(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   has_fit_parameter5  s    g»½×Ùß|Û=c         C   s?  |  j  d k s) |  j d |  j d k rD t d j |  j ƒ ƒ ‚ n  t j |  ƒ rŸ |  |  j } | j d k r~ | j ƒ  } n  t j	 t
 | j ƒ | k  ƒ } n t j |  |  j d | ƒ} | s;| rÕ t d	 ƒ ‚ n  | rë t j d
 ƒ n  t j |  ƒ r'd |  j } t d |  |  j | ƒ ƒ  }  q;d |  |  j }  n  |  S(   sË  Make sure that array is 2D, square and symmetric.

    If the array is not symmetric, then a symmetrized version is returned.
    Optionally, a warning or exception is raised if the matrix is not
    symmetric.

    Parameters
    ----------
    array : nd-array or sparse matrix
        Input object to check / convert. Must be two-dimensional and square,
        otherwise a ValueError will be raised.
    tol : float
        Absolute tolerance for equivalence of arrays. Default = 1E-10.
    raise_warning : boolean (default=True)
        If True then raise a warning if conversion is required.
    raise_exception : boolean (default=False)
        If True then raise an exception if array is not symmetric.

    Returns
    -------
    array_sym : ndarray or sparse matrix
        Symmetrized version of the input array, i.e. the average of array
        and array.transpose(). If sparse, then duplicate entries are first
        summed and zeros are eliminated.
    i   i    i   s3   array must be 2-dimensional and square. shape = {0}R$   R%   R&   t   atols   Array must be symmetricsY   Array is not symmetric, and will be converted to symmetric by average with its transpose.t   tog      à?(   R$   R%   R&   (   Rƒ   R;   R   R   R    R!   t   TRb   R   R   t   absR"   t   allcloseRl   Rm   R~   (   Rc   t   tolt   raise_warningt   raise_exceptiont   difft	   symmetrict
   conversion(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   check_symmetricP  s&    )	! c         C   s§   | d k r d } n  t |  d ƒ s7 t d |  ƒ ‚ n  t | t t f ƒ sX | g } n  | g  | D] } t |  | ƒ ^ qb ƒ s£ t | i t |  ƒ j d 6ƒ ‚ n  d S(   sL  Perform is_fitted validation for estimator.

    Checks if the estimator is fitted by verifying the presence of
    "all_or_any" of the passed attributes and raises a NotFittedError with the
    given message.

    Parameters
    ----------
    estimator : estimator instance.
        estimator instance for which the check is performed.

    attributes : attribute name(s) given as string or a list/tuple of strings
        Eg.:
            ``["coef_", "estimator_", ...], "coef_"``

    msg : string
        The default error message is, "This %(name)s instance is not fitted
        yet. Call 'fit' with appropriate arguments before using this method."

        For custom messages if "%(name)s" is present in the message string,
        it is substituted for the estimator name.

        Eg. : "Estimator, %(name)s, must be fitted before sparsifying".

    all_or_any : callable, {all, any}, default all
        Specify whether all or any of the given attributes must exist.

    Returns
    -------
    None

    Raises
    ------
    NotFittedError
        If the attributes are not found.
    si   This %(name)s instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.R@   s    %s is not an estimator instance.t   nameN(	   RS   R=   RB   R.   Rh   Ri   R   RD   R€   (   R   t
   attributesRš   t
   all_or_anyt   attr(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   check_is_fitted‡  s    %	(c         C   sG   t  j |  ƒ r |  j n |  }  |  d k  j ƒ  rC t d | ƒ ‚ n  d S(   sÌ   
    Check if there is any negative value in an array.

    Parameters
    ----------
    X : array-like or sparse matrix
        Input data.

    whom : string
        Who passed X to this function.
    i    s$   Negative values in data passed to %sN(   R    R!   R"   R   R   (   R   t   whom(    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   check_non_negativeº  s    (;   t   __doc__Rl   RF   t   numpyR   t   scipy.sparset   sparseR    t   scipyR    R£   t   distutils.versionR   t   numpy.core.numericR   t	   externalsR   t   fixesR   Ry   R   R   t
   exceptionsR   R   R   t   _joblibR	   RU   R2   R4   t   float16t   FLOAT_DTYPESR‚   R¡   R3   R   R#   Rk   R9   R?   RH   RN   RW   R^   Rf   Rr   Rt   RS   R1   Rg   R¬   R¨   R´   R·   RÃ   R   RÈ   RÊ   (    (    (    s7   lib/python2.7/site-packages/sklearn/utils/validation.pyt   <module>   s\   
1			"	!			[		ø		ƒ		63