ó
‡ˆ\c           @   sG  d  d l  m 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 m Z m 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 e j j Z d d g Z d e e f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d S(   iÿÿÿÿ(   t   divisionN(   t   sparsei   (   t
   get_config(   t   BaseEstimatort   TransformerMixin(   t   six(   t   check_array(   t
   deprecated(   t   _argmaxt   _object_dtype_isnan(   t   check_is_fittedi   (   t   _transform_selected(   t   _encodet   _encode_check_unknownt   OneHotEncodert   OrdinalEncodert   _BaseEncoderc           B   s/   e  Z d  Z d „  Z d d „ Z d d „ Z RS(   sm   
    Base class for encoders that includes the code to categorize and
    transform the input features.

    c         C   s¨   t  | d d ƒ} t | d ƒ rR t j | j t j ƒ rR t  | d t j ƒ} n | } | j t j d ƒ k r¤ t ƒ  d s¤ t	 | ƒ j
 ƒ  r¡ t d ƒ ‚ q¡ q¤ n  | S(   sÂ   
        Perform custom check_array:
        - convert list of strings to object dtype
        - check for missing values for object dtype data (check_array does
          not do that)

        t   dtypet   objectt   assume_finites   Input contains NaNN(   R   t   Nonet   hasattrt   npt
   issubdtypeR   t   str_R   t   _get_configR	   t   anyt
   ValueError(   t   selft   Xt   X_temp(    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   _check_X'   s    (t   errorc   
      C   s|  |  j  | ƒ } | j \ } } |  j d k r° | j t k r‰ xJ |  j D]< } t j t j | ƒ t j | ƒ k ƒ sF t	 d ƒ ‚ qF qF Wn  t
 |  j ƒ | k r° t	 d ƒ ‚ q° n  g  |  _ x¼ t | ƒ D]® } | d  d  … | f } |  j d k r t | ƒ } nd t j |  j | d | j ƒ} | d k rdt | | ƒ } | rdd j | | ƒ }	 t	 |	 ƒ ‚ qdn  |  j j | ƒ qÆ Wd  S(   Nt   autos>   Unsorted categories are not supported for numerical categoriessM   Shape mismatch: if n_values is an array, it has to be of shape (n_features,).R   R    s5   Found unknown categories {0} in column {1} during fit(   R   t   shapet   _categoriesR   R   R   t   allt   sortt   arrayR   t   lent   categories_t   rangeR   R   t   formatt   append(
   R   R   t   handle_unknownt	   n_samplest
   n_featurest   catst   it   Xit   difft   msg(    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   _fit<   s,    '	c         C   s¤  |  j  | ƒ } | j \ } } t j | d t j ƒ} t j | d t j ƒ} xIt | ƒ D];} | d  d  … | f } t | |  j	 | d t
 ƒ\ }	 }
 t j |
 ƒ s^| d k rÕ d j |	 | ƒ } t | ƒ ‚ q^|
 | d  d  … | f <|  j	 | j j d	 k r9|  j	 | j | j k r9| j |  j	 | j ƒ } n | j ƒ  } |  j	 | d | |
 <n  t | |  j	 | d t
 ƒ\ } } | | d  d  … | f <q[ W| | f S(
   NR   t   return_maskR    s;   Found unknown categories {0} in column {1} during transformt   Ut   Si    t   encode(   R6   R7   (   R   R"   R   t
   zeros_liket   intt	   ones_liket   boolR)   R   R(   t   TrueR$   R*   R   R   t   kindt   itemsizet   astypet   copyR   (   R   R   R,   t   _R.   t   X_intt   X_maskR0   R1   R2   t
   valid_maskR3   t   encoded(    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt
   _transform[   s,    "(   t   __name__t
   __module__t   __doc__R   R4   RG   (    (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyR       s   	c           B   s×   e  Z d  Z d d d e e j d d „ Z e e	 d ƒ d „  ƒ ƒ Z
 e e	 d ƒ d „  ƒ ƒ Z e e	 d ƒ d „  ƒ ƒ Z d	 „  Z d d
 „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(   s5  Encode categorical integer features as a one-hot numeric array.

    The input to this transformer should be an array-like of integers or
    strings, denoting the values taken on by categorical (discrete) features.
    The features are encoded using a one-hot (aka 'one-of-K' or 'dummy')
    encoding scheme. This creates a binary column for each category and
    returns a sparse matrix or dense array.

    By default, the encoder derives the categories based on the unique values
    in each feature. Alternatively, you can also specify the `categories`
    manually.
    The OneHotEncoder previously assumed that the input features take on
    values in the range [0, max(values)). This behaviour is deprecated.

    This encoding is needed for feeding categorical data to many scikit-learn
    estimators, notably linear models and SVMs with the standard kernels.

    Note: a one-hot encoding of y labels should use a LabelBinarizer
    instead.

    Read more in the :ref:`User Guide <preprocessing_categorical_features>`.

    Parameters
    ----------
    categories : 'auto' or a list of lists/arrays of values, default='auto'.
        Categories (unique values) per feature:

        - 'auto' : Determine categories automatically from the training data.
        - list : ``categories[i]`` holds the categories expected in the ith
          column. The passed categories should not mix strings and numeric
          values within a single feature, and should be sorted in case of
          numeric values.

        The used categories can be found in the ``categories_`` attribute.

    sparse : boolean, default=True
        Will return sparse matrix if set True else will return an array.

    dtype : number type, default=np.float
        Desired dtype of output.

    handle_unknown : 'error' or 'ignore', default='error'.
        Whether to raise an error or ignore if an unknown categorical feature
        is present during transform (default is to raise). When this parameter
        is set to 'ignore' and an unknown category is encountered during
        transform, the resulting one-hot encoded columns for this feature
        will be all zeros. In the inverse transform, an unknown category
        will be denoted as None.

    n_values : 'auto', int or array of ints, default='auto'
        Number of values per feature.

        - 'auto' : determine value range from training data.
        - int : number of categorical values per feature.
                Each feature value should be in ``range(n_values)``
        - array : ``n_values[i]`` is the number of categorical values in
                  ``X[:, i]``. Each feature value should be
                  in ``range(n_values[i])``

        .. deprecated:: 0.20
            The `n_values` keyword was deprecated in version 0.20 and will
            be removed in 0.22. Use `categories` instead.

    categorical_features : 'all' or array of indices or mask, default='all'
        Specify what features are treated as categorical.

        - 'all': All features are treated as categorical.
        - array of indices: Array of categorical feature indices.
        - mask: Array of length n_features and with dtype=bool.

        Non-categorical features are always stacked to the right of the matrix.

        .. deprecated:: 0.20
            The `categorical_features` keyword was deprecated in version
            0.20 and will be removed in 0.22.
            You can use the ``ColumnTransformer`` instead.

    Attributes
    ----------
    categories_ : list of arrays
        The categories of each feature determined during fitting
        (in order of the features in X and corresponding with the output
        of ``transform``).

    active_features_ : array
        Indices for active features, meaning values that actually occur
        in the training set. Only available when n_values is ``'auto'``.

        .. deprecated:: 0.20
            The ``active_features_`` attribute was deprecated in version
            0.20 and will be removed in 0.22.

    feature_indices_ : array of shape (n_features,)
        Indices to feature ranges.
        Feature ``i`` in the original data is mapped to features
        from ``feature_indices_[i]`` to ``feature_indices_[i+1]``
        (and then potentially masked by ``active_features_`` afterwards)

        .. deprecated:: 0.20
            The ``feature_indices_`` attribute was deprecated in version
            0.20 and will be removed in 0.22.

    n_values_ : array of shape (n_features,)
        Maximum number of values per feature.

        .. deprecated:: 0.20
            The ``n_values_`` attribute was deprecated in version
            0.20 and will be removed in 0.22.

    Examples
    --------
    Given a dataset with two features, we let the encoder find the unique
    values per feature and transform the data to a binary one-hot encoding.

    >>> from sklearn.preprocessing import OneHotEncoder
    >>> enc = OneHotEncoder(handle_unknown='ignore')
    >>> X = [['Male', 1], ['Female', 3], ['Female', 2]]
    >>> enc.fit(X)
    ... # doctest: +ELLIPSIS
    OneHotEncoder(categorical_features=None, categories=None,
           dtype=<... 'numpy.float64'>, handle_unknown='ignore',
           n_values=None, sparse=True)

    >>> enc.categories_
    [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
    >>> enc.transform([['Female', 1], ['Male', 4]]).toarray()
    array([[1., 0., 1., 0., 0.],
           [0., 1., 0., 0., 0.]])
    >>> enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])
    array([['Male', 1],
           [None, 2]], dtype=object)
    >>> enc.get_feature_names()
    array(['x0_Female', 'x0_Male', 'x1_1', 'x1_2', 'x1_3'], dtype=object)

    See also
    --------
    sklearn.preprocessing.OrdinalEncoder : performs an ordinal (integer)
      encoding of the categorical features.
    sklearn.feature_extraction.DictVectorizer : performs a one-hot encoding of
      dictionary items (also handles string-valued features).
    sklearn.feature_extraction.FeatureHasher : performs an approximate one-hot
      encoding of dictionary items or strings.
    sklearn.preprocessing.LabelBinarizer : binarizes labels in a one-vs-all
      fashion.
    sklearn.preprocessing.MultiLabelBinarizer : transforms between iterable of
      iterables and a multilabel format, e.g. a (samples x classes) binary
      matrix indicating the presence of a class label.
    R    c         C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t
   categoriesR   R   R,   t   n_valuest   categorical_features(   R   RL   RM   RK   R   R   R,   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   __init__  s    					s[   The ``active_features_`` attribute was deprecated in version 0.20 and will be removed 0.22.c         C   s   t  |  d ƒ |  j S(   NR(   (   R
   t   _active_features_(   R   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   active_features_"  s    s[   The ``feature_indices_`` attribute was deprecated in version 0.20 and will be removed 0.22.c         C   s   t  |  d ƒ |  j S(   NR(   (   R
   t   _feature_indices_(   R   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   feature_indices_)  s    sT   The ``n_values_`` attribute was deprecated in version 0.20 and will be removed 0.22.c         C   s   t  |  d ƒ |  j S(   NR(   (   R
   t
   _n_values_(   R   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt	   n_values_0  s    c         C   s`  |  j  |  _ t |  d d  ƒ |  _ t |  d d  ƒ |  _ |  j d  k	 sT |  j d  k	 r~ t |  _ |  j d  k	 rq|  j |  _ qqnó |  j  d  k	 r¾ |  j  d k r¾ d } t	 j
 | t ƒ t |  _ n³ d |  _ |  j d k rt |  _ d |  _ |  j  d k rqd } t	 j
 | t ƒ qqn^ y t | d t j ƒ} Wn# t k
 rQt |  _ d |  _ n  Xd } t	 j
 | t ƒ t |  _ |  j d  k	 rSt |  j t j ƒ r·|  j d	 k r·t	 j
 d
 t ƒ n |  j d  k	 rÕt d ƒ ‚ n  t	 j
 d t ƒ | j d } t j | d t ƒ} t | t j |  j ƒ <t | ƒ d k r;g  |  _ n  t |  _ |  j |  _ n	 d	 |  _ d  S(   NR#   t   _categorical_featuresR!   s°   Passing 'n_values' is deprecated in version 0.20 and will be removed in 0.22. You can use the 'categories' keyword instead. 'n_values=n' corresponds to 'categories=[range(n)]'.t   ignores…   Passing 'n_values' is deprecated in version 0.20 and will be removed in 0.22. n_values='auto' can be replaced with categories='auto'.R   sÁ  The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.
If you want the future behaviour and silence this warning, you can specify "categories='auto'".
In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.R$   s¡   The 'categorical_features' keyword is deprecated in version 0.20 and will be removed in 0.22. The passed value of 'all' is the default and can simply be removed.sk   The 'categorical_features' keyword is deprecated, and cannot be used together with specifying 'categories'.sˆ   The 'categorical_features' keyword is deprecated in version 0.20 and will be removed in 0.22. You can use the ColumnTransformer instead.i   i    (   RL   t	   _n_valuest   getattrR   R#   RU   RK   t   Falset   _legacy_modet   warningst   warnt   DeprecationWarningR=   R,   R   R   R:   R   t   FutureWarningRM   t
   isinstanceR   t   string_typesR"   t   zerosR<   t   asarrayt   sumR(   (   R   R   R3   R.   t   sel(    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   _handle_deprecations7  s^    							
	c         C   sŠ   |  j  d k r0 d j |  j  ƒ } t | ƒ ‚ n  |  j | ƒ |  j rl t | |  j |  j |  j d t	 ƒ|  S|  j
 | d |  j  ƒ|  Sd S(   sí   Fit OneHotEncoder to X.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features]
            The data to determine the categories of each feature.

        Returns
        -------
        self
        R    RV   s=   handle_unknown should be either 'error' or 'ignore', got {0}.RA   R,   N(   R    RV   (   R,   R*   R   Re   RZ   R   t   _legacy_fit_transformR   RU   R=   R4   (   R   R   t   yR3   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   fit”  s    		c         C   sˆ  t  | d d ƒ } t | d t j ƒ} t j | d k  ƒ rK t d ƒ ‚ n  | j \ } } t |  j	 t
 j ƒ rš |  j	 d k rš t j | d d ƒd } nt |  j	 t j ƒ rt j | d d ƒ|  j	 k j ƒ  ré t d |  j	 ƒ ‚ n  t j | d t j ƒ} | j |  j	 ƒ n‡ y t j |  j	 d t ƒ} Wn0 t t f k
 rbt d t |  j	 ƒ ƒ ‚ n X| j d k  sŒ| j d | j d k r›t d	 ƒ ‚ n  | |  _ g  | D] } t j | d d | ƒ^ q«|  _ t j d g | g ƒ } t j | ƒ } | |  _ | | d
  j ƒ  } t j t j | d t j ƒ| ƒ }	 t j | | ƒ }
 t j  |
 |	 | f f d | | d
 f d |  j! ƒj" ƒ  } t |  j	 t
 j ƒ rq|  j	 d k rqt j# | j$ d d ƒ ƒ j ƒ  d k } t j% | ƒ d } | d d … | f } | |  _& g  t' | ƒ D]S } | rFt j( | d d … | f ƒ j) | ƒ n t j( | d d … | f ƒ ^ q|  _ n  |  j r~| S| j* ƒ  S(   s-   Assumes X contains only categorical features.R   i    s¿   OneHotEncoder in legacy mode cannot handle categories encoded as negative integers. Please set categories='auto' explicitly to be able to use arbitrary integer values as category identifiers.R!   t   axisi   s%   Feature out of bounds for n_values=%dsR   Wrong type for parameter `n_values`. Expected 'auto', int or array of ints, got %rsM   Shape mismatch: if n_values is an array, it has to be of shape (n_features,).iÿÿÿÿR"   N(+   RX   R   R   R   R:   R   R   R"   R_   RW   R   R`   t   maxt   numberst   Integralt   emptyt   fillRb   t	   TypeErrort   typet   ndimRS   t   arangeR(   t   hstackt   cumsumRQ   t   ravelt   repeatt   int32t   onesR   t
   coo_matrixR   t   tocsrR&   Rc   t   whereRO   R)   t   uniqueR@   t   toarray(   R   R   R   R-   R.   RL   t   n_valt   indicest   column_indicest   row_indicest   datat   outt   maskt   active_featuresR0   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyRf   °  sV    $)	,		'	ic         C   s‚   |  j  d k r0 d j |  j  ƒ } t | ƒ ‚ n  |  j | ƒ |  j rh t | |  j |  j |  j d t	 ƒS|  j
 | ƒ j | ƒ Sd S(   sm  Fit OneHotEncoder to X, then transform X.

        Equivalent to fit(X).transform(X) but more convenient.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features]
            The data to encode.

        Returns
        -------
        X_out : sparse matrix if sparse=True else a 2-d array
            Transformed input.
        R    RV   s=   handle_unknown should be either 'error' or 'ignore', got {0}.RA   N(   R    RV   (   R,   R*   R   Re   RZ   R   Rf   R   RU   R=   Rh   t	   transform(   R   R   Rg   R3   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   fit_transformë  s    	c   
      C   sï  t  | d t j ƒ} t j | d k  ƒ r9 t d ƒ ‚ n  | j \ } } |  j } | | j d d k rŒ t d | j d d | f ƒ ‚ n  | |  j k  j ƒ  } t j | ƒ r|  j	 d k rÖ t d |  j	 ƒ ‚ n  |  j	 d k rt d	 | j ƒ  | ƒ ‚ qn  | | d
  j ƒ  | } t j
 t j | d t j ƒ| ƒ | } t j t j | ƒ ƒ } t j | | | f f d | | d
 f d |  j ƒj ƒ  }	 t |  j t j ƒ rØ|  j d k rØ|	 d d … |  j f }	 n  |  j rå|	 S|	 j ƒ  S(   s-   Assumes X contains only categorical features.R   i    s¿   OneHotEncoder in legacy mode cannot handle categories encoded as negative integers. Please set categories='auto' explicitly to be able to use arbitrary integer values as category identifiers.i   s?   X has different shape than during fitting. Expected %d, got %d.R    RV   s7   handle_unknown should be either error or unknown got %ss8   unknown categorical feature present %s during transform.iÿÿÿÿR"   R!   N(   R    RV   (   R   R   R:   R   R   R"   RQ   RS   Ru   R,   Rv   Rr   Rw   Rx   Rc   R   Ry   R   Rz   R_   RW   R   R`   RO   R}   (
   R   R   R-   R.   R   R„   R€   R   R‚   Rƒ   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   _legacy_transform  s6    	c         C   s  t  | d d ƒ} t | d ƒ rR t j | j t j ƒ rR t  | d t j ƒ} n | } | j \ } } |  j	 | d |  j
 ƒ\ } } | j ƒ  } g  |  j D] } | j d ^ q› }	 t j d g |	 ƒ }	 t j |	 ƒ }
 | |
 d  j ƒ  | } | j d d ƒ j ƒ  } t j | d d ƒ } t j | | ƒ | } t j | | | f d | |
 d f d |  j ƒ} |  j sy| j ƒ  S| Sd S(	   s-   New implementation assuming categorical inputR   R,   i    iÿÿÿÿRi   i   R"   N(   R   R   R   R   R   R   R   R   R"   RG   R,   Ru   R(   R&   Rt   Rc   t   insertRx   R   t
   csr_matrixR}   (   R   R   R   R-   R.   RC   RD   R„   R/   RL   t   feature_indicesR   t   indptrR‚   Rƒ   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   _transform_new4  s(    (#	
c         C   sI   t  |  d ƒ |  j r8 t | |  j |  j |  j d t ƒS|  j | ƒ Sd S(   s'  Transform X using one-hot encoding.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features]
            The data to encode.

        Returns
        -------
        X_out : sparse matrix if sparse=True else a 2-d array
            Transformed input.
        R(   RA   N(   R
   RZ   R   Rˆ   R   RU   R=   R   (   R   R   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyR†   R  s    		c         C   s5  t  |  d ƒ t | d d ƒ} | j \ } } t |  j ƒ } t g  |  j D] } t | ƒ ^ qJ ƒ } d } | j d | k r  t | j | | j d ƒ ƒ ‚ n  t j	 g  |  j D] } | j
 ^ q° g  ƒ }	 t j | | f d |	 ƒ}
 d } i  } xå t | ƒ D]× } t |  j | ƒ } | d d … | | | … f } t j t | d	 d ƒƒ j ƒ  } |  j | | |
 d d … | f <|  j d
 k rÌt j | j d	 d ƒ d k ƒ j ƒ  } | j ƒ  rÌ| | | <qÌn  | | 7} qÿ W| r1|
 j
 t k r|
 j t ƒ }
 n  x- | j ƒ  D] \ } } d |
 | | f <qWn  |
 S(   sç  Convert the back data to the original representation.

        In case unknown categories are encountered (all zero's in the
        one-hot encoding), ``None`` is used to represent this category.

        Parameters
        ----------
        X : array-like or sparse matrix, shape [n_samples, n_encoded_features]
            The transformed data.

        Returns
        -------
        X_tr : array-like, shape [n_samples, n_features]
            Inverse transformed array.

        R(   t   accept_sparset   csrsI   Shape of the passed X data is not correct. Expected {0} columns, got {1}.i   R   i    NRi   RV   (   R
   R   R"   R'   R(   Rc   R   R*   R   t   find_common_typeR   Rm   R)   Rb   R   t   flattenR,   R   R   R@   t   itemsR   (   R   R   R-   RB   R.   R/   t   n_transformed_featuresR3   t   catt   dtt   X_trt   jt   found_unknownR0   t   n_categoriest   subt   labelst   unknownt   idxR„   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   inverse_transformg  s8    ("+ !!'c         C   s  t  |  d ƒ |  j } | d k rN g  t t | ƒ ƒ D] } d | ^ q5 } nE t | ƒ t |  j ƒ k r“ t d j t |  j ƒ t | ƒ ƒ ƒ ‚ n  g  } xY t t | ƒ ƒ D]E } g  | | D]! } | | d t j | ƒ ^ q½ } | j	 | ƒ q¬ Wt
 j | d t ƒS(   s‚  Return feature names for output features.

        Parameters
        ----------
        input_features : list of string, length n_features, optional
            String names for input features if available. By default,
            "x0", "x1", ... "xn_features" is used.

        Returns
        -------
        output_feature_names : array of string, length n_output_features

        R(   s   x%dsJ   input_features should have length equal to number of features ({}), got {}RB   R   N(   R
   R(   R   R)   R'   R   R*   R   t	   text_typet   extendR   R&   R   (   R   t   input_featuresR/   R0   t   feature_namest   tt   names(    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   get_feature_namesª  s    	,2N(   RH   RI   RJ   R   R=   R   t   float64RN   t   propertyR   RP   RR   RT   Re   Rh   Rf   R‡   Rˆ   R   R†   Rž   R¥   (    (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyR   €   s&   ”
	]	;	,			Cc           B   s>   e  Z d  Z d e j d „ Z d d „ Z d „  Z d „  Z	 RS(   s©  Encode categorical features as an integer array.

    The input to this transformer should be an array-like of integers or
    strings, denoting the values taken on by categorical (discrete) features.
    The features are converted to ordinal integers. This results in
    a single column of integers (0 to n_categories - 1) per feature.

    Read more in the :ref:`User Guide <preprocessing_categorical_features>`.

    Parameters
    ----------
    categories : 'auto' or a list of lists/arrays of values.
        Categories (unique values) per feature:

        - 'auto' : Determine categories automatically from the training data.
        - list : ``categories[i]`` holds the categories expected in the ith
          column. The passed categories should not mix strings and numeric
          values, and should be sorted in case of numeric values.

        The used categories can be found in the ``categories_`` attribute.

    dtype : number type, default np.float64
        Desired dtype of output.

    Attributes
    ----------
    categories_ : list of arrays
        The categories of each feature determined during fitting
        (in order of the features in X and corresponding with the output
        of ``transform``).

    Examples
    --------
    Given a dataset with two features, we let the encoder find the unique
    values per feature and transform the data to an ordinal encoding.

    >>> from sklearn.preprocessing import OrdinalEncoder
    >>> enc = OrdinalEncoder()
    >>> X = [['Male', 1], ['Female', 3], ['Female', 2]]
    >>> enc.fit(X)
    ... # doctest: +ELLIPSIS
    OrdinalEncoder(categories='auto', dtype=<... 'numpy.float64'>)
    >>> enc.categories_
    [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
    >>> enc.transform([['Female', 3], ['Male', 1]])
    array([[0., 2.],
           [1., 0.]])

    >>> enc.inverse_transform([[1, 0], [0, 1]])
    array([['Male', 1],
           ['Female', 2]], dtype=object)

    See also
    --------
    sklearn.preprocessing.OneHotEncoder : performs a one-hot encoding of
      categorical features.
    sklearn.preprocessing.LabelEncoder : encodes target labels with values
      between 0 and n_classes-1.
    R!   c         C   s   | |  _  | |  _ d  S(   N(   RK   R   (   R   RK   R   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyRN     s    	c         C   s   |  j  |  _ |  j | ƒ |  S(   só   Fit the OrdinalEncoder to X.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features]
            The data to determine the categories of each feature.

        Returns
        -------
        self

        (   RK   R#   R4   (   R   R   Rg   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyRh     s    c         C   s+   |  j  | ƒ \ } } | j |  j d t ƒS(   s  Transform X to ordinal codes.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features]
            The data to encode.

        Returns
        -------
        X_out : sparse matrix or a 2-d array
            Transformed input.

        RA   (   RG   R@   R   RY   (   R   R   RC   RB   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyR†      s    c         C   s  t  |  d ƒ t | d d ƒ} | j \ } } t |  j ƒ } d } | j d | k rx t | j | | j d ƒ ƒ ‚ n  t j g  |  j D] } | j	 ^ qˆ g  ƒ } t j
 | | f d | ƒ} xT t | ƒ D]F }	 | d d … |	 f j d ƒ }
 |  j |	 |
 | d d … |	 f <qË W| S(	   sX  Convert the data back to the original representation.

        Parameters
        ----------
        X : array-like or sparse matrix, shape [n_samples, n_encoded_features]
            The transformed data.

        Returns
        -------
        X_tr : array-like, shape [n_samples, n_features]
            Inverse transformed array.

        R(   RŽ   R   sI   Shape of the passed X data is not correct. Expected {0} columns, got {1}.i   R   Nt   int64(   R
   R   R"   R'   R(   R   R*   R   R   R   Rm   R)   R@   (   R   R   R-   RB   R.   R3   R”   R•   R–   R0   R›   (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyRž   1  s    "+%N(
   RH   RI   RJ   R   R¦   RN   R   Rh   R†   Rž   (    (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyR   Ë  s
   ;	("   t
   __future__R    Rk   R[   t   numpyR   t   scipyR   t    R   R   t   baseR   R   t	   externalsR   t   utilsR   R   t   utils.fixesR   R	   t   utils.validationR
   R   t   labelR   R   t   movesR)   t   __all__R   R   R   (    (    (    s>   lib/python2.7/site-packages/sklearn/preprocessing/_encoders.pyt   <module>   s*   	`ÿ ÿ M