
\c           @   s  d  Z  d d l Z d d l Z d d l m Z d d l 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 d d	 l m Z d
   Z e d  Z d e d  Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ  d  e f d!     YZ! d"   Z" d#   Z# d$   Z$ d S(%   s    Base classes for all estimators.iN(   t   defaultdict(   t   sparsei   (   t   six(   t	   signature(   t	   _IS_32BIT(   t   __version__c         C   sm   t  |  t j  s! t |  d  rW t j |   r9 |  j n |  } | j d | j d f S|  d |  d f Sd S(   s?   Returns first and last element of numpy array or sparse matrix.t   datai    iN(   i    i    (   ii(   t
   isinstancet   npt   ndarrayt   hasattrR   t   issparseR   t   flat(   t   arrR   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   _first_and_last_element   s    !c         C   sQ  t  |   } | t t t t f k rM | g  |  D] } t | d | ^ q.  St |  d  s | so t j |   St	 d t
 |   t  |   f   n  |  j } |  j d t  } x3 t j |  D]" \ } } t | d t | | <q W| |   } | j d t  }	 xG | D]? } | | }
 |	 | } |
 | k	 r
t d |  | f   q
q
W| S(   s  Constructs a new estimator with the same parameters.

    Clone does a deep copy of the model in an estimator
    without actually copying attached data. It yields a new estimator
    with the same parameters that has not been fit on any data.

    Parameters
    ----------
    estimator : estimator object, or list, tuple or set of objects
        The estimator or group of estimators to be cloned

    safe : boolean, optional
        If safe is false, clone will fall back to a deep copy on objects
        that are not estimators.

    t   safet
   get_paramss   Cannot clone object '%s' (type %s): it does not seem to be a scikit-learn estimator as it does not implement a 'get_params' methods.t   deepsW   Cannot clone object %s, as the constructor either does not set or modifies parameter %s(   t   typet   listt   tuplet   sett	   frozensett   cloneR
   t   copyt   deepcopyt	   TypeErrort   reprt	   __class__R   t   FalseR   t	   iteritemst   RuntimeError(   t	   estimatorR   t   estimator_typet   et   klasst   new_object_paramst   namet   paramt
   new_objectt
   params_sett   param1t   param2(    (    s+   lib/python2.7/site-packages/sklearn/base.pyR       s*    )	

i    c         C   s  t  j   } t  j d d d d d d  t   } | } d d | d d	 } xt t t j |     D] \ } \ } }	 t |	  t	 k r d
 | t
 |	  f }
 n d
 | | |	  f }
 t |
  d k r |
 d  d |
 d }
 n  | d k rK| t |
  d k sd |
 k r1| j |  t |  } qK| j d  | d 7} n  | j |
  | t |
  7} qi Wt  j |   d j |  } d j d   | j d  D  } | S(   sM  Pretty print the dictionary 'params'

    Parameters
    ----------
    params : dict
        The dictionary to pretty print

    offset : int
        The offset in characters to add at the begin of each line.

    printer : callable
        The function to convert entries to strings, typically
        the builtin str or repr

    t	   precisioni   t	   thresholdi@   t	   edgeitemsi   s   ,
i   t    s   %s=%si  i,  s   ...ii    iK   s   
s   , t    c         s   s   |  ] } | j  d   Vq d S(   R.   N(   t   rstrip(   t   .0t   l(    (    s+   lib/python2.7/site-packages/sklearn/base.pys	   <genexpr>~   s    (   R   t   get_printoptionst   set_printoptionsR   t	   enumeratet   sortedR   R   R   t   floatt   strt   lent   appendt   joint   split(   t   paramst   offsett   printert   optionst   params_listt   this_line_lengtht   line_sept   it   kt   vt	   this_reprt   lines(    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   _pprintP   s.    	.""t   BaseEstimatorc           B   sM   e  Z d  Z e d    Z e d  Z d   Z d   Z d   Z	 d   Z
 RS(   s   Base class for all estimators in scikit-learn

    Notes
    -----
    All estimators should specify all the parameters that can be set
    at the class level in their ``__init__`` as explicit keyword
    arguments (no ``*args`` or ``**kwargs``).
    c         C   s   t  |  j d |  j  } | t j k r+ g  St |  } g  | j j   D]- } | j d k rG | j | j k rG | ^ qG } x9 | D]1 } | j | j	 k r t
 d |  | f   q q Wt g  | D] } | j ^ q  S(   s%   Get parameter names for the estimatort   deprecated_originalt   selfs   scikit-learn estimators should always specify their parameters in the signature of their __init__ (no varargs). %s with constructor %s doesn't  follow this convention.(   t   getattrt   __init__t   objectR   t
   parameterst   valuesR%   t   kindt   VAR_KEYWORDt   VAR_POSITIONALR   R6   (   t   clst   initt   init_signaturet   pRP   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   _get_param_names   s    -c            s   t    } xw |  j   D]i   t |    d  } | ru t | d  ru | j   j   } | j   f d   | D  n  | |   <q W| S(   so  Get parameters for this estimator.

        Parameters
        ----------
        deep : boolean, optional
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : mapping of string to any
            Parameter names mapped to their values.
        R   c         3   s)   |  ] \ } }   d  | | f Vq d S(   t   __N(    (   R1   RE   t   val(   t   key(    s+   lib/python2.7/site-packages/sklearn/base.pys	   <genexpr>   s    N(   t   dictRY   RM   t   NoneR
   R   t   itemst   update(   RL   R   t   outt   valuet
   deep_items(    (   R\   s+   lib/python2.7/site-packages/sklearn/base.pyR      s    	 c   	      K   s   | s
 |  S|  j  d t  } t t  } x | j   D]z \ } } | j d  \ } } } | | k r~ t d | |  f   n  | r | | | | <q5 t |  | |  | | | <q5 Wx+ | j   D] \ } } | | j |   q W|  S(   s\  Set the parameters of this estimator.

        The method works on simple estimators as well as on nested objects
        (such as pipelines). The latter have parameters of the form
        ``<component>__<parameter>`` so that it's possible to update each
        component of a nested object.

        Returns
        -------
        self
        R   RZ   ss   Invalid parameter %s for estimator %s. Check the list of available parameters with `estimator.get_params().keys()`.(	   R   t   TrueR    R]   R_   t	   partitiont
   ValueErrort   setattrt
   set_params(	   RL   R=   t   valid_paramst   nested_paramsR\   Rb   t   delimt   sub_keyt
   sub_params(    (    s+   lib/python2.7/site-packages/sklearn/base.pyRh      s     c         C   s8   |  j  j } d | t |  j d t  d t |  f S(   Ns   %s(%s)R   R>   (   R   t   __name__RI   R   R   R9   (   RL   t
   class_name(    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   __repr__   s    c         C   sr   y t  t |   j   } Wn  t k
 r; |  j j   } n Xt |   j j d  rj t	 | j
   d t S| Sd  S(   Ns   sklearn.t   _sklearn_version(   t   superRJ   t   __getstate__t   AttributeErrort   __dict__R   R   t
   __module__t
   startswithR]   R_   R   (   RL   t   state(    (    s+   lib/python2.7/site-packages/sklearn/base.pyRs      s    c         C   s   t  |   j j d  ra | j d d  } | t k ra t j d j |  j j	 | t  t
  qa n  y t t |   j |  Wn! t k
 r |  j j |  n Xd  S(   Ns   sklearn.Rq   s   pre-0.18s   Trying to unpickle estimator {0} from version {1} when using version {2}. This might lead to breaking code or invalid results. Use at your own risk.(   R   Rv   Rw   t   popR   t   warningst   warnt   formatR   Rn   t   UserWarningRr   RJ   t   __setstate__Rt   Ru   R`   (   RL   Rx   t   pickle_version(    (    s+   lib/python2.7/site-packages/sklearn/base.pyR~      s    (   Rn   Rv   t   __doc__t   classmethodRY   Rd   R   Rh   Rp   Rs   R~   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyRJ      s   	%		t   ClassifierMixinc           B   s    e  Z d  Z d Z d d  Z RS(   s0   Mixin class for all classifiers in scikit-learn.t
   classifierc         C   s,   d d l  m } | | |  j |  d | S(   s  Returns the mean accuracy on the given test data and labels.

        In multi-label classification, this is the subset accuracy
        which is a harsh metric since you require for each sample that
        each label set be correctly predicted.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_features)
            Test samples.

        y : array-like, shape = (n_samples) or (n_samples, n_outputs)
            True labels for X.

        sample_weight : array-like, shape = [n_samples], optional
            Sample weights.

        Returns
        -------
        score : float
            Mean accuracy of self.predict(X) wrt. y.

        i   (   t   accuracy_scoret   sample_weight(   t   metricsR   t   predict(   RL   t   Xt   yR   R   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   score	  s    N(   Rn   Rv   R   t   _estimator_typeR^   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s   t   RegressorMixinc           B   s    e  Z d  Z d Z d d  Z RS(   s:   Mixin class for all regression estimators in scikit-learn.t	   regressorc         C   s2   d d l  m } | | |  j |  d | d d S(   s  Returns the coefficient of determination R^2 of the prediction.

        The coefficient R^2 is defined as (1 - u/v), where u is the residual
        sum of squares ((y_true - y_pred) ** 2).sum() and v is the total
        sum of squares ((y_true - y_true.mean()) ** 2).sum().
        The best possible score is 1.0 and it can be negative (because the
        model can be arbitrarily worse). A constant model that always
        predicts the expected value of y, disregarding the input features,
        would get a R^2 score of 0.0.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_features)
            Test samples. For some estimators this may be a
            precomputed kernel matrix instead, shape = (n_samples,
            n_samples_fitted], where n_samples_fitted is the number of
            samples used in the fitting for the estimator.

        y : array-like, shape = (n_samples) or (n_samples, n_outputs)
            True values for X.

        sample_weight : array-like, shape = [n_samples], optional
            Sample weights.

        Returns
        -------
        score : float
            R^2 of self.predict(X) wrt. y.
        i   (   t   r2_scoreR   t   multioutputt   variance_weighted(   R   R   R   (   RL   R   R   R   R   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR   *  s    N(   Rn   Rv   R   R   R^   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR   &  s   t   ClusterMixinc           B   s    e  Z d  Z d Z d d  Z RS(   s7   Mixin class for all cluster estimators in scikit-learn.t	   clustererc         C   s   |  j  |  |  j S(   sn  Performs clustering on X and returns cluster labels.

        Parameters
        ----------
        X : ndarray, shape (n_samples, n_features)
            Input data.

        y : Ignored
            not used, present for API consistency by convention.

        Returns
        -------
        labels : ndarray, shape (n_samples,)
            cluster labels
        (   t   fitt   labels_(   RL   R   R   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   fit_predictS  s    N(   Rn   Rv   R   R   R^   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR   O  s   t   BiclusterMixinc           B   s8   e  Z d  Z e d    Z d   Z d   Z d   Z RS(   s8   Mixin class for all bicluster estimators in scikit-learnc         C   s   |  j  |  j f S(   s{   Convenient way to get row and column indicators together.

        Returns the ``rows_`` and ``columns_`` members.
        (   t   rows_t   columns_(   RL   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   biclusters_l  s    c         C   s>   |  j  | } |  j | } t j |  d t j |  d f S(   s  Row and column indices of the i'th bicluster.

        Only works if ``rows_`` and ``columns_`` attributes exist.

        Parameters
        ----------
        i : int
            The index of the cluster.

        Returns
        -------
        row_ind : np.array, dtype=np.intp
            Indices of rows in the dataset that belong to the bicluster.
        col_ind : np.array, dtype=np.intp
            Indices of columns in the dataset that belong to the bicluster.

        i    (   R   R   R   t   nonzero(   RL   RD   t   rowst   columns(    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   get_indicest  s    c         C   s#   |  j  |  } t d   | D  S(   s   Shape of the i'th bicluster.

        Parameters
        ----------
        i : int
            The index of the cluster.

        Returns
        -------
        shape : (int, int)
            Number of rows and columns (resp.) in the bicluster.
        c         s   s   |  ] } t  |  Vq d  S(   N(   R9   (   R1   RD   (    (    s+   lib/python2.7/site-packages/sklearn/base.pys	   <genexpr>  s    (   R   R   (   RL   RD   t   indices(    (    s+   lib/python2.7/site-packages/sklearn/base.pyt	   get_shape  s    c         C   sX   d d l  m } | | d d } |  j |  \ } } | | d d  t j f | f S(   s  Returns the submatrix corresponding to bicluster `i`.

        Parameters
        ----------
        i : int
            The index of the cluster.
        data : array
            The data.

        Returns
        -------
        submatrix : array
            The submatrix corresponding to bicluster i.

        Notes
        -----
        Works with sparse matrices. Only works if ``rows_`` and
        ``columns_`` attributes exist.
        i   (   t   check_arrayt   accept_sparset   csrN(   t   utils.validationR   R   R   t   newaxis(   RL   RD   R   R   t   row_indt   col_ind(    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   get_submatrix  s    (   Rn   Rv   R   t   propertyR   R   R   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR   i  s
   		t   TransformerMixinc           B   s   e  Z d  Z d d  Z RS(   s1   Mixin class for all transformers in scikit-learn.c         K   sE   | d k r% |  j | |  j |  S|  j | | |  j |  Sd S(   s  Fit to data, then transform it.

        Fits transformer to X and y with optional parameters fit_params
        and returns a transformed version of X.

        Parameters
        ----------
        X : numpy array of shape [n_samples, n_features]
            Training set.

        y : numpy array of shape [n_samples]
            Target values.

        Returns
        -------
        X_new : numpy array of shape [n_samples, n_features_new]
            Transformed array.

        N(   R^   R   t	   transform(   RL   R   R   t
   fit_params(    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   fit_transform  s    N(   Rn   Rv   R   R^   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s   t   DensityMixinc           B   s    e  Z d  Z d Z d d  Z RS(   s7   Mixin class for all density estimators in scikit-learn.t   DensityEstimatorc         C   s   d S(   s   Returns the score of the model on the data X

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

        Returns
        -------
        score : float
        N(    (   RL   R   R   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s    N(   Rn   Rv   R   R   R^   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s   t   OutlierMixinc           B   s    e  Z d  Z d Z d d  Z RS(   sA   Mixin class for all outlier detection estimators in scikit-learn.t   outlier_detectorc         C   s   |  j  |  j |  S(   s  Performs fit on X and returns labels for X.

        Returns -1 for outliers and 1 for inliers.

        Parameters
        ----------
        X : ndarray, shape (n_samples, n_features)
            Input data.

        y : Ignored
            not used, present for API consistency by convention.

        Returns
        -------
        y : ndarray, shape (n_samples,)
            1 for inliers, -1 for outliers.
        (   R   R   (   RL   R   R   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s    N(   Rn   Rv   R   R   R^   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s   t   MetaEstimatorMixinc           B   s   e  Z d  Z RS(   s4   Mixin class for all meta estimators in scikit-learn.(   Rn   Rv   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s   t   _UnstableArchMixinc           B   s   e  Z d  Z d   Z RS(   s=   Mark estimators that are non-determinstic on 32bit or PowerPCc         C   s    i t  p t j   j d  d 6S(   Nt   ppct   powerpct   non_deterministic(   R   R   (   R   t   platformt   machineRw   (   RL   (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt
   _more_tags
  s    (   Rn   Rv   R   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyR     s   c         C   s   t  |  d d  d k S(   s  Returns True if the given estimator is (probably) a classifier.

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

    Returns
    -------
    out : bool
        True if estimator is a classifier and False otherwise.
    R   R   N(   RM   R^   (   R    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   is_classifier  s    c         C   s   t  |  d d  d k S(   s  Returns True if the given estimator is (probably) a regressor.

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

    Returns
    -------
    out : bool
        True if estimator is a regressor and False otherwise.
    R   R   N(   RM   R^   (   R    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   is_regressor  s    c         C   s   t  |  d d  d k S(   s  Returns True if the given estimator is (probably) an outlier detector.

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

    Returns
    -------
    out : bool
        True if estimator is an outlier detector and False otherwise.
    R   R   N(   RM   R^   (   R    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   is_outlier_detector/  s    (%   R   R   Rz   t   collectionsR    R   t   numpyR   t   scipyR   t	   externalsR   t   utils.fixesR   t   utilsR   R/   R   R   Rd   R   R   RI   RO   RJ   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/sklearn/base.pyt   <module>   s4   	03!)L!		