
\c           @   s  d  Z  d d l m Z d d l m Z m Z m Z d d l Z d d l m	 Z	 m
 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 m Z d d l m Z d d l m Z d d l m Z d d l m Z m Z m  Z  m! Z! d d l" m# Z# m$ Z$ d d l% m& Z& m' Z' m( Z( d d l) m* Z* m+ Z+ d d l m, Z, m- Z- d d l. m/ Z/ m0 Z0 d d l1 m2 Z2 d d l3 m4 Z4 d d d d d g Z5 e j6 e j7  j8 Z9 d   Z: d   Z; d e< d  Z= d  e j> e	 e,  f d!     YZ? d"   Z@ d# e j> e	 e? e  f d$     YZA d% e j> e	 e? e  f d&     YZB d eA f d'     YZC d eB f d(     YZD d eA f d)     YZE d eB f d*     YZF d e? f d+     YZG d S(,   s1  Forest of trees-based ensemble methods

Those methods include random forests and extremely randomized trees.

The module structure is the following:

- The ``BaseForest`` base class implements a common ``fit`` method for all
  the estimators in the module. The ``fit`` method of the base ``Forest``
  class calls the ``fit`` method of each sub-estimator on random samples
  (with replacement, a.k.a. bootstrap) of the training set.

  The init of the sub-estimator is further delegated to the
  ``BaseEnsemble`` constructor.

- The ``ForestClassifier`` and ``ForestRegressor`` base classes further
  implement the prediction logic by computing an average of the predicted
  outcomes of the sub-estimators.

- The ``RandomForestClassifier`` and ``RandomForestRegressor`` derived
  classes provide the user with concrete implementations of
  the forest ensemble method using classical, deterministic
  ``DecisionTreeClassifier`` and ``DecisionTreeRegressor`` as
  sub-estimator implementations.

- The ``ExtraTreesClassifier`` and ``ExtraTreesRegressor`` derived
  classes provide the user with concrete implementations of the
  forest ensemble method using the extremely randomized trees
  ``ExtraTreeClassifier`` and ``ExtraTreeRegressor`` as
  sub-estimator implementations.

Single and multi-output problems are both handled.

i(   t   division(   t   catch_warningst   simplefiltert   warnN(   t   ABCMetat   abstractmethod(   t   issparse(   t   hstacki   (   t   ClassifierMixint   RegressorMixin(   t   Parallelt   delayed(   t   six(   t   r2_score(   t   OneHotEncoder(   t   DecisionTreeClassifiert   DecisionTreeRegressort   ExtraTreeClassifiert   ExtraTreeRegressor(   t   DTYPEt   DOUBLE(   t   check_random_statet   check_arrayt   compute_sample_weight(   t   DataConversionWarningt   NotFittedErrori   (   t   BaseEnsemblet   _partition_estimators(   t   parallel_helpert   _joblib_parallel_args(   t   check_classification_targets(   t   check_is_fittedt   RandomForestClassifiert   RandomForestRegressort   ExtraTreesClassifiert   ExtraTreesRegressort   RandomTreesEmbeddingc         C   s%   t  |   } | j d | |  } | S(   s8   Private function used to _parallel_build_trees function.i    (   R   t   randint(   t   random_statet	   n_samplest   random_instancet   sample_indices(    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyt   _generate_sample_indicesL   s    c         C   sM   t  |  |  } t j | d | } | d k } t j |  } | | } | S(   s8   Private function used to forest._set_oob_score function.t	   minlengthi    (   R*   t   npt   bincountt   arange(   R&   R'   R)   t   sample_countst   unsampled_maskt   indices_ranget   unsampled_indices(    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyt   _generate_unsampled_indicesT   s    
i    c	      	   C   sE  | d k r" d | d | f GHn  | j  r%| j d }	 | d	 k rb t j |	 f d t j }
 n | j   }
 t |  j |	  } t j	 | d |	 } |
 | 9}
 | d k r t
   ( t d t  |
 t d | |  9}
 Wd	 QXn% | d
 k r|
 t d | |  9}
 n  |  j | | d |
 d t n |  j | | d | d t |  S(   s7   Private function used to fit a single tree in parallel.i   s   building tree %d of %di    t   dtypeR+   t	   subsamplet   ignoret   autoNt   balanced_subsamplet   balancedt   sample_weightt   check_input(   t	   bootstrapt   shapet   NoneR,   t   onest   float64t   copyR*   R&   R-   R   R   t   DeprecationWarningR   t   fitt   False(   t   treet   forestt   Xt   yR:   t   tree_idxt   n_treest   verboset   class_weightR'   t   curr_sample_weightt   indicesR/   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyt   _parallel_build_trees_   s&    	

t
   BaseForestc           B   s   e  Z d  Z e d e   e e d d d e d d 	  Z d   Z d   Z	 d d  Z
 e d    Z d   Z d	   Z e d
    Z RS(   s|   Base class for forests of trees.

    Warning: This class should not be used directly. Use derived classes
    instead.
    id   i    c         C   sh   t  t |   j d | d | d |  | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 |  _	 d  S(   Nt   base_estimatort   n_estimatorst   estimator_params(
   t   superRP   t   __init__R<   t	   oob_scoret   n_jobsR&   RK   t
   warm_startRL   (   t   selfRQ   RR   RS   R<   RV   RW   R&   RK   RX   RL   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU      s    						c            s_   |  j       t d |  j d |  j t d d     f d   |  j D  } t j |  j S(   sX  Apply trees in the forest to X, return leaf indices.

        Parameters
        ----------
        X : array-like or sparse matrix, shape = [n_samples, n_features]
            The input samples. Internally, its dtype will be converted to
            ``dtype=np.float32``. If a sparse matrix is provided, it will be
            converted into a sparse ``csr_matrix``.

        Returns
        -------
        X_leaves : array_like, shape = [n_samples, n_estimators]
            For each datapoint x in X and for each tree in the forest,
            return the index of the leaf x ends up in.
        RW   RK   t   prefert   threadsc         3   s-   |  ]# } t  t  | d    d t Vq d S(   t   applyR;   N(   R   R   RD   (   t   .0RE   (   RG   (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pys	   <genexpr>   s   (	   t   _validate_X_predictR
   RW   RK   R   t   estimators_R,   t   arrayt   T(   RY   RG   t   results(    (   RG   s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR\      s    c            s   |  j       t d |  j d |  j t d d     f d   |  j D  } d g } | j g  | D] } | j d ^ qe  t j	 |  j
   } t |  j   | f S(   s1  Return the decision path in the forest

        .. versionadded:: 0.18

        Parameters
        ----------
        X : array-like or sparse matrix, shape = [n_samples, n_features]
            The input samples. Internally, its dtype will be converted to
            ``dtype=np.float32``. If a sparse matrix is provided, it will be
            converted into a sparse ``csr_matrix``.

        Returns
        -------
        indicator : sparse csr array, shape = [n_samples, n_nodes]
            Return a node indicator matrix where non zero elements
            indicates that the samples goes through the nodes.

        n_nodes_ptr : array of size (n_estimators + 1, )
            The columns from indicator[n_nodes_ptr[i]:n_nodes_ptr[i+1]]
            gives the indicator value for the i-th estimator.

        RW   RK   RZ   R[   c         3   s-   |  ]# } t  t  | d    d t Vq d S(   t   decision_pathR;   N(   R   R   RD   (   R]   RE   (   RG   (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pys	   <genexpr>   s   i    i   (   R^   R
   RW   RK   R   R_   t   extendR=   R,   R`   t   cumsumt   sparse_hstackt   tocsr(   RY   RG   t
   indicatorst   n_nodest   it   n_nodes_ptr(    (   RG   s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRc      s    	'c   	         s   j  d k r( t d t  d  _  n  t   d d d t   t  d d d t d d   d k	 r t  d t  n  t    r   j   n    j	 d  _
 t j     j d	 k r  j	 d d k r t d
 t d d	 n   j d k rt j  d   n   j	 d  _  j   \  } t  d d  t k s] j j rut j  d t  n  | d k	 r d k	 r |  q|  n   j    j r j rt d   n  t  j  }  j st  d  rg   _ n   j  t   j  } | d k  rKt d  j  t   j  f   n | d k rdt d  n  j rt   j  d k r| j! t" d t   j  n  g   x9 t# |  D]+ }  j$ d t d |  }  j% |  qWt& d  j' d  j( t) d d         f d   t*   D    j j+    j r^ j,     n  t  d  r j d k r j- d  _-  j. d  _. n   S(   s0  Build a forest of trees from the training set (X, y).

        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The training input samples. Internally, its dtype will be converted
            to ``dtype=np.float32``. If a sparse matrix is provided, it will be
            converted into a sparse ``csc_matrix``.

        y : array-like, shape = [n_samples] or [n_samples, n_outputs]
            The target values (class labels in classification, real numbers in
            regression).

        sample_weight : array-like, shape = [n_samples] or None
            Sample weights. If None, then samples are equally weighted. Splits
            that would create child nodes with net zero or negative weight are
            ignored while searching for a split in each node. In the case of
            classification, splits are also ignored if they would result in any
            single class carrying a negative weight in either child node.

        Returns
        -------
        self : object
        R   sU   The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22.i
   t   accept_sparset   cscR4   t	   ensure_2di   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().t
   stacklevelis6   Out of bag estimation only available if bootstrap=TrueR_   i    sT   n_estimators=%d must be larger or equal to len(estimators_)=%d when warm_start==TruesJ   Warm-start fitting without increasing n_estimators does not fit new trees.t   sizet   appendR&   RW   RK   RZ   R[   c         3   sQ   |  ]G \ } } t  t  |      | t   d   j d  j Vq d S(   RK   RL   N(   R   RO   t   lenRK   RL   (   R]   Rj   t   t(   RG   R:   RY   t   treesRH   (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pys	   <genexpr>J  s   t   classes_N(   ii   (/   RR   R   t   FutureWarningR   R   RD   R>   R   t   sort_indicesR=   t   n_features_R,   t
   atleast_1dt   ndimR   t   reshapet
   n_outputs_t   _validate_y_class_weightt   getattrR   t   flagst
   contiguoust   ascontiguousarrayt   _validate_estimatorR<   RV   t
   ValueErrorR   R&   RX   t   hasattrR_   Rr   R%   t   MAX_INTt   ranget   _make_estimatorRq   R
   RW   RK   R   t	   enumerateRd   t   _set_oob_scoret
   n_classes_Ru   (	   RY   RG   RH   R:   t   expanded_class_weightR&   t   n_more_estimatorsRj   RE   (    (   RG   R:   RY   Rt   RH   s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRC      sn    "%	
		c         C   s   d S(   s+   Calculate out of bag predictions and score.N(    (   RY   RG   RH   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR   \  s    c         C   s
   | d  f S(   N(   R>   (   RY   RH   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR}   `  s    c         C   sM   |  j  d k s$ t |  j   d k r3 t d   n  |  j  d j | d t S(   s>   Validate X whenever one tries to predict, apply, predict_probai    s=   Estimator not fitted, call `fit` before exploiting the model.R;   N(   R_   R>   Rr   R   R^   t   True(   RY   RG   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR^   d  s    $c         C   sU   t  |  d  t d |  j t d d   d   |  j D  } t |  t |  j  S(   s   Return the feature importances (the higher, the more important the
           feature).

        Returns
        -------
        feature_importances_ : array, shape = [n_features]
        R_   RW   RZ   R[   c         s   s$   |  ] } t  t  | d   Vq d S(   t   feature_importances_N(   R   R~   (   R]   RE   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pys	   <genexpr>y  s   (   R   R
   RW   R   R_   t   sumRr   (   RY   t   all_importances(    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR   l  s    	N(   t   __name__t
   __module__t   __doc__R   t   tupleRD   R>   RU   R\   Rc   RC   R   R}   R^   t   propertyR   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRP   ~   s$   		$		c      
   C   sy   |  | d t  } | [ t |  d k r> | d c | 7<n1 x. t t |   D] } | | c | | 7<qQ WWd QXd S(   s   This is a utility function for joblib's Parallel.

    It can't go locally in ForestClassifier or ForestRegressor, because joblib
    complains that it cannot pickle it when placed there.
    R;   i   i    N(   RD   Rr   R   (   t   predictRG   t   outt   lockt
   predictionRj   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyt   _accumulate_prediction  s    t   ForestClassifierc           B   sh   e  Z d  Z e d e   e e d	 d	 d e d	 d 	  Z d   Z d   Z	 d   Z
 d   Z d   Z RS(
   s   Base class for forest of trees-based classifiers.

    Warning: This class should not be used directly. Use derived classes
    instead.
    id   i    c         C   sP   t  t |   j | d | d | d | d | d | d | d | d |	 d	 |
 	d  S(
   NRR   RS   R<   RV   RW   R&   RK   RX   RL   (   RT   R   RU   (   RY   RQ   RR   RS   R<   RV   RW   R&   RK   RX   RL   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU     s    c         C   s#  t  | d t d d } |  j } | j d } g  } d } g  } x7 t |  j  D]& } | j t j | | | f   qP Wx |  j	 D] }	 t
 |	 j |  }
 |	 j | |
 d d  f d t } |  j d k r | g } n  x; t |  j  D]* } | | |
 d d  f c | | 7<q Wq Wx t |  j  D] } | | j d	 d  d k j   rct d
  n  | | | | j d	 d  d d  t j f } | j |  | t j | d d  | f t j | | d	 d k d	 d 7} q.W|  j d k r| d |  _ n	 | |  _ | |  j |  _ d S(   s   Compute out-of-bag scoreR4   Rl   t   csri    g        NR;   i   t   axissv   Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.(   R   R   R   R=   R   R|   Rq   R,   t   zerosR_   R3   R&   t   predict_probaRD   R   t   anyR   t   newaxist   meant   argmaxt   oob_decision_function_t
   oob_score_(   RY   RG   RH   R   R'   t   oob_decision_functionRV   t   predictionst   kt	   estimatorR2   t   p_estimatort   decision(    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s:    	$	,"**	c   	      C   s  t  |  t j |  } d  } |  j d  k	 r@ t j |  } n  g  |  _ g  |  _ t j | j d t j	 } xy t
 |  j  D]h } t j | d  d   | f d t \ } | d  d   | f <|  j j |  |  j j | j d  q} W| } |  j d  k	 rd } t |  j t j  rW|  j | k r>t d |  j   n  |  j rWt d  qWn  |  j d k sp|  j r|  j d k rd } n	 |  j } t | |  } qn  | | f S(	   NR4   t   return_inversei    R9   R8   sW   Valid presets for class_weight include "balanced" and "balanced_subsample". Given "%s".s  class_weight presets "balanced" or "balanced_subsample" are not recommended for warm_start if the fitted data differs from the full dataset. In order to use "balanced" weights, use compute_class_weight("balanced", classes, y). In place of y you can use a large enough sample of the full training set target to properly estimate the class frequency distributions. Pass the resulting weights as the class_weight parameter.(   R9   R8   (   R   R,   RA   R>   RL   Ru   R   R   R=   t   intR   R|   t   uniqueR   Rq   t
   isinstanceR   t   string_typesR   RX   R   R<   R   (	   RY   RH   R   t
   y_originalt   y_store_unique_indicesR   t	   classes_kt   valid_presetsRL   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR}     s:    
		;	

		c         C   s   |  j  |  } |  j d k rC |  j j t j | d d d d S| d j d } t j | |  j f  } xV t |  j  D]E } |  j | j t j | | d d d d | d d  | f <q| W| Sd S(   s  Predict class for X.

        The predicted class of an input sample is a vote by the trees in
        the forest, weighted by their probability estimates. That is,
        the predicted class is the one with highest mean probability
        estimate across the trees.

        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The input samples. Internally, its dtype will be converted to
            ``dtype=np.float32``. If a sparse matrix is provided, it will be
            converted into a sparse ``csr_matrix``.

        Returns
        -------
        y : array of shape = [n_samples] or [n_samples, n_outputs]
            The predicted classes.
        i   R   i    N(	   R   R|   Ru   t   takeR,   R   R=   R   R   (   RY   RG   t   probaR'   R   R   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s    %	c            s  t  |  d  |  j      t |  j |  j  \ } } } g  t j |  j  D]+ } t j   j	 d | f d t j
 ^ qM  t j    t d | d |  j t d d       f d   |  j D  x!  D] } | t |  j  } q Wt   d	 k r	 d S Sd
 S(   s  Predict class probabilities for X.

        The predicted class probabilities of an input sample are computed as
        the mean predicted class probabilities of the trees in the forest. The
        class probability of a single tree is the fraction of samples of the same
        class in a leaf.

        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The input samples. Internally, its dtype will be converted to
            ``dtype=np.float32``. If a sparse matrix is provided, it will be
            converted into a sparse ``csr_matrix``.

        Returns
        -------
        p : array of shape = [n_samples, n_classes], or a list of n_outputs
            such arrays if n_outputs > 1.
            The class probabilities of the input samples. The order of the
            classes corresponds to that in the attribute `classes_`.
        R_   i    R4   RW   RK   t   requiret	   sharedmemc         3   s-   |  ]# } t  t  | j      Vq d  S(   N(   R   R   R   (   R]   t   e(   RG   t	   all_probaR   (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pys	   <genexpr>R  s   i   N(   R   R^   R   RR   RW   R,   Ry   R   R   R=   R@   t	   threadingt   LockR
   RK   R   R_   Rr   (   RY   RG   RW   t   _t   jR   (    (   RG   R   R   s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR   /  s    Ac         C   sd   |  j  |  } |  j d k r+ t j |  Sx. t |  j  D] } t j | |  | | <q; W| Sd S(   sB  Predict class log-probabilities for X.

        The predicted class log-probabilities of an input sample is computed as
        the log of the mean predicted class probabilities of the trees in the
        forest.

        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The input samples. Internally, its dtype will be converted to
            ``dtype=np.float32``. If a sparse matrix is provided, it will be
            converted into a sparse ``csr_matrix``.

        Returns
        -------
        p : array of shape = [n_samples, n_classes], or a list of n_outputs
            such arrays if n_outputs > 1.
            The class probabilities of the input samples. The order of the
            classes corresponds to that in the attribute `classes_`.
        i   N(   R   R|   R,   t   logR   (   RY   RG   R   R   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyt   predict_log_proba^  s    N(   R   R   R   R   R   RD   R>   RU   R   R}   R   R   R   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s    	-	0	$	/t   ForestRegressorc        
   B   sJ   e  Z d  Z e d e   e e d d d e d   Z d   Z d   Z	 RS(   s   Base class for forest of trees-based regressors.

    Warning: This class should not be used directly. Use derived classes
    instead.
    id   i    c
   
      C   sJ   t  t |   j | d | d | d | d | d | d | d | d |	 d  S(	   NRR   RS   R<   RV   RW   R&   RK   RX   (   RT   R   RU   (
   RY   RQ   RR   RS   R<   RV   RW   R&   RK   RX   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU     s    c            s   t  |  d  |  j      t |  j |  j  \ } } } |  j d k rt t j   j d |  j f d t j	  n t j   j d d t j	  t
 j    t d | d |  j t d d       f d	   |  j D   t |  j    S(
   s  Predict regression target for X.

        The predicted regression target of an input sample is computed as the
        mean predicted regression targets of the trees in the forest.

        Parameters
        ----------
        X : array-like or sparse matrix of shape = [n_samples, n_features]
            The input samples. Internally, its dtype will be converted to
            ``dtype=np.float32``. If a sparse matrix is provided, it will be
            converted into a sparse ``csr_matrix``.

        Returns
        -------
        y : array of shape = [n_samples] or [n_samples, n_outputs]
            The predicted values.
        R_   i   i    R4   RW   RK   R   R   c         3   s0   |  ]& } t  t  | j    g   Vq d  S(   N(   R   R   R   (   R]   R   (   RG   R   t   y_hat(    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pys	   <genexpr>  s   (   R   R^   R   RR   RW   R|   R,   R   R=   R@   R   R   R
   RK   R   R_   Rr   (   RY   RG   RW   R   (    (   RG   R   R   s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s    +c   
      C   s  t  | d t d d } | j d } t j | |  j f  } t j | |  j f  } x |  j D] } t | j |  } | j	 | | d d  f d t
 } |  j d k r | d d  t j f } n  | | d d  f c | 7<| | d d  f c d 7<q_ W| d k j   r2t d  d | | d k <n  | | } | |  _ |  j d k ro|  j j | f  |  _ n  d	 |  _ xO t |  j  D]> }	 |  j t | d d  |	 f | d d  |	 f  7_ qW|  j |  j _ d S(
   s   Compute out-of-bag scoresR4   Rl   R   i    NR;   i   sv   Some inputs do not have OOB scores. This probably means too few trees were used to compute any reliable oob estimates.g        (   R   R   R=   R,   R   R|   R_   R3   R&   R   RD   R   R   R   t   oob_prediction_R{   R   R   R   (
   RY   RG   RH   R'   R   t   n_predictionsR   R2   R   R   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s2     

		N(
   R   R   R   R   R   RD   R>   RU   R   R   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s   	*c           B   sJ   e  Z d  Z d d d	 d d d d d	 d d	 e e d	 d	 d e d	 d  Z RS(
   sx*  A random forest classifier.

    A random forest is a meta estimator that fits a number of decision tree
    classifiers on various sub-samples of the dataset and uses averaging to
    improve the predictive accuracy and control over-fitting.
    The sub-sample size is always the same as the original
    input sample size but the samples are drawn with replacement if
    `bootstrap=True` (default).

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

    Parameters
    ----------
    n_estimators : integer, optional (default=10)
        The number of trees in the forest.

        .. versionchanged:: 0.20
           The default value of ``n_estimators`` will change from 10 in
           version 0.20 to 100 in version 0.22.

    criterion : string, optional (default="gini")
        The function to measure the quality of a split. Supported criteria are
        "gini" for the Gini impurity and "entropy" for the information gain.
        Note: this parameter is tree-specific.

    max_depth : integer or None, optional (default=None)
        The maximum depth of the tree. If None, then nodes are expanded until
        all leaves are pure or until all leaves contain less than
        min_samples_split samples.

    min_samples_split : int, float, optional (default=2)
        The minimum number of samples required to split an internal node:

        - If int, then consider `min_samples_split` as the minimum number.
        - If float, then `min_samples_split` is a fraction and
          `ceil(min_samples_split * n_samples)` are the minimum
          number of samples for each split.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_samples_leaf : int, float, optional (default=1)
        The minimum number of samples required to be at a leaf node.
        A split point at any depth will only be considered if it leaves at
        least ``min_samples_leaf`` training samples in each of the left and
        right branches.  This may have the effect of smoothing the model,
        especially in regression.

        - If int, then consider `min_samples_leaf` as the minimum number.
        - If float, then `min_samples_leaf` is a fraction and
          `ceil(min_samples_leaf * n_samples)` are the minimum
          number of samples for each node.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_weight_fraction_leaf : float, optional (default=0.)
        The minimum weighted fraction of the sum total of weights (of all
        the input samples) required to be at a leaf node. Samples have
        equal weight when sample_weight is not provided.

    max_features : int, float, string or None, optional (default="auto")
        The number of features to consider when looking for the best split:

        - If int, then consider `max_features` features at each split.
        - If float, then `max_features` is a fraction and
          `int(max_features * n_features)` features are considered at each
          split.
        - If "auto", then `max_features=sqrt(n_features)`.
        - If "sqrt", then `max_features=sqrt(n_features)` (same as "auto").
        - If "log2", then `max_features=log2(n_features)`.
        - If None, then `max_features=n_features`.

        Note: the search for a split does not stop until at least one
        valid partition of the node samples is found, even if it requires to
        effectively inspect more than ``max_features`` features.

    max_leaf_nodes : int or None, optional (default=None)
        Grow trees with ``max_leaf_nodes`` in best-first fashion.
        Best nodes are defined as relative reduction in impurity.
        If None then unlimited number of leaf nodes.

    min_impurity_decrease : float, optional (default=0.)
        A node will be split if this split induces a decrease of the impurity
        greater than or equal to this value.

        The weighted impurity decrease equation is the following::

            N_t / N * (impurity - N_t_R / N_t * right_impurity
                                - N_t_L / N_t * left_impurity)

        where ``N`` is the total number of samples, ``N_t`` is the number of
        samples at the current node, ``N_t_L`` is the number of samples in the
        left child, and ``N_t_R`` is the number of samples in the right child.

        ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,
        if ``sample_weight`` is passed.

        .. versionadded:: 0.19

    min_impurity_split : float, (default=1e-7)
        Threshold for early stopping in tree growth. A node will split
        if its impurity is above the threshold, otherwise it is a leaf.

        .. deprecated:: 0.19
           ``min_impurity_split`` has been deprecated in favor of
           ``min_impurity_decrease`` in 0.19. The default value of
           ``min_impurity_split`` will change from 1e-7 to 0 in 0.23 and it
           will be removed in 0.25. Use ``min_impurity_decrease`` instead.


    bootstrap : boolean, optional (default=True)
        Whether bootstrap samples are used when building trees. If False, the
        whole datset is used to build each tree.

    oob_score : bool (default=False)
        Whether to use out-of-bag samples to estimate
        the generalization accuracy.

    n_jobs : int or None, optional (default=None)
        The number of jobs to run in parallel for both `fit` and `predict`.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    verbose : int, optional (default=0)
        Controls the verbosity when fitting and predicting.

    warm_start : bool, optional (default=False)
        When set to ``True``, reuse the solution of the previous call to fit
        and add more estimators to the ensemble, otherwise, just fit a whole
        new forest. See :term:`the Glossary <warm_start>`.

    class_weight : dict, list of dicts, "balanced", "balanced_subsample" or     None, optional (default=None)
        Weights associated with classes in the form ``{class_label: weight}``.
        If not given, all classes are supposed to have weight one. For
        multi-output problems, a list of dicts can be provided in the same
        order as the columns of y.

        Note that for multioutput (including multilabel) weights should be
        defined for each class of every column in its own dict. For example,
        for four-class multilabel classification weights should be
        [{0: 1, 1: 1}, {0: 1, 1: 5}, {0: 1, 1: 1}, {0: 1, 1: 1}] instead of
        [{1:1}, {2:5}, {3:1}, {4:1}].

        The "balanced" mode uses the values of y to automatically adjust
        weights inversely proportional to class frequencies in the input data
        as ``n_samples / (n_classes * np.bincount(y))``

        The "balanced_subsample" mode is the same as "balanced" except that
        weights are computed based on the bootstrap sample for every tree
        grown.

        For multi-output, the weights of each column of y will be multiplied.

        Note that these weights will be multiplied with sample_weight (passed
        through the fit method) if sample_weight is specified.

    Attributes
    ----------
    estimators_ : list of DecisionTreeClassifier
        The collection of fitted sub-estimators.

    classes_ : array of shape = [n_classes] or a list of such arrays
        The classes labels (single output problem), or a list of arrays of
        class labels (multi-output problem).

    n_classes_ : int or list
        The number of classes (single output problem), or a list containing the
        number of classes for each output (multi-output problem).

    n_features_ : int
        The number of features when ``fit`` is performed.

    n_outputs_ : int
        The number of outputs when ``fit`` is performed.

    feature_importances_ : array of shape = [n_features]
        The feature importances (the higher, the more important the feature).

    oob_score_ : float
        Score of the training dataset obtained using an out-of-bag estimate.

    oob_decision_function_ : array of shape = [n_samples, n_classes]
        Decision function computed with out-of-bag estimate on the training
        set. If n_estimators is small it might be possible that a data point
        was never left out during the bootstrap. In this case,
        `oob_decision_function_` might contain NaN.

    Examples
    --------
    >>> from sklearn.ensemble import RandomForestClassifier
    >>> from sklearn.datasets import make_classification

    >>> X, y = make_classification(n_samples=1000, n_features=4,
    ...                            n_informative=2, n_redundant=0,
    ...                            random_state=0, shuffle=False)
    >>> clf = RandomForestClassifier(n_estimators=100, max_depth=2,
    ...                              random_state=0)
    >>> clf.fit(X, y)
    RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
                max_depth=2, max_features='auto', max_leaf_nodes=None,
                min_impurity_decrease=0.0, min_impurity_split=None,
                min_samples_leaf=1, min_samples_split=2,
                min_weight_fraction_leaf=0.0, n_estimators=100, n_jobs=None,
                oob_score=False, random_state=0, verbose=0, warm_start=False)
    >>> print(clf.feature_importances_)
    [0.14205973 0.76664038 0.0282433  0.06305659]
    >>> print(clf.predict([[0, 0, 0, 0]]))
    [1]

    Notes
    -----
    The default values for the parameters controlling the size of the trees
    (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and
    unpruned trees which can potentially be very large on some data sets. To
    reduce memory consumption, the complexity and size of the trees should be
    controlled by setting those parameter values.

    The features are always randomly permuted at each split. Therefore,
    the best found split may vary, even with the same training data,
    ``max_features=n_features`` and ``bootstrap=False``, if the improvement
    of the criterion is identical for several splits enumerated during the
    search of the best split. To obtain a deterministic behaviour during
    fitting, ``random_state`` has to be fixed.

    References
    ----------

    .. [1] L. Breiman, "Random Forests", Machine Learning, 45(1), 5-32, 2001.

    See also
    --------
    DecisionTreeClassifier, ExtraTreesClassifier
    R   t   ginii   i   g        R7   i    c         C   s   t  t |   j d t   d | d d d | d | d | d | d | d | d |  
| |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |	 |  _ |
 |  _ d  S(   NRQ   RR   RS   t	   criteriont	   max_deptht   min_samples_splitt   min_samples_leaft   min_weight_fraction_leaft   max_featurest   max_leaf_nodest   min_impurity_decreaset   min_impurity_splitR&   R<   RV   RW   RK   RX   RL   (
   R   R   R   R   R   R   R   R   R   R&   (   RT   R    RU   R   R   R   R   R   R   R   R   R   R   (   RY   RR   R   R   R   R   R   R   R   R   R   R<   RV   RW   R&   RK   RX   RL   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU     s0    	    								N(   R   R   R   R>   R   RD   RU   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR      s$   c           B   sG   e  Z d  Z d d d	 d d d d d	 d d	 e e d	 d	 d e d  Z RS(
   s$  A random forest regressor.

    A random forest is a meta estimator that fits a number of classifying
    decision trees on various sub-samples of the dataset and uses averaging
    to improve the predictive accuracy and control over-fitting.
    The sub-sample size is always the same as the original
    input sample size but the samples are drawn with replacement if
    `bootstrap=True` (default).

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

    Parameters
    ----------
    n_estimators : integer, optional (default=10)
        The number of trees in the forest.

        .. versionchanged:: 0.20
           The default value of ``n_estimators`` will change from 10 in
           version 0.20 to 100 in version 0.22.

    criterion : string, optional (default="mse")
        The function to measure the quality of a split. Supported criteria
        are "mse" for the mean squared error, which is equal to variance
        reduction as feature selection criterion, and "mae" for the mean
        absolute error.

        .. versionadded:: 0.18
           Mean Absolute Error (MAE) criterion.

    max_depth : integer or None, optional (default=None)
        The maximum depth of the tree. If None, then nodes are expanded until
        all leaves are pure or until all leaves contain less than
        min_samples_split samples.

    min_samples_split : int, float, optional (default=2)
        The minimum number of samples required to split an internal node:

        - If int, then consider `min_samples_split` as the minimum number.
        - If float, then `min_samples_split` is a fraction and
          `ceil(min_samples_split * n_samples)` are the minimum
          number of samples for each split.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_samples_leaf : int, float, optional (default=1)
        The minimum number of samples required to be at a leaf node.
        A split point at any depth will only be considered if it leaves at
        least ``min_samples_leaf`` training samples in each of the left and
        right branches.  This may have the effect of smoothing the model,
        especially in regression.

        - If int, then consider `min_samples_leaf` as the minimum number.
        - If float, then `min_samples_leaf` is a fraction and
          `ceil(min_samples_leaf * n_samples)` are the minimum
          number of samples for each node.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_weight_fraction_leaf : float, optional (default=0.)
        The minimum weighted fraction of the sum total of weights (of all
        the input samples) required to be at a leaf node. Samples have
        equal weight when sample_weight is not provided.

    max_features : int, float, string or None, optional (default="auto")
        The number of features to consider when looking for the best split:

        - If int, then consider `max_features` features at each split.
        - If float, then `max_features` is a fraction and
          `int(max_features * n_features)` features are considered at each
          split.
        - If "auto", then `max_features=n_features`.
        - If "sqrt", then `max_features=sqrt(n_features)`.
        - If "log2", then `max_features=log2(n_features)`.
        - If None, then `max_features=n_features`.

        Note: the search for a split does not stop until at least one
        valid partition of the node samples is found, even if it requires to
        effectively inspect more than ``max_features`` features.

    max_leaf_nodes : int or None, optional (default=None)
        Grow trees with ``max_leaf_nodes`` in best-first fashion.
        Best nodes are defined as relative reduction in impurity.
        If None then unlimited number of leaf nodes.

    min_impurity_decrease : float, optional (default=0.)
        A node will be split if this split induces a decrease of the impurity
        greater than or equal to this value.

        The weighted impurity decrease equation is the following::

            N_t / N * (impurity - N_t_R / N_t * right_impurity
                                - N_t_L / N_t * left_impurity)

        where ``N`` is the total number of samples, ``N_t`` is the number of
        samples at the current node, ``N_t_L`` is the number of samples in the
        left child, and ``N_t_R`` is the number of samples in the right child.

        ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,
        if ``sample_weight`` is passed.

        .. versionadded:: 0.19

    min_impurity_split : float, (default=1e-7)
        Threshold for early stopping in tree growth. A node will split
        if its impurity is above the threshold, otherwise it is a leaf.

        .. deprecated:: 0.19
           ``min_impurity_split`` has been deprecated in favor of
           ``min_impurity_decrease`` in 0.19. The default value of
           ``min_impurity_split`` will change from 1e-7 to 0 in 0.23 and it
           will be removed in 0.25. Use ``min_impurity_decrease`` instead.

    bootstrap : boolean, optional (default=True)
        Whether bootstrap samples are used when building trees. If False, the
        whole datset is used to build each tree.

    oob_score : bool, optional (default=False)
        whether to use out-of-bag samples to estimate
        the R^2 on unseen data.

    n_jobs : int or None, optional (default=None)
        The number of jobs to run in parallel for both `fit` and `predict`.
        `None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    verbose : int, optional (default=0)
        Controls the verbosity when fitting and predicting.

    warm_start : bool, optional (default=False)
        When set to ``True``, reuse the solution of the previous call to fit
        and add more estimators to the ensemble, otherwise, just fit a whole
        new forest. See :term:`the Glossary <warm_start>`.

    Attributes
    ----------
    estimators_ : list of DecisionTreeRegressor
        The collection of fitted sub-estimators.

    feature_importances_ : array of shape = [n_features]
        The feature importances (the higher, the more important the feature).

    n_features_ : int
        The number of features when ``fit`` is performed.

    n_outputs_ : int
        The number of outputs when ``fit`` is performed.

    oob_score_ : float
        Score of the training dataset obtained using an out-of-bag estimate.

    oob_prediction_ : array of shape = [n_samples]
        Prediction computed with out-of-bag estimate on the training set.

    Examples
    --------
    >>> from sklearn.ensemble import RandomForestRegressor
    >>> from sklearn.datasets import make_regression

    >>> X, y = make_regression(n_features=4, n_informative=2,
    ...                        random_state=0, shuffle=False)
    >>> regr = RandomForestRegressor(max_depth=2, random_state=0,
    ...                              n_estimators=100)
    >>> regr.fit(X, y)
    RandomForestRegressor(bootstrap=True, criterion='mse', max_depth=2,
               max_features='auto', max_leaf_nodes=None,
               min_impurity_decrease=0.0, min_impurity_split=None,
               min_samples_leaf=1, min_samples_split=2,
               min_weight_fraction_leaf=0.0, n_estimators=100, n_jobs=None,
               oob_score=False, random_state=0, verbose=0, warm_start=False)
    >>> print(regr.feature_importances_)
    [0.18146984 0.81473937 0.00145312 0.00233767]
    >>> print(regr.predict([[0, 0, 0, 0]]))
    [-8.32987858]

    Notes
    -----
    The default values for the parameters controlling the size of the trees
    (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and
    unpruned trees which can potentially be very large on some data sets. To
    reduce memory consumption, the complexity and size of the trees should be
    controlled by setting those parameter values.

    The features are always randomly permuted at each split. Therefore,
    the best found split may vary, even with the same training data,
    ``max_features=n_features`` and ``bootstrap=False``, if the improvement
    of the criterion is identical for several splits enumerated during the
    search of the best split. To obtain a deterministic behaviour during
    fitting, ``random_state`` has to be fixed.

    The default value ``max_features="auto"`` uses ``n_features`` 
    rather than ``n_features / 3``. The latter was originally suggested in
    [1], whereas the former was more recently justified empirically in [2].

    References
    ----------

    .. [1] L. Breiman, "Random Forests", Machine Learning, 45(1), 5-32, 2001.

    .. [2] P. Geurts, D. Ernst., and L. Wehenkel, "Extremely randomized 
           trees", Machine Learning, 63(1), 3-42, 2006.

    See also
    --------
    DecisionTreeRegressor, ExtraTreesRegressor
    R   t   msei   i   g        R7   i    c         C   s   t  t |   j d t   d | d d d | d | d | d | d | d |  	| |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |	 |  _ |
 |  _ d  S(   NRQ   RR   RS   R   R   R   R   R   R   R   R   R   R&   R<   RV   RW   RK   RX   (
   R   R   R   R   R   R   R   R   R   R&   (   RT   R!   RU   R   R   R   R   R   R   R   R   R   R   (   RY   RR   R   R   R   R   R   R   R   R   R   R<   RV   RW   R&   RK   RX   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU     s.    	    								N(   R   R   R   R>   R   RD   RU   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR!     s"   c           B   sJ   e  Z d  Z d d d	 d d d d d	 d d	 e e d	 d	 d e d	 d  Z RS(
   s$  An extra-trees classifier.

    This class implements a meta estimator that fits a number of
    randomized decision trees (a.k.a. extra-trees) on various sub-samples
    of the dataset and uses averaging to improve the predictive accuracy
    and control over-fitting.

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

    Parameters
    ----------
    n_estimators : integer, optional (default=10)
        The number of trees in the forest.

        .. versionchanged:: 0.20
           The default value of ``n_estimators`` will change from 10 in
           version 0.20 to 100 in version 0.22.

    criterion : string, optional (default="gini")
        The function to measure the quality of a split. Supported criteria are
        "gini" for the Gini impurity and "entropy" for the information gain.

    max_depth : integer or None, optional (default=None)
        The maximum depth of the tree. If None, then nodes are expanded until
        all leaves are pure or until all leaves contain less than
        min_samples_split samples.

    min_samples_split : int, float, optional (default=2)
        The minimum number of samples required to split an internal node:

        - If int, then consider `min_samples_split` as the minimum number.
        - If float, then `min_samples_split` is a fraction and
          `ceil(min_samples_split * n_samples)` are the minimum
          number of samples for each split.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_samples_leaf : int, float, optional (default=1)
        The minimum number of samples required to be at a leaf node.
        A split point at any depth will only be considered if it leaves at
        least ``min_samples_leaf`` training samples in each of the left and
        right branches.  This may have the effect of smoothing the model,
        especially in regression.

        - If int, then consider `min_samples_leaf` as the minimum number.
        - If float, then `min_samples_leaf` is a fraction and
          `ceil(min_samples_leaf * n_samples)` are the minimum
          number of samples for each node.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_weight_fraction_leaf : float, optional (default=0.)
        The minimum weighted fraction of the sum total of weights (of all
        the input samples) required to be at a leaf node. Samples have
        equal weight when sample_weight is not provided.

    max_features : int, float, string or None, optional (default="auto")
        The number of features to consider when looking for the best split:

        - If int, then consider `max_features` features at each split.
        - If float, then `max_features` is a fraction and
          `int(max_features * n_features)` features are considered at each
          split.
        - If "auto", then `max_features=sqrt(n_features)`.
        - If "sqrt", then `max_features=sqrt(n_features)`.
        - If "log2", then `max_features=log2(n_features)`.
        - If None, then `max_features=n_features`.

        Note: the search for a split does not stop until at least one
        valid partition of the node samples is found, even if it requires to
        effectively inspect more than ``max_features`` features.

    max_leaf_nodes : int or None, optional (default=None)
        Grow trees with ``max_leaf_nodes`` in best-first fashion.
        Best nodes are defined as relative reduction in impurity.
        If None then unlimited number of leaf nodes.

    min_impurity_decrease : float, optional (default=0.)
        A node will be split if this split induces a decrease of the impurity
        greater than or equal to this value.

        The weighted impurity decrease equation is the following::

            N_t / N * (impurity - N_t_R / N_t * right_impurity
                                - N_t_L / N_t * left_impurity)

        where ``N`` is the total number of samples, ``N_t`` is the number of
        samples at the current node, ``N_t_L`` is the number of samples in the
        left child, and ``N_t_R`` is the number of samples in the right child.

        ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,
        if ``sample_weight`` is passed.

        .. versionadded:: 0.19

    min_impurity_split : float, (default=1e-7)
        Threshold for early stopping in tree growth. A node will split
        if its impurity is above the threshold, otherwise it is a leaf.

        .. deprecated:: 0.19
           ``min_impurity_split`` has been deprecated in favor of
           ``min_impurity_decrease`` in 0.19. The default value of
           ``min_impurity_split`` will change from 1e-7 to 0 in 0.23 and it
           will be removed in 0.25. Use ``min_impurity_decrease`` instead.

    bootstrap : boolean, optional (default=False)
        Whether bootstrap samples are used when building trees. If False, the
        whole datset is used to build each tree.

    oob_score : bool, optional (default=False)
        Whether to use out-of-bag samples to estimate
        the generalization accuracy.

    n_jobs : int or None, optional (default=None)
        The number of jobs to run in parallel for both `fit` and `predict`.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    verbose : int, optional (default=0)
        Controls the verbosity when fitting and predicting.

    warm_start : bool, optional (default=False)
        When set to ``True``, reuse the solution of the previous call to fit
        and add more estimators to the ensemble, otherwise, just fit a whole
        new forest. See :term:`the Glossary <warm_start>`.

    class_weight : dict, list of dicts, "balanced", "balanced_subsample" or     None, optional (default=None)
        Weights associated with classes in the form ``{class_label: weight}``.
        If not given, all classes are supposed to have weight one. For
        multi-output problems, a list of dicts can be provided in the same
        order as the columns of y.

        Note that for multioutput (including multilabel) weights should be
        defined for each class of every column in its own dict. For example,
        for four-class multilabel classification weights should be
        [{0: 1, 1: 1}, {0: 1, 1: 5}, {0: 1, 1: 1}, {0: 1, 1: 1}] instead of
        [{1:1}, {2:5}, {3:1}, {4:1}].

        The "balanced" mode uses the values of y to automatically adjust
        weights inversely proportional to class frequencies in the input data
        as ``n_samples / (n_classes * np.bincount(y))``

        The "balanced_subsample" mode is the same as "balanced" except that weights are
        computed based on the bootstrap sample for every tree grown.

        For multi-output, the weights of each column of y will be multiplied.

        Note that these weights will be multiplied with sample_weight (passed
        through the fit method) if sample_weight is specified.

    Attributes
    ----------
    estimators_ : list of DecisionTreeClassifier
        The collection of fitted sub-estimators.

    classes_ : array of shape = [n_classes] or a list of such arrays
        The classes labels (single output problem), or a list of arrays of
        class labels (multi-output problem).

    n_classes_ : int or list
        The number of classes (single output problem), or a list containing the
        number of classes for each output (multi-output problem).

    feature_importances_ : array of shape = [n_features]
        The feature importances (the higher, the more important the feature).

    n_features_ : int
        The number of features when ``fit`` is performed.

    n_outputs_ : int
        The number of outputs when ``fit`` is performed.

    oob_score_ : float
        Score of the training dataset obtained using an out-of-bag estimate.

    oob_decision_function_ : array of shape = [n_samples, n_classes]
        Decision function computed with out-of-bag estimate on the training
        set. If n_estimators is small it might be possible that a data point
        was never left out during the bootstrap. In this case,
        `oob_decision_function_` might contain NaN.

    Notes
    -----
    The default values for the parameters controlling the size of the trees
    (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and
    unpruned trees which can potentially be very large on some data sets. To
    reduce memory consumption, the complexity and size of the trees should be
    controlled by setting those parameter values.

    References
    ----------

    .. [1] P. Geurts, D. Ernst., and L. Wehenkel, "Extremely randomized 
           trees", Machine Learning, 63(1), 3-42, 2006.

    See also
    --------
    sklearn.tree.ExtraTreeClassifier : Base classifier for this ensemble.
    RandomForestClassifier : Ensemble Classifier based on trees with optimal
        splits.
    R   R   i   i   g        R7   i    c         C   s   t  t |   j d t   d | d d d | d | d | d | d | d | d |  
| |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |	 |  _ |
 |  _ d  S(   NRQ   RR   RS   R   R   R   R   R   R   R   R   R   R&   R<   RV   RW   RK   RX   RL   (
   R   R   R   R   R   R   R   R   R   R&   (   RT   R"   RU   R   R   R   R   R   R   R   R   R   R   (   RY   RR   R   R   R   R   R   R   R   R   R   R<   RV   RW   R&   RK   RX   RL   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU     s0    	    								N(   R   R   R   R>   RD   RU   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR"     s$   c           B   sG   e  Z d  Z d d d	 d d d d d	 d d	 e e d	 d	 d e d  Z RS(
   s  An extra-trees regressor.

    This class implements a meta estimator that fits a number of
    randomized decision trees (a.k.a. extra-trees) on various sub-samples
    of the dataset and uses averaging to improve the predictive accuracy
    and control over-fitting.

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

    Parameters
    ----------
    n_estimators : integer, optional (default=10)
        The number of trees in the forest.

        .. versionchanged:: 0.20
           The default value of ``n_estimators`` will change from 10 in
           version 0.20 to 100 in version 0.22.

    criterion : string, optional (default="mse")
        The function to measure the quality of a split. Supported criteria
        are "mse" for the mean squared error, which is equal to variance
        reduction as feature selection criterion, and "mae" for the mean
        absolute error.

        .. versionadded:: 0.18
           Mean Absolute Error (MAE) criterion.

    max_depth : integer or None, optional (default=None)
        The maximum depth of the tree. If None, then nodes are expanded until
        all leaves are pure or until all leaves contain less than
        min_samples_split samples.

    min_samples_split : int, float, optional (default=2)
        The minimum number of samples required to split an internal node:

        - If int, then consider `min_samples_split` as the minimum number.
        - If float, then `min_samples_split` is a fraction and
          `ceil(min_samples_split * n_samples)` are the minimum
          number of samples for each split.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_samples_leaf : int, float, optional (default=1)
        The minimum number of samples required to be at a leaf node.
        A split point at any depth will only be considered if it leaves at
        least ``min_samples_leaf`` training samples in each of the left and
        right branches.  This may have the effect of smoothing the model,
        especially in regression.

        - If int, then consider `min_samples_leaf` as the minimum number.
        - If float, then `min_samples_leaf` is a fraction and
          `ceil(min_samples_leaf * n_samples)` are the minimum
          number of samples for each node.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_weight_fraction_leaf : float, optional (default=0.)
        The minimum weighted fraction of the sum total of weights (of all
        the input samples) required to be at a leaf node. Samples have
        equal weight when sample_weight is not provided.

    max_features : int, float, string or None, optional (default="auto")
        The number of features to consider when looking for the best split:

        - If int, then consider `max_features` features at each split.
        - If float, then `max_features` is a fraction and
          `int(max_features * n_features)` features are considered at each
          split.
        - If "auto", then `max_features=n_features`.
        - If "sqrt", then `max_features=sqrt(n_features)`.
        - If "log2", then `max_features=log2(n_features)`.
        - If None, then `max_features=n_features`.

        Note: the search for a split does not stop until at least one
        valid partition of the node samples is found, even if it requires to
        effectively inspect more than ``max_features`` features.

    max_leaf_nodes : int or None, optional (default=None)
        Grow trees with ``max_leaf_nodes`` in best-first fashion.
        Best nodes are defined as relative reduction in impurity.
        If None then unlimited number of leaf nodes.

    min_impurity_decrease : float, optional (default=0.)
        A node will be split if this split induces a decrease of the impurity
        greater than or equal to this value.

        The weighted impurity decrease equation is the following::

            N_t / N * (impurity - N_t_R / N_t * right_impurity
                                - N_t_L / N_t * left_impurity)

        where ``N`` is the total number of samples, ``N_t`` is the number of
        samples at the current node, ``N_t_L`` is the number of samples in the
        left child, and ``N_t_R`` is the number of samples in the right child.

        ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,
        if ``sample_weight`` is passed.

        .. versionadded:: 0.19

    min_impurity_split : float, (default=1e-7)
        Threshold for early stopping in tree growth. A node will split
        if its impurity is above the threshold, otherwise it is a leaf.

        .. deprecated:: 0.19
           ``min_impurity_split`` has been deprecated in favor of
           ``min_impurity_decrease`` in 0.19. The default value of
           ``min_impurity_split`` will change from 1e-7 to 0 in 0.23 and it
           will be removed in 0.25. Use ``min_impurity_decrease`` instead.

    bootstrap : boolean, optional (default=False)
        Whether bootstrap samples are used when building trees. If False, the
        whole datset is used to build each tree.

    oob_score : bool, optional (default=False)
        Whether to use out-of-bag samples to estimate the R^2 on unseen data.

    n_jobs : int or None, optional (default=None)
        The number of jobs to run in parallel for both `fit` and `predict`.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    verbose : int, optional (default=0)
        Controls the verbosity when fitting and predicting.

    warm_start : bool, optional (default=False)
        When set to ``True``, reuse the solution of the previous call to fit
        and add more estimators to the ensemble, otherwise, just fit a whole
        new forest. See :term:`the Glossary <warm_start>`.

    Attributes
    ----------
    estimators_ : list of DecisionTreeRegressor
        The collection of fitted sub-estimators.

    feature_importances_ : array of shape = [n_features]
        The feature importances (the higher, the more important the feature).

    n_features_ : int
        The number of features.

    n_outputs_ : int
        The number of outputs.

    oob_score_ : float
        Score of the training dataset obtained using an out-of-bag estimate.

    oob_prediction_ : array of shape = [n_samples]
        Prediction computed with out-of-bag estimate on the training set.

    Notes
    -----
    The default values for the parameters controlling the size of the trees
    (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and
    unpruned trees which can potentially be very large on some data sets. To
    reduce memory consumption, the complexity and size of the trees should be
    controlled by setting those parameter values.

    References
    ----------

    .. [1] P. Geurts, D. Ernst., and L. Wehenkel, "Extremely randomized trees",
           Machine Learning, 63(1), 3-42, 2006.

    See also
    --------
    sklearn.tree.ExtraTreeRegressor: Base estimator for this ensemble.
    RandomForestRegressor: Ensemble regressor using trees with optimal splits.
    R   R   i   i   g        R7   i    c         C   s   t  t |   j d t   d | d d d | d | d | d | d | d |  	| |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |	 |  _ |
 |  _ d  S(   NRQ   RR   RS   R   R   R   R   R   R   R   R   R   R&   R<   RV   RW   RK   RX   (
   R   R   R   R   R   R   R   R   R   R&   (   RT   R#   RU   R   R   R   R   R   R   R   R   R   R   (   RY   RR   R   R   R   R   R   R   R   R   R   R<   RV   RW   R&   RK   RX   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU     s.    	    								N(   R   R   R   R>   RD   RU   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR#     s"   c           B   sn   e  Z d  Z d d d d d d d d e d d d e d  Z d   Z d d d	  Z d d d
  Z	 d   Z
 RS(   s]  An ensemble of totally random trees.

    An unsupervised transformation of a dataset to a high-dimensional
    sparse representation. A datapoint is coded according to which leaf of
    each tree it is sorted into. Using a one-hot encoding of the leaves,
    this leads to a binary coding with as many ones as there are trees in
    the forest.

    The dimensionality of the resulting representation is
    ``n_out <= n_estimators * max_leaf_nodes``. If ``max_leaf_nodes == None``,
    the number of leaf nodes is at most ``n_estimators * 2 ** max_depth``.

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

    Parameters
    ----------
    n_estimators : integer, optional (default=10)
        Number of trees in the forest.

        .. versionchanged:: 0.20
           The default value of ``n_estimators`` will change from 10 in
           version 0.20 to 100 in version 0.22.

    max_depth : integer, optional (default=5)
        The maximum depth of each tree. If None, then nodes are expanded until
        all leaves are pure or until all leaves contain less than
        min_samples_split samples.

    min_samples_split : int, float, optional (default=2)
        The minimum number of samples required to split an internal node:

        - If int, then consider `min_samples_split` as the minimum number.
        - If float, then `min_samples_split` is a fraction and
          `ceil(min_samples_split * n_samples)` is the minimum
          number of samples for each split.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_samples_leaf : int, float, optional (default=1)
        The minimum number of samples required to be at a leaf node.
        A split point at any depth will only be considered if it leaves at
        least ``min_samples_leaf`` training samples in each of the left and
        right branches.  This may have the effect of smoothing the model,
        especially in regression.

        - If int, then consider `min_samples_leaf` as the minimum number.
        - If float, then `min_samples_leaf` is a fraction and
          `ceil(min_samples_leaf * n_samples)` is the minimum
          number of samples for each node.

        .. versionchanged:: 0.18
           Added float values for fractions.

    min_weight_fraction_leaf : float, optional (default=0.)
        The minimum weighted fraction of the sum total of weights (of all
        the input samples) required to be at a leaf node. Samples have
        equal weight when sample_weight is not provided.

    max_leaf_nodes : int or None, optional (default=None)
        Grow trees with ``max_leaf_nodes`` in best-first fashion.
        Best nodes are defined as relative reduction in impurity.
        If None then unlimited number of leaf nodes.

    min_impurity_decrease : float, optional (default=0.)
        A node will be split if this split induces a decrease of the impurity
        greater than or equal to this value.

        The weighted impurity decrease equation is the following::

            N_t / N * (impurity - N_t_R / N_t * right_impurity
                                - N_t_L / N_t * left_impurity)

        where ``N`` is the total number of samples, ``N_t`` is the number of
        samples at the current node, ``N_t_L`` is the number of samples in the
        left child, and ``N_t_R`` is the number of samples in the right child.

        ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,
        if ``sample_weight`` is passed.

        .. versionadded:: 0.19

    min_impurity_split : float, (default=1e-7)
        Threshold for early stopping in tree growth. A node will split
        if its impurity is above the threshold, otherwise it is a leaf.

        .. deprecated:: 0.19
           ``min_impurity_split`` has been deprecated in favor of
           ``min_impurity_decrease`` in 0.19. The default value of
           ``min_impurity_split`` will change from 1e-7 to 0 in 0.23 and it
           will be removed in 0.25. Use ``min_impurity_decrease`` instead.

    sparse_output : bool, optional (default=True)
        Whether or not to return a sparse CSR matrix, as default behavior,
        or to return a dense array compatible with dense pipeline operators.

    n_jobs : int or None, optional (default=None)
        The number of jobs to run in parallel for both `fit` and `predict`.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    verbose : int, optional (default=0)
        Controls the verbosity when fitting and predicting.

    warm_start : bool, optional (default=False)
        When set to ``True``, reuse the solution of the previous call to fit
        and add more estimators to the ensemble, otherwise, just fit a whole
        new forest. See :term:`the Glossary <warm_start>`.

    Attributes
    ----------
    estimators_ : list of DecisionTreeClassifier
        The collection of fitted sub-estimators.

    References
    ----------
    .. [1] P. Geurts, D. Ernst., and L. Wehenkel, "Extremely randomized trees",
           Machine Learning, 63(1), 3-42, 2006.
    .. [2] Moosmann, F. and Triggs, B. and Jurie, F.  "Fast discriminative
           visual codebooks using randomized clustering forests"
           NIPS 2007

    R   i   i   i   g        i    c         C   s   t  t |   j d t   d | d d d t d t d |
 d | d | d |  	d |  _ | |  _ | |  _ | |  _ | |  _	 d |  _
 | |  _ | |  _ | |  _ |	 |  _ d  S(   NRQ   RR   RS   R   R   R   R   R   R   R   R   R   R&   R<   RV   RW   RK   RX   R   i   (
   R   R   R   R   R   R   R   R   R   R&   (   RT   R$   RU   R   RD   R   R   R   R   R   R   R   R   R   t   sparse_output(   RY   RR   R   R   R   R   R   R   R   R   RW   R&   RK   RX   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRU   v  s0    	    									c         C   s   t  d   d  S(   Ns)   OOB score not supported by tree embedding(   t   NotImplementedError(   RY   RG   RH   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s    c         C   s   |  j  | | d | |  S(   sA  Fit estimator.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            The input samples. Use ``dtype=np.float32`` for maximum
            efficiency. Sparse matrices are also supported, use sparse
            ``csc_matrix`` for maximum efficiency.

        sample_weight : array-like, shape = [n_samples] or None
            Sample weights. If None, then samples are equally weighted. Splits
            that would create child nodes with net zero or negative weight are
            ignored while searching for a split in each node. In the case of
            classification, splits are also ignored if they would result in any
            single class carrying a negative weight in either child node.

        Returns
        -------
        self : object

        R:   (   t   fit_transform(   RY   RG   RH   R:   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyRC     s    c         C   s   t  | d d g } t |  r. | j   n  t |  j  } | j d | j d  } t t |   j	 | | d | t
 d |  j d d  |  _ |  j j |  j |   S(	   sN  Fit estimator and transform dataset.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Input data used to build forests. Use ``dtype=np.float32`` for
            maximum efficiency.

        sample_weight : array-like, shape = [n_samples] or None
            Sample weights. If None, then samples are equally weighted. Splits
            that would create child nodes with net zero or negative weight are
            ignored while searching for a split in each node. In the case of
            classification, splits are also ignored if they would result in any
            single class carrying a negative weight in either child node.

        Returns
        -------
        X_transformed : sparse matrix, shape=(n_samples, n_out)
            Transformed dataset.
        Rl   Rm   Rp   i    R:   t   sparset
   categoriesR7   (   R   R   Rw   R   R&   t   uniformR=   RT   R$   RC   R   R   t   one_hot_encoder_R   R\   (   RY   RG   RH   R:   t   rnd(    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s    c         C   s   |  j  j |  j |   S(   s  Transform dataset.

        Parameters
        ----------
        X : array-like or sparse matrix, shape=(n_samples, n_features)
            Input data to be transformed. Use ``dtype=np.float32`` for maximum
            efficiency. Sparse matrices are also supported, use sparse
            ``csr_matrix`` for maximum efficiency.

        Returns
        -------
        X_transformed : sparse matrix, shape=(n_samples, n_out)
            Transformed dataset.
        (   R   t	   transformR\   (   RY   RG   (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR     s    N(   R   R   R   R>   R   RD   RU   R   RC   R   R   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyR$     s$   	$(H   R   t
   __future__R    t   warningsR   R   R   R   t   abcR   R   t   numpyR,   t   scipy.sparseR   R   Rf   t   baseR   R	   t   utils._joblibR
   R   t	   externalsR   t   metricsR   t   preprocessingR   RE   R   R   R   R   t
   tree._treeR   R   t   utilsR   R   R   t
   exceptionsR   R   R   R   t   utils.fixesR   R   t   utils.multiclassR   t   utils.validationR   t   __all__t   iinfot   int32t   maxR   R*   R3   R>   RO   t   with_metaclassRP   R   R   R   R    R!   R"   R#   R$   (    (    (    s6   lib/python2.7/site-packages/sklearn/ensemble/forest.pyt   <module>!   sV   	"			" 	%r !  