
    0PhL                     X   d Z ddlZddlmZ ddlmZ ddlZddlm	Z	 ddl
mZmZmZ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mZmZmZmZ ddlm Z m!Z!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,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3 d Z4 G d de2ee          Z5 G d de5          Z6dS )z1Recursive feature elimination for feature ranking    N)deepcopy)Integral)effective_n_jobs   )BaseEstimatorMetaEstimatorMixin_fit_contextcloneis_classifier)
get_scorer)check_cv_score)Bunchmetadata_routing)MetadataRouterMethodMapping_raise_for_params_routing_enabledprocess_routing)
HasMethodsInterval
RealNotInt)get_tags)_safe_splitavailable_if)Paralleldelayed)_check_method_params_deprecate_positional_args_estimator_hascheck_is_fittedvalidate_data   )SelectorMixin_get_feature_importancesc                    t          ||||          \  }}	t          |||||          \  t          ||j        j        |          }
t          ||j        j        |           | j        ||	fdfi |
 | j        | j        fS )zM
    Return the score and n_features per step for a fit across one fold.
    )paramsindices)Xr(   r)   c                 @    t          | d d |f                   S )N)score_paramsr   )	estimatorfeaturesX_testr,   scorery_tests     ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/feature_selection/_rfe.py<lambda>z!_rfe_single_fit.<locals>.<lambda>7   s2    F111h;%%
 %
 %
     )	r   r   r-   fitr0   score_fitstep_scores_step_n_features_)rfer-   r*   ytraintestr0   routed_paramsX_trainy_train
fit_paramsr/   r,   r1   s         `    @@@r2   _rfe_single_fitrB   '   s     #9aE::GW Aq$>>NFF%	-)-u  J (
M(.  L CH	
 	
 	
 	
 	
 	
 	
     S111r4   c            	       j    e Zd ZU dZ edg          gd eeddd           eeddd          g eeddd           eeddd          gd	gee	gd
Z
eed<   ddddddZed             Zed             Z ed          d             Zd"dZ e ed                    d             Z e ed                    d             Zd Z e ed                    d             Z e ed                    d             Z e ed                    d             Z fd Zd! Z xZS )#RFEar  Feature ranking with recursive feature elimination.

    Given an external estimator that assigns weights to features (e.g., the
    coefficients of a linear model), the goal of recursive feature elimination
    (RFE) is to select features by recursively considering smaller and smaller
    sets of features. First, the estimator is trained on the initial set of
    features and the importance of each feature is obtained either through
    any specific attribute or callable.
    Then, the least important features are pruned from current set of features.
    That procedure is recursively repeated on the pruned set until the desired
    number of features to select is eventually reached.

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

    Parameters
    ----------
    estimator : ``Estimator`` instance
        A supervised learning estimator with a ``fit`` method that provides
        information about feature importance
        (e.g. `coef_`, `feature_importances_`).

    n_features_to_select : int or float, default=None
        The number of features to select. If `None`, half of the features are
        selected. If integer, the parameter is the absolute number of features
        to select. If float between 0 and 1, it is the fraction of features to
        select.

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

    step : int or float, default=1
        If greater than or equal to 1, then ``step`` corresponds to the
        (integer) number of features to remove at each iteration.
        If within (0.0, 1.0), then ``step`` corresponds to the percentage
        (rounded down) of features to remove at each iteration.

    verbose : int, default=0
        Controls verbosity of output.

    importance_getter : str or callable, default='auto'
        If 'auto', uses the feature importance either through a `coef_`
        or `feature_importances_` attributes of estimator.

        Also accepts a string that specifies an attribute name/path
        for extracting feature importance (implemented with `attrgetter`).
        For example, give `regressor_.coef_` in case of
        :class:`~sklearn.compose.TransformedTargetRegressor`  or
        `named_steps.clf.feature_importances_` in case of
        class:`~sklearn.pipeline.Pipeline` with its last step named `clf`.

        If `callable`, overrides the default feature importance getter.
        The callable is passed with the fitted estimator and it should
        return importance for each feature.

        .. versionadded:: 0.24

    Attributes
    ----------
    classes_ : ndarray of shape (n_classes,)
        The classes labels. Only available when `estimator` is a classifier.

    estimator_ : ``Estimator`` instance
        The fitted estimator used to select features.

    n_features_ : int
        The number of selected features.

    n_features_in_ : int
        Number of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    ranking_ : ndarray of shape (n_features,)
        The feature ranking, such that ``ranking_[i]`` corresponds to the
        ranking position of the i-th feature. Selected (i.e., estimated
        best) features are assigned rank 1.

    support_ : ndarray of shape (n_features,)
        The mask of selected features.

    See Also
    --------
    RFECV : Recursive feature elimination with built-in cross-validated
        selection of the best number of features.
    SelectFromModel : Feature selection based on thresholds of importance
        weights.
    SequentialFeatureSelector : Sequential cross-validation based feature
        selection. Does not rely on importance weights.

    Notes
    -----
    Allows NaN/Inf in the input if the underlying estimator does as well.

    References
    ----------

    .. [1] Guyon, I., Weston, J., Barnhill, S., & Vapnik, V., "Gene selection
           for cancer classification using support vector machines",
           Mach. Learn., 46(1-3), 389--422, 2002.

    Examples
    --------
    The following example shows how to retrieve the 5 most informative
    features in the Friedman #1 dataset.

    >>> from sklearn.datasets import make_friedman1
    >>> from sklearn.feature_selection import RFE
    >>> from sklearn.svm import SVR
    >>> X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
    >>> estimator = SVR(kernel="linear")
    >>> selector = RFE(estimator, n_features_to_select=5, step=1)
    >>> selector = selector.fit(X, y)
    >>> selector.support_
    array([ True,  True,  True,  True,  True, False, False, False, False,
           False])
    >>> selector.ranking_
    array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])
    r5   Nr   r$   rightclosedneitherverbose)r-   n_features_to_selectsteprI   importance_getter_parameter_constraintsauto)rJ   rK   rI   rL   c                L    || _         || _        || _        || _        || _        d S Nr-   rJ   rK   rL   rI   )selfr-   rJ   rK   rI   rL   s         r2   __init__zRFE.__init__   s-     #$8!	!2r4   c                     | j         j        S rP   )r-   _estimator_typerR   s    r2   rU   zRFE._estimator_type   s    ~--r4   c                     | j         j        S )zClasses labels available when `estimator` is a classifier.

        Returns
        -------
        ndarray of shape (n_classes,)
        )
estimator_classes_rV   s    r2   rY   zRFE.classes_   s     ''r4   Fprefer_skip_nested_validationc                     t                      rt          | dfi |}nt          t          |                    } | j        ||fi |j        j        S )ab  Fit the RFE model and then the underlying estimator on the selected features.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            The training input samples.

        y : array-like of shape (n_samples,)
            The target values.

        **fit_params : dict
            - If `enable_metadata_routing=False` (default): Parameters directly passed
              to the ``fit`` method of the underlying estimator.

            - If `enable_metadata_routing=True`: Parameters safely routed to the ``fit``
              method of the underlying estimator.

            .. versionchanged:: 1.6
                See :ref:`Metadata Routing User Guide <metadata_routing>`
                for more details.

        Returns
        -------
        self : object
            Fitted estimator.
        r5   r5   r-   )r   r   r   r7   r-   r5   )rR   r*   r;   rA   r>   s        r2   r5   zRFE.fit   si    >  	C+D%FF:FFMM!Ej,A,A,ABBBMtyA==!8!<===r4   c           	         t          | ||dddd          \  }}|j        d         }| j        |dz  }n`t          | j        t                    r/| j        }||k    r!t          j        d|d|d	t                     nt          || j        z            }d
| j	        cxk     rdk     r)n n&t          t          d| j	        |z                      }nt          | j	                  }t          j        |t                    }t          j        |t                    }	|rg | _        g | _        t          j        |          |k    rut          j        |          |         }
t%          | j                  }| j        dk    r$t+          dt          j        |          z              |j        |d d |
f         |fi | t/          || j        d          }t          j        |          }t          j        |          }t7          |t          j        |          |z
            }|rK| j                            t;          |
                     | j                             |||
                     d||
|         d |         <   |	t          j        |          xx         dz  cc<   t          j        |          |k    ut          j        |          |         }
t%          | j                  | _         | j        j        |d d |
f         |fi | |rP| j                            t;          |
                     | j                             || j        |
                     |                                | _         || _!        |	| _"        | S )Ncscr   FTaccept_sparseensure_min_featuresensure_all_finitemulti_outputr$   zFound n_features_to_select= > n_features=C. There will be no feature selection and all features will be kept.g        g      ?)dtyper   z#Fitting estimator with %d features.square)transform_func)#r#   shaperJ   
isinstancer   warningswarnUserWarningintrK   maxnponesboolr9   r8   sumaranger
   r-   rI   printr5   r&   rL   argsortravelminappendlenlogical_notrX   n_features_support_ranking_)rR   r*   r;   
step_scorerA   
n_featuresrJ   rK   r   r   r.   r-   importancesranks	thresholds                  r2   r7   zRFE._fit  s   
  !#
 
 
1 WQZ
$,#-?  18<< 	O#'#< #j00O!5 O O: O O O     $'zD4M'M#N#N     S     s1di*45566DDty>>D7:T2227:S111 	#$&D! "D fX!555y,,X6H dn--I|a;bfX>N>NNOOOIM!AAAxK.!::z::: 3&'  K
 J{++E HUOOE D"&"2"25I"IJJI
  J%,,S]];;;!((Ix)H)HIII49HXe_ZiZ01R^H--...!3...A fX!555F 9Z((2//AaaakNA<<<<<  	L!((X777$$ZZ%J%JKKK#<<>>  r4   predictc                    t          || d           t          |            t                      rt          | dfi |}nt	          t	          i                     } | j        j        |                     |          fi |j        j        S )a  Reduce X to the selected features and predict using the estimator.

        Parameters
        ----------
        X : array of shape [n_samples, n_features]
            The input samples.

        **predict_params : dict
            Parameters to route to the ``predict`` method of the
            underlying estimator.

            .. versionadded:: 1.6
                Only available if `enable_metadata_routing=True`,
                which can be set by using
                ``sklearn.set_config(enable_metadata_routing=True)``.
                See :ref:`Metadata Routing User Guide <metadata_routing>`
                for more details.

        Returns
        -------
        y : array of shape [n_samples]
            The predicted target values.
        r   )r   r^   )	r   r"   r   r   r   rX   r   	transformr-   )rR   r*   predict_paramsr>   s       r2   r   zRFE.predictt  s    2 	.$	::: 	?+D)NN~NNMM!E",=,=,=>>>M&t&NN1
 
!.!8!@
 
 	
r4   r6   c                     t          |            t                      rt          | dfi |}nt          t          |                    } | j        j        |                     |          |fi |j        j        S )a  Reduce X to the selected features and return the score of the estimator.

        Parameters
        ----------
        X : array of shape [n_samples, n_features]
            The input samples.

        y : array of shape [n_samples]
            The target values.

        **score_params : dict
            - If `enable_metadata_routing=False` (default): Parameters directly passed
              to the ``score`` method of the underlying estimator.

            - If `enable_metadata_routing=True`: Parameters safely routed to the `score`
              method of the underlying estimator.

            .. versionadded:: 1.0

            .. versionchanged:: 1.6
                See :ref:`Metadata Routing User Guide <metadata_routing>`
                for more details.

        Returns
        -------
        score : float
            Score of the underlying base estimator computed with the selected
            features returned by `rfe.transform(X)` and `y`.
        r6   r6   r^   )r"   r   r   r   rX   r6   r   r-   )rR   r*   r;   r,   r>   s        r2   r6   z	RFE.score  s    > 	 	G+D'JJ\JJMM!E,E,E,EFFFM$t$NN1q
 
$1$;$A
 
 	
r4   c                 .    t          |            | j        S rP   )r"   r   rV   s    r2   _get_support_maskzRFE._get_support_mask  s    }r4   decision_functionc                 z    t          |            | j                            |                     |                    S )a  Compute the decision function of ``X``.

        Parameters
        ----------
        X : {array-like or sparse matrix} of shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        score : array, shape = [n_samples, n_classes] or [n_samples]
            The decision function of the input samples. The order of the
            classes corresponds to that in the attribute :term:`classes_`.
            Regression and binary classification produce an array of shape
            [n_samples].
        )r"   rX   r   r   rR   r*   s     r2   r   zRFE.decision_function  s4    & 	001B1BCCCr4   predict_probac                 z    t          |            | j                            |                     |                    S )a5  Predict class probabilities for X.

        Parameters
        ----------
        X : {array-like or sparse matrix} of shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        p : array of shape (n_samples, n_classes)
            The class probabilities of the input samples. The order of the
            classes corresponds to that in the attribute :term:`classes_`.
        )r"   rX   r   r   r   s     r2   r   zRFE.predict_proba  s4    " 	,,T^^A->->???r4   predict_log_probac                 z    t          |            | j                            |                     |                    S )a  Predict class log-probabilities for X.

        Parameters
        ----------
        X : array of shape [n_samples, n_features]
            The input samples.

        Returns
        -------
        p : array of shape (n_samples, n_classes)
            The class log-probabilities of the input samples. The order of the
            classes corresponds to that in the attribute :term:`classes_`.
        )r"   rX   r   r   r   s     r2   r   zRFE.predict_log_proba  s4     	001B1BCCCr4   c                    t                                                      }t          | j                  }|j        |_        t          |j                  |_        t          |j                  |_        |j        d|j        _        |j        d|j        _        d|j	        _
        |j        j        |j        _        |j        j        |j        _        |S )NT)super__sklearn_tags__r   r-   estimator_typer   classifier_tagsregressor_tags
poor_scoretarget_tagsrequired
input_tagssparse	allow_nan)rR   tagssub_estimator_tags	__class__s      r2   r   zRFE.__sklearn_tags__  s    ww''))%dn550?'(:(JKK&'9'HII+.2D +*-1D*$(!!3!>!E$6$A$K!r4   c                    t          | j        j                                      | j        t                                          dd                              dd                              dd                    }|S )j  Get metadata routing of this object.

        Please check :ref:`User Guide <metadata_routing>` on how the routing
        mechanism works.

        .. versionadded:: 1.6

        Returns
        -------
        routing : MetadataRouter
            A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
            routing information.
        ownerr5   callercalleer   r6   r-   method_mapping)r   r   __name__addr-   r   rR   routers     r2   get_metadata_routingzRFE.get_metadata_routing  su      dn&=>>>BBn(??SeS,,S	)S44SS00 C 
 
 r4   rP   )r   
__module____qualname____doc__r   r   r   r   strcallablerM   dict__annotations__rS   propertyrU   rY   r	   r5   r7   r   r!   r   r6   r   r   r   r   r   r   __classcell__)r   s   @r2   rD   rD   D   s        | |~ !j%))*HZAg666HXq$y999!
 HXq$y999HZAi888
 ;!8_$ $D   & "       . . X. ( ( X( \&+   >  >	  >D\ \ \ \| \..++,,!
 !
 -,!
F \..))**&
 &
 +*&
P   \..!45566D D 76D* \..1122@ @ 32@& \..!45566D D 76D"          r4   rD   c                       e Zd ZU dZi ej         eeddd          gdgdee	gdegdZe
ed<   e                    d	           d
ej        iZdddddddddZ ed           ed          ddd                        Zd Zd Zd ZdS )RFECVaq  Recursive feature elimination with cross-validation to select features.

    The number of features selected is tuned automatically by fitting an :class:`RFE`
    selector on the different cross-validation splits (provided by the `cv` parameter).
    The performance of the :class:`RFE` selector are evaluated using `scorer` for
    different number of selected features and aggregated together. Finally, the scores
    are averaged across folds and the number of features selected is set to the number
    of features that maximize the cross-validation score.
    See glossary entry for :term:`cross-validation estimator`.

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

    Parameters
    ----------
    estimator : ``Estimator`` instance
        A supervised learning estimator with a ``fit`` method that provides
        information about feature importance either through a ``coef_``
        attribute or through a ``feature_importances_`` attribute.

    step : int or float, default=1
        If greater than or equal to 1, then ``step`` corresponds to the
        (integer) number of features to remove at each iteration.
        If within (0.0, 1.0), then ``step`` corresponds to the percentage
        (rounded down) of features to remove at each iteration.
        Note that the last iteration may remove fewer than ``step`` features in
        order to reach ``min_features_to_select``.

    min_features_to_select : int, default=1
        The minimum number of features to be selected. This number of features
        will always be scored, even if the difference between the original
        feature count and ``min_features_to_select`` isn't divisible by
        ``step``.

        .. versionadded:: 0.20

    cv : int, cross-validation generator or an iterable, default=None
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 5-fold cross-validation,
        - integer, to specify the number of folds.
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if ``y`` is binary or multiclass,
        :class:`~sklearn.model_selection.StratifiedKFold` is used. If the
        estimator is not a classifier or if ``y`` is neither binary nor multiclass,
        :class:`~sklearn.model_selection.KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.22
            ``cv`` default value of None changed from 3-fold to 5-fold.

    scoring : str, callable or None, default=None
        A string (see :ref:`scoring_parameter`) or
        a scorer callable object / function with signature
        ``scorer(estimator, X, y)``.

    verbose : int, default=0
        Controls verbosity of output.

    n_jobs : int or None, default=None
        Number of cores to run in parallel while fitting across folds.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

        .. versionadded:: 0.18

    importance_getter : str or callable, default='auto'
        If 'auto', uses the feature importance either through a `coef_`
        or `feature_importances_` attributes of estimator.

        Also accepts a string that specifies an attribute name/path
        for extracting feature importance.
        For example, give `regressor_.coef_` in case of
        :class:`~sklearn.compose.TransformedTargetRegressor`  or
        `named_steps.clf.feature_importances_` in case of
        :class:`~sklearn.pipeline.Pipeline` with its last step named `clf`.

        If `callable`, overrides the default feature importance getter.
        The callable is passed with the fitted estimator and it should
        return importance for each feature.

        .. versionadded:: 0.24

    Attributes
    ----------
    classes_ : ndarray of shape (n_classes,)
        The classes labels. Only available when `estimator` is a classifier.

    estimator_ : ``Estimator`` instance
        The fitted estimator used to select features.

    cv_results_ : dict of ndarrays
        All arrays (values of the dictionary) are sorted in ascending order
        by the number of features used (i.e., the first element of the array
        represents the models that used the least number of features, while the
        last element represents the models that used all available features).

        .. versionadded:: 1.0

        This dictionary contains the following keys:

        split(k)_test_score : ndarray of shape (n_subsets_of_features,)
            The cross-validation scores across (k)th fold.

        mean_test_score : ndarray of shape (n_subsets_of_features,)
            Mean of scores over the folds.

        std_test_score : ndarray of shape (n_subsets_of_features,)
            Standard deviation of scores over the folds.

        n_features : ndarray of shape (n_subsets_of_features,)
            Number of features used at each step.

            .. versionadded:: 1.5

    n_features_ : int
        The number of selected features with cross-validation.

    n_features_in_ : int
        Number of features seen during :term:`fit`. Only defined if the
        underlying estimator exposes such an attribute when fit.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    ranking_ : narray of shape (n_features,)
        The feature ranking, such that `ranking_[i]`
        corresponds to the ranking
        position of the i-th feature.
        Selected (i.e., estimated best)
        features are assigned rank 1.

    support_ : ndarray of shape (n_features,)
        The mask of selected features.

    See Also
    --------
    RFE : Recursive feature elimination.

    Notes
    -----
    The size of all values in ``cv_results_`` is equal to
    ``ceil((n_features - min_features_to_select) / step) + 1``,
    where step is the number of features removed at each iteration.

    Allows NaN/Inf in the input if the underlying estimator does as well.

    References
    ----------

    .. [1] Guyon, I., Weston, J., Barnhill, S., & Vapnik, V., "Gene selection
           for cancer classification using support vector machines",
           Mach. Learn., 46(1-3), 389--422, 2002.

    Examples
    --------
    The following example shows how to retrieve the a-priori not known 5
    informative features in the Friedman #1 dataset.

    >>> from sklearn.datasets import make_friedman1
    >>> from sklearn.feature_selection import RFECV
    >>> from sklearn.svm import SVR
    >>> X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
    >>> estimator = SVR(kernel="linear")
    >>> selector = RFECV(estimator, step=1, cv=5)
    >>> selector = selector.fit(X, y)
    >>> selector.support_
    array([ True,  True,  True,  True,  True, False, False, False, False,
           False])
    >>> selector.ranking_
    array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])
    r   NrH   rF   	cv_object)min_features_to_selectcvscoringn_jobsrM   rJ   groupsr$   rN   )rK   r   r   r   rI   r   rL   c                v    || _         || _        || _        || _        || _        || _        || _        || _        d S rP   )r-   rK   rL   r   r   rI   r   r   )	rR   r-   rK   r   r   r   rI   r   rL   s	            r2   rS   zRFECV.__init__  sD     #	!2&<###r4   z1.8)versionFrZ   )r   c          	          t          | d           t           dddd          \  t                      r(||                    d|i           t	           dfi |n>t          t          i 	          t          d|i
          t          i                     t           j        t           j	                            } 
                                j        d         } j        |k    r&t          j        d j         d|dt                     t!           j	        t#           j        |           j         j         j                  t+           j                  dk    rt.          t0          c}n)t3           j                  }t5          t0                     | fd |j        fi j        j        D                       }t;          | \  }	}
t=          j        |
d                   ddd         }t=          j        |	          }	t=          j         |	d          ddd         }|t=          j!        |                   }t!           j	        | j         j         j                   j"        fi j	        j"         j#         _#        j$         _$        j%         _%        tM           j	                   _'          j'        j"         (                              fi j	        j"         |	dddddf         t=          j)        d          t=          j*        d          dfdtW          |	j        d                   D             d|i _,         S )aa  Fit the RFE model and automatically tune the number of selected features.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vector, where `n_samples` is the number of samples and
            `n_features` is the total number of features.

        y : array-like of shape (n_samples,)
            Target values (integers for classification, real numbers for
            regression).

        groups : array-like of shape (n_samples,) or None, default=None
            Group labels for the samples used while splitting the dataset into
            train/test set. Only used in conjunction with a "Group" :term:`cv`
            instance (e.g., :class:`~sklearn.model_selection.GroupKFold`).

            .. versionadded:: 0.20

        **params : dict of str -> object
            Parameters passed to the ``fit`` method of the estimator,
            the scorer, and the CV splitter.

            .. versionadded:: 1.6
                Only available if `enable_metadata_routing=True`,
                which can be set by using
                ``sklearn.set_config(enable_metadata_routing=True)``.
                See :ref:`Metadata Routing User Guide <metadata_routing>`
                for more details.

        Returns
        -------
        self : object
            Fitted estimator.
        r5   csrr   FTra   Nr   r]   )splitr   )r-   splitterr0   )
classifierr$   zFound min_features_to_select=rf   rg   )r-   rJ   rL   rK   rI   )r   c              3   f   K   | ]+\  }} t                    j        	||          V  ,d S rP   )r
   r-   )
.0r<   r=   r*   funcr:   r>   r0   rR   r;   s
      r2   	<genexpr>zRFECV.fit.<locals>.<genexpr>i  s[       #
 #
t DsT^Q5$VV#
 #
 #
 #
 #
 #
r4   r   )axisrQ   )mean_test_scorestd_test_scorec                 *    i | ]}d | d|         S )r   _test_score )r   i
scores_revs     r2   
<dictcomp>zRFECV.fit.<locals>.<dictcomp>  s+    UUU%q%%%z!}UUUr4   r   )-r   r#   r   updater   r   r   r   r   r-   _get_scorerrk   r   rm   rn   ro   rD   rz   rL   rK   rI   r   r   listrB   r   r   r   r   ziprr   arrayru   argmaxr5   r   r~   r   r
   rX   
_transformmeanstdrangecv_results_)rR   r*   r;   r   r(   r   r   parallelscores_featuresscoresstep_n_featuresstep_n_features_revscores_sum_revrJ   r   r:   r>   r0   r   s   ```           @@@@@r2   r5   z	RFECV.fit   s   R 	&$... !#
 
 
1  		!x0111+D%BB6BBMM!B---h%78882  M dgq]4>-J-JKKK!!## WQZ
&33M-D4O - -!- - -    n!$T%@*!M!M"4L
 
 
( DK((A--!?NHddt{333H?++D"( #
 #
 #
 #
 #
 #
 #
 #
 #
 #
'rx1MM0F0LMM#
 #
 #
 
 
 #&"7 hq'9::44R4@&!! Q///"5229^3L3LM n!5"4L
 
 
 	144/3444 ?//DOOA..QQ]5L5PQQQ AAAtttG_
!wz::: fZa888
 
 VUUUeFLQRO>T>TUUU
 -	
 
 r4   c                     t          || d           |                                 }t                      rt          | dfi |}n#t	                      }t	          i           |_         || ||fi |j        j        S )a<  Score using the `scoring` option on the given test data and labels.

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

        y : array-like of shape (n_samples,)
            True labels for X.

        **score_params : dict
            Parameters to pass to the `score` method of the underlying scorer.

            .. versionadded:: 1.6
                Only available if `enable_metadata_routing=True`,
                which can be set by using
                ``sklearn.set_config(enable_metadata_routing=True)``.
                See :ref:`Metadata Routing User Guide <metadata_routing>`
                for more details.

        Returns
        -------
        score : float
            Score of self.predict(X) w.r.t. y defined by `scoring`.
        r6   r   )r   r   r   r   r   r0   r6   )rR   r*   r;   r,   r   r>   s         r2   r6   zRFECV.score  s    4 	,g666""$$ 	3+D'JJ\JJMM!GGM#(r???M wtQ@@]%9%?@@@r4   c                    t          | j        j                  }|                    | j        t                                          dd                     |                    t          | j                  t                                          dd                     |                    |                                 t                                          dd                              dd                     |S )	r   r   r5   r   r   r   )r   r   r6   )r0   r   )	r   r   r   r   r-   r   r   r   r   r   s     r2   r   zRFECV.get_metadata_routing  s      dn&=>>>

n(??..eE.JJ 	 	
 	
 	
 	

dg&&(??.. /   	 	
 	
 	
 	

##%%(??SgS..SS00	 	 	
 	
 	
 r4   c                 n    | j         t          | j                  rdnd}n| j         }t          |          S )Naccuracyr2)r   r   r-   r   )rR   r   s     r2   r   zRFECV._get_scorer  s9    <$1$.$A$AKjjtGGlG'"""r4   )r   r   r   r   rD   rM   r   r   r   r   r   r   popr   UNUSED_RFECV__metadata_request__fitrS   r    r	   r5   r6   r   r   r   r4   r2   r   r   (  sn        u un$

$$#+8Hai#P#P#P"Qm#x("$ $ $D    5666')9)@A   = = = = =,  ...\&+   #' K K K K	  /.
KZ"A "A "AH! ! !F# # # # #r4   r   )7r   rm   copyr   numbersr   numpyrr   joblibr   baser   r   r	   r
   r   metricsr   model_selectionr   model_selection._validationr   utilsr   r   utils._metadata_requestsr   r   r   r   r   utils._param_validationr   r   r   utils._tagsr   utils.metaestimatorsr   r   utils.parallelr   r   utils.validationr   r    r!   r"   r#   _baser%   r&   rB   rD   r   r   r4   r2   <module>r     s^   8 7                  # # # # # # X X X X X X X X X X X X X X             & & & & & & 0 0 0 0 0 0 + + + + + + + +              G F F F F F F F F F " " " " " " < < < < < < < < . . . . . . . .              ; : : : : : : :2 2 2:a a a a a-+] a a aHv# v# v# v# v#C v# v# v# v# v#r4   