
    -i}K                       S r SSKrSSKJrJr  SSKJr  SSKJr  SSK	J
r
Jr  SSKrSSKJr  SS	KJrJrJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJrJr  SSKJ r   SSK!J"r"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)J*r*J+r+J,r,J-r-J.r.  SSK/J0r0J1r1  SSK2J3r3J4r4  SSK5J6r6J7r7  / SQr8\S 5       r9S r:S r; " S S\05      r<S r=SSSS.S  jr>S! r? S)S" jr@S)S# jrA " S$ S%\\05      rBSSS&S'.S( jrCg)*zQUtilities to build a composite estimator as a chain of transforms and estimators.    N)Counterdefaultdict)contextmanager)deepcopy)chainislice)sparse   )TransformerMixin_fit_contextclone)NotFittedError)FunctionTransformer)Bunch)METHODS)
HasMethodsHidden)_VisualBlock)_get_container_adapter_safe_set_output)get_tags)_print_elapsed_time)MetadataRouterMethodMapping_raise_for_params_routing_enabledget_routing_for_objectprocess_routing)_BaseCompositionavailable_if)Paralleldelayed)check_is_fittedcheck_memory)FeatureUnionPipelinemake_pipeline
make_unionc              #      #     Sv    [        U 5        g! [          a  n[        S5      UeSnAff = f! [          a    [        R                  " S[        5         gf = f7f)zA context manager to make sure a NotFittedError is raised, if a sub-estimator
raises the error.

Otherwise, we raise a warning if the pipeline is not fitted, with the deprecation.

TODO(1.8): remove this context manager and replace with check_is_fitted.
NzPipeline is not fitted yet.zThis Pipeline instance is not fitted yet. Call 'fit' with appropriate arguments before using other methods such as transform, predict, etc. This will raise an error in 1.8 instead of the current warning.)r   r#   warningswarnFutureWarning)	estimatorexcs     C/var/www/html/venv/lib/python3.13/site-packages/sklearn/pipeline.py_raise_or_warn_if_not_fittedr0   +   sb     E
	
	"  E:;DE  
 	

s:   A 3 A
0+0A%AAAAc                    ^  U 4S jnU$ )zXCheck that final_estimator has `attr`.

Used together with `available_if` in `Pipeline`.c                 2   > [        U R                  T5        gNT)getattr_final_estimator)selfattrs    r/   check#_final_estimator_has.<locals>.checkK   s    %%t,     )r7   r8   s   ` r/   _final_estimator_hasr<   F   s    

 Lr:   c                   ^ ^ X!;  aF  [        U[        5      (       a  [        U U4S jU 5       5      X'   X   $ T R                  " U40 TD6X'   X   $ )aY  Transform a parameter value using a sub-pipeline and cache the result.

Parameters
----------
sub_pipeline : Pipeline
    The sub-pipeline to be used for transformation.
cache : dict
    The cache dictionary to store the transformed values.
param_name : str
    The name of the parameter to be transformed.
param_value : object
    The value of the parameter to be transformed.
transform_params : dict
    The metadata to be used for transformation. This passed to the
    `transform` method of the sub-pipeline.

Returns
-------
transformed_value : object
    The transformed value of the parameter.
c              3   J   >#    U  H  nTR                   " U40 TD6v   M     g 7fN	transform).0elementsub_pipelinetransform_paramss     r/   	<genexpr>$_cached_transform.<locals>.<genexpr>q   s)      &*G &&wC2BC*s    #)
isinstancetuplerA   )rD   cache
param_nameparam_valuerE   s   `   `r/   _cached_transformrM   S   sc    0 
 k5)) % &*& !E  !- 6 6{ WFV WEr:   c                     ^  \ rS rSr% Sr\\" \5      /\S/S\\	" S/5      /S/S.r
\\S'   SSSS	.S
 jrSS.S jrS9S jrS rS rS:S jrS rS r\S 5       r\S 5       r\S 5       rS rS rS rS;S jr\" SS9S<S j5       rS r\ " \5      \" SS9S<S j5       5       r!\ " \"" S5      5      S 5       r#\ " \"" S 5      5      \" SS9S<S! j5       5       r$\ " \"" S"5      5      S# 5       r%\ " \"" S$5      5      S% 5       r&\ " \"" S&5      5      S' 5       r'\ " \"" S(5      5      S) 5       r(S* r)\ " \)5      S+ 5       r*S, r+\ " \+5      S- 5       r,\ " \"" S.5      5      S=S/ j5       r-\S0 5       r.U 4S1 jr/S<S2 jr0\S3 5       r1\S4 5       r2S5 r3S6 r4S7 r5S8r6U =r7$ )>r&   {   a  
A sequence of data transformers with an optional final predictor.

`Pipeline` allows you to sequentially apply a list of transformers to
preprocess the data and, if desired, conclude the sequence with a final
:term:`predictor` for predictive modeling.

Intermediate steps of the pipeline must be transformers, that is, they
must implement `fit` and `transform` methods.
The final :term:`estimator` only needs to implement `fit`.
The transformers in the pipeline can be cached using ``memory`` argument.

The purpose of the pipeline is to assemble several steps that can be
cross-validated together while setting different parameters. For this, it
enables setting parameters of the various steps using their names and the
parameter name separated by a `'__'`, as in the example below. A step's
estimator may be replaced entirely by setting the parameter with its name
to another estimator, or a transformer removed by setting it to
`'passthrough'` or `None`.

For an example use case of `Pipeline` combined with
:class:`~sklearn.model_selection.GridSearchCV`, refer to
:ref:`sphx_glr_auto_examples_compose_plot_compare_reduction.py`. The
example :ref:`sphx_glr_auto_examples_compose_plot_digits_pipe.py` shows how
to grid search on a pipeline using `'__'` as a separator in the parameter names.

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

.. versionadded:: 0.5

Parameters
----------
steps : list of tuples
    List of (name of step, estimator) tuples that are to be chained in
    sequential order. To be compatible with the scikit-learn API, all steps
    must define `fit`. All non-last steps must also define `transform`. See
    :ref:`Combining Estimators <combining_estimators>` for more details.

transform_input : list of str, default=None
    The names of the :term:`metadata` parameters that should be transformed by the
    pipeline before passing it to the step consuming it.

    This enables transforming some input arguments to ``fit`` (other than ``X``)
    to be transformed by the steps of the pipeline up to the step which requires
    them. Requirement is defined via :ref:`metadata routing <metadata_routing>`.
    For instance, this can be used to pass a validation set through the pipeline.

    You can only set this if metadata routing is enabled, which you
    can enable using ``sklearn.set_config(enable_metadata_routing=True)``.

    .. versionadded:: 1.6

memory : str or object with the joblib.Memory interface, default=None
    Used to cache the fitted transformers of the pipeline. The last step
    will never be cached, even if it is a transformer. By default, no
    caching is performed. If a string is given, it is the path to the
    caching directory. Enabling caching triggers a clone of the transformers
    before fitting. Therefore, the transformer instance given to the
    pipeline cannot be inspected directly. Use the attribute ``named_steps``
    or ``steps`` to inspect estimators within the pipeline. Caching the
    transformers is advantageous when fitting is time consuming. See
    :ref:`sphx_glr_auto_examples_neighbors_plot_caching_nearest_neighbors.py`
    for an example on how to enable caching.

verbose : bool, default=False
    If True, the time elapsed while fitting each step will be printed as it
    is completed.

Attributes
----------
named_steps : :class:`~sklearn.utils.Bunch`
    Dictionary-like object, with the following attributes.
    Read-only attribute to access any step parameter by user given name.
    Keys are step names and values are steps parameters.

classes_ : ndarray of shape (n_classes,)
    The classes labels. Only exist if the last step of the pipeline is a
    classifier.

n_features_in_ : int
    Number of features seen during :term:`fit`. Only defined if the
    underlying first estimator in `steps` 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`. Only defined if the
    underlying estimator exposes such an attribute when fit.

    .. versionadded:: 1.0

See Also
--------
make_pipeline : Convenience function for simplified pipeline construction.

Examples
--------
>>> from sklearn.svm import SVC
>>> from sklearn.preprocessing import StandardScaler
>>> from sklearn.datasets import make_classification
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.pipeline import Pipeline
>>> X, y = make_classification(random_state=0)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y,
...                                                     random_state=0)
>>> pipe = Pipeline([('scaler', StandardScaler()), ('svc', SVC())])
>>> # The pipeline can be used as any other estimator
>>> # and avoids leaking the test set into the train set
>>> pipe.fit(X_train, y_train).score(X_test, y_test)
0.88
>>> # An estimator's parameter can be set using '__' syntax
>>> pipe.set_params(svc__C=10).fit(X_train, y_train).score(X_test, y_test)
0.76
NrJ   booleanstepstransform_inputmemoryverbose_parameter_constraintsFrS   rT   rU   c                4    Xl         X l        X0l        X@l        g r?   rQ   )r6   rR   rS   rT   rU   s        r/   __init__Pipeline.__init__   s    
.r:   r@   c                L    U R                  5        H  u    p#[        X1S9  M     U $ )aT  Set the output container when `"transform"` and `"fit_transform"` are called.

Calling `set_output` will set the output of all estimators in `steps`.

Parameters
----------
transform : {"default", "pandas", "polars"}, default=None
    Configure output of `transform` and `fit_transform`.

    - `"default"`: Default output format of a transformer
    - `"pandas"`: DataFrame output
    - `"polars"`: Polars output
    - `None`: Transform configuration is unchanged

    .. versionadded:: 1.4
        `"polars"` option was added.

Returns
-------
self : estimator instance
    Estimator instance.
r@   )_iterr   )r6   rA   _steps       r/   
set_outputPipeline.set_output   s%    . **,JAqT7 'r:   c                 "    U R                  SUS9$ )a  Get parameters for this estimator.

Returns the parameters given in the constructor as well as the
estimators contained within the `steps` of the `Pipeline`.

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

Returns
-------
params : mapping of string to any
    Parameter names mapped to their values.
rR   deep_get_paramsr6   rc   s     r/   
get_paramsPipeline.get_params  s    " d33r:   c                 *    U R                   " S0 UD6  U $ )a  Set the parameters of this estimator.

Valid parameter keys can be listed with ``get_params()``. Note that
you can directly set the parameters of the estimators contained in
`steps`.

Parameters
----------
**kwargs : dict
    Parameters of this estimator or parameters of estimators contained
    in `steps`. Parameters of the steps may be set using its name and
    the parameter name separated by a '__'.

Returns
-------
self : object
    Pipeline class instance.
)rR   _set_paramsr6   kwargss     r/   
set_paramsPipeline.set_params,  s    & 	+F+r:   c           	         U R                   (       d  [        S5      e[        U R                   6 u  pU R                  U5        US S nUS   nU H^  nUb  US:X  a  M  [	        US5      (       d  [	        US5      (       a  [	        US5      (       a  MC  [        SU< S[        U5      < S	35      e   Ub6  US:w  a/  [	        US5      (       d  [        S
U< S[        U5      < S	35      eg g g )Nz(The pipeline is empty. Please add steps.passthroughfitfit_transformrA   znAll intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' '' (type 	) doesn'tzLLast step of Pipeline should implement fit or be the string 'passthrough'. ')rR   
ValueErrorzip_validate_nameshasattr	TypeErrortype)r6   names
estimatorstransformersr-   ts         r/   _validate_stepsPipeline._validate_stepsB  s    zzGHH, 	U# "#2rN	AyA.Au%%O)D)DW;N N   1247<   !]*Iu-- -6tIH  . + "r:   c              #      #    [        U R                  5      nU(       d  US-  n[        [        U R                  SU5      5       H*  u  nu  pVU(       d  XEU4v   M  Uc  M  US:w  d  M$  XEU4v   M,     g7f)z
Generate (idx, (name, trans)) tuples from self.steps

When filter_passthrough is True, 'passthrough' and None transformers
are filtered out.
r
   r   Nrr   )lenrR   	enumerater   )r6   
with_finalfilter_passthroughstopidxnametranss          r/   r\   Pipeline._iterg  sj      4::AID"+F4::q$,G"HC$%&&"u'=&&	 #Is   AA3 A3(A3c                 ,    [        U R                  5      $ )z$
Returns the length of the Pipeline
)r   rR   r6   s    r/   __len__Pipeline.__len__x  s     4::r:   c                 ,   [        U[        5      (       aM  UR                  S;  a  [        S5      eU R	                  U R
                  U   U R                  U R                  S9$  U R
                  U   u  p#U$ ! [         a    U R                  U   s $ f = f)a  Returns a sub-pipeline or a single estimator in the pipeline

Indexing with an integer will return an estimator; using a slice
returns another Pipeline instance which copies a slice of this
Pipeline. This copy is shallow: modifying (or fitting) estimators in
the sub-pipeline will affect the larger pipeline and vice-versa.
However, replacing a value in `step` will not affect a copy.

See
:ref:`sphx_glr_auto_examples_feature_selection_plot_feature_selection_pipeline.py`
for an example of how to use slicing to inspect part of a pipeline.
)r
   Nz*Pipeline slicing only supports a step of 1)rT   rU   )
rH   slicer^   rw   	__class__rR   rT   rU   r{   named_steps)r6   indr   ests       r/   __getitem__Pipeline.__getitem__~  s     c5!!xxy( !MNN>>

3T\\ "  	)

3ID 
  	)##C((	)s   $A7 7BBc                 ^    U R                   (       d  gU R                   S   S   R                  $ )z;Return the estimator type of the last step in the pipeline.Nrq   r
   )rR   _estimator_typer   s    r/   r   Pipeline._estimator_type  s'     zzzz"~a 000r:   c                 >    [        S0 [        U R                  5      D6$ )zAccess the steps by name.

Read-only attribute to access any step by given name.
Keys are steps names and values are the steps objects.r;   )r   dictrR   r   s    r/   r   Pipeline.named_steps  s     (tDJJ'((r:   c                 l     U R                   S   S   nUc  S$ U$ ! [        [        [        4 a     g f = f)Nrq   r
   rr   )rR   rw   AttributeErrorr{   )r6   r-   s     r/   r5   Pipeline._final_estimator  sD    	

2q)I$-$5=D9DNI6 	
 	s     33c                     U R                   (       d  g U R                  U   u  p#SUS-   [        U R                  5      U4-  $ )N(step %d of %d) Processing %sr
   )rU   rR   r   )r6   step_idxr   r]   s       r/   _log_messagePipeline._log_message  s;    ||**X&.(Q,DJJQU1VVVr:   c                    [        5       (       a  [        X40 UDUD6nU$ [        S0 U R                   VVVs0 s H+  u  pVUc  M
  U[        S0 [         Vs0 s H  o0 _M     snD6_M-     snnnD6nUR                  5        HW  u  pSU;  a  [        SR                  U5      5      eUR                  SS5      u  pjXU   S   U
'   XU   S   U
'   XU   S   U
'   MY     U$ s  snf s  snnnf )N__zPipeline.fit does not accept the {} parameter. You can pass parameters to specific steps of your pipeline using the stepname__parameter format, e.g. `Pipeline.fit(X, y, logisticregression__sample_weight=sample_weight)`.r
   rs   rt   fit_predictr;   )	r   r   r   rR   r   itemsrw   formatsplit)r6   methodpropsrm   routed_paramsr   r^   fit_params_stepspnamepvalparams              r/   _check_method_paramsPipeline._check_method_params  s   +DLELVLM  $   '+jj&0
 FD%EG"DG&2:G"DEE&0   %{{}u$$, -3F5M  $kk$27;&u-e4 BF&7>?C&}5e<  - $#) #Es   	C"C"C  	C"C"c          
          U R                   b  U(       a  U(       a  US:X  a  U$ U SU n[        U5      nUR                  5        VVs0 s H+  u  pgUUR                  SUR	                  5       S9;   d  M)  Xg_M-     nnn[        5       n	[        5       n
UR                  5        HT  u  p[        5       X'   UR                  5        H/  u  pXR                   ;   a  [        UU
UUUS9X   U'   M(  XU   U'   M1     MV     U	$ s  snnf )a  Get params (metadata) for step `name`.

This transforms the metadata up to this step if required, which is
indicated by the `transform_input` parameter.

If a param in `step_params` is included in the `transform_input` list,
it will be transformed.

Parameters
----------
step_idx : int
    Index of the step in the pipeline.

step_params : dict
    Parameters specific to the step. These are routed parameters, e.g.
    `routed_params[name]`. If a parameter name here is included in the
    `pipeline.transform_input`, then it will be transformed. Note that
    these parameters are *after* routing, so the aliases are already
    resolved.

all_params : dict
    All parameters passed by the user. Here this is used to call
    `transform` on the slice of the pipeline itself.

Returns
-------
dict
    Parameters to be passed to the step. The ones which should be
    transformed are transformed.
Nr   rA   )r   params)rJ   rK   rL   rE   )rS   r   r   consumeskeysr   r   rM   )r6   r   step_params
all_paramsrD   sub_metadata_routingkeyvaluerE   transformed_paramstransformed_cacher   method_paramsrK   rL   s                  r/   _get_metadata_for_stepPipeline._get_metadata_for_step  s0   @   (1} IX5lC )..0
0
#,,":??+< -  CJ0 	 
 "V F
 &1%6%6%8!F).&+8+>+>+@'
 !5!55 >O$/#-$/)9>&.z: >Iv.z: ,A &9" "!?
s   (C:3C:c                 <   [        U R                  5      U l        U R                  5         [        U R                  5      nUR                  [        5      nU R                  SSS9 H  u  pxn	U	b  U	S:X  a'  [        SU R                  U5      5          SSS5        M6  [        US5      (       a  UR                  c  U	n
O[        U	5      n
U R                  UX8   US9nU" U
UUSSU R                  U5      US9u  pX4U R                  U'   M     U$ ! , (       d  f       N= f)	zFit the pipeline except the last step.

routed_params is the output of `process_routing`
raw_params is the parameters passed by the user, used when `transform_input`
    is set by the user, to transform metadata using a sub-pipeline.
Fr   r   Nrr   r&   locationr   r   r   )weightmessage_clsnamemessager   )listrR   r   r$   rT   rJ   _fit_transform_oner\   r   r   rz   r   r   r   )r6   Xyr   
raw_paramsrT   fit_transform_one_cachedr   r   transformercloned_transformerr   fitted_transformers                r/   _fitPipeline._fit*  s1    $**%
dkk*#)<<0B#C +/:: ,6 ,
'HK "k]&B(T5F5Fx5PQ RQ vz**v/F &1"%*;%7"55!)/% 6 K %=" *))(3"%!A %)#=DJJx A,
B ; RQs   D
D	)prefer_skip_nested_validationc                    [        5       (       d  U R                  b  [        S5      eU R                  SUS9nU R	                  XXCS9n[        SU R                  [        U R                  5      S-
  5      5         U R                  S:w  aO  U R                  [        U 5      S-
  X@R                  S	   S
      US9nU R                  R                  " XR40 US   D6  SSS5        U $ ! , (       d  f       U $ = f)a  Fit the model.

Fit all the transformers one after the other and sequentially transform the
data. Finally, fit the transformed data using the final estimator.

Parameters
----------
X : iterable
    Training data. Must fulfill input requirements of first step of the
    pipeline.

y : iterable, default=None
    Training targets. Must fulfill label requirements for all steps of
    the pipeline.

**params : dict of str -> object
    - If `enable_metadata_routing=False` (default): Parameters passed to the
      ``fit`` method of each step, where each parameter name is prefixed such
      that parameter ``p`` for step ``s`` has key ``s__p``.

    - If `enable_metadata_routing=True`: Parameters requested and accepted by
      steps. Each step must have requested certain metadata for these parameters
      to be forwarded to them.

    .. versionchanged:: 1.4
        Parameters are now passed to the ``transform`` method of the
        intermediate steps as well, if requested, and if
        `enable_metadata_routing=True` is set via
        :func:`~sklearn.set_config`.

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

Returns
-------
self : object
    Pipeline with fitted steps.
NzThe `transform_input` parameter can only be set if metadata routing is enabled. You can enable metadata routing using `sklearn.set_config(enable_metadata_routing=True)`.rs   r   r   )r   r&   r
   rr   rq   r   r   )r   rS   rw   r   r   r   r   r   rR   r5   r   rs   )r6   r   r   r   r   Xtlast_step_paramss          r/   rs   Pipeline.fit\  s    V  !!d&:&:&FF  11f1MYYq]Y> T->->s4::QR?R-ST$$5#'#>#> Y] -jjnQ.? @% $? $ 
 %%))"K3CE3JK U  UT s   9A C##
C2c                     U R                   S:H  =(       d3    [        U R                   S5      =(       d    [        U R                   S5      $ )Nrr   rA   rt   r5   rz   r   s    r/   _can_fit_transformPipeline._can_fit_transform  s?    !!]2 ?t,,k:?t,,o>	
r:   c                 *   U R                  SUS9nU R                  XU5      nU R                  n[        SU R	                  [        U R                  5      S-
  5      5         US:X  a  UsSSS5        $ U R                  [        U 5      S-
  X@R                  S   S      US	9n[        US5      (       a  UR                  " XR40 US   D6sSSS5        $ UR                  " XR40 US
   D6R                  " U40 US   D6sSSS5        $ ! , (       d  f       g= f)a
  Fit the model and transform with the final estimator.

Fit all the transformers one after the other and sequentially transform
the data. Only valid if the final estimator either implements
`fit_transform` or `fit` and `transform`.

Parameters
----------
X : iterable
    Training data. Must fulfill input requirements of first step of the
    pipeline.

y : iterable, default=None
    Training targets. Must fulfill label requirements for all steps of
    the pipeline.

**params : dict of str -> object
    - If `enable_metadata_routing=False` (default): Parameters passed to the
      ``fit`` method of each step, where each parameter name is prefixed such
      that parameter ``p`` for step ``s`` has key ``s__p``.

    - If `enable_metadata_routing=True`: Parameters requested and accepted by
      steps. Each step must have requested certain metadata for these parameters
      to be forwarded to them.

    .. versionchanged:: 1.4
        Parameters are now passed to the ``transform`` method of the
        intermediate steps as well, if requested, and if
        `enable_metadata_routing=True`.

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

Returns
-------
Xt : ndarray of shape (n_samples, n_transformed_features)
    Transformed samples.
rt   r   r&   r
   rr   Nrq   r   r   rs   rA   )r   r   r5   r   r   r   rR   r   rz   rt   rs   rA   )r6   r   r   r   r   r   	last_stepr   s           r/   rt   Pipeline.fit_transform  s   X 11PV1WYYq]+))	 T->->s4::QR?R-STM) UT  $::TQ)**R.*;<!  ;  
 y/22 ..-o> UT !}}RF.>u.EFPP*;7 UTTs    D2AD)D
Dpredictc                 $   [        U 5         Un[        5       (       dV  U R                  SS9 H  u  pEnUR                  U5      nM     U R                  S   S   R
                  " U40 UD6sSSS5        $ [        U S40 UD6nU R                  SS9 H%  u  pEnUR                  " U40 Xu   R                  D6nM'     U R                  S   S   R
                  " U40 XpR                  S   S      R
                  D6sSSS5        $ ! , (       d  f       g= f)a  Transform the data, and apply `predict` with the final estimator.

Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls `predict`
method. Only valid if the final estimator implements `predict`.

Parameters
----------
X : iterable
    Data to predict on. Must fulfill input requirements of first step
    of the pipeline.

**params : dict of str -> object
    - If `enable_metadata_routing=False` (default): Parameters to the
      ``predict`` called at the end of all transformations in the pipeline.

    - If `enable_metadata_routing=True`: Parameters requested and accepted by
      steps. Each step must have requested certain metadata for these parameters
      to be forwarded to them.

    .. versionadded:: 0.20

    .. versionchanged:: 1.4
        Parameters are now passed to the ``transform`` method of the
        intermediate steps as well, if requested, and if
        `enable_metadata_routing=True` is set via
        :func:`~sklearn.set_config`.

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

    Note that while this may be used to return uncertainties from some
    models with ``return_std`` or ``return_cov``, uncertainties that are
    generated by the transformations in the pipeline are not propagated
    to the final estimator.

Returns
-------
y_pred : ndarray
    Result of calling `predict` on the final estimator.
Fr   rq   r
   Nr   r   )r0   r   r\   rA   rR   r   r   r6   r   r   r   r]   r   rA   r   s           r/   r   Pipeline.predict  s   X *$/B#%%*.****F&AY",,R0B +Gzz"~a(00>v> 0/ ,D)FvFM&*jjEj&B"((M}/B/L/LM 'C::b>!$,,#JJrN1$56>> 0//   AD4BD
Dr   c           	      p   U R                  SUS9nU R                  XU5      nX@R                  S   S      n[        SU R	                  [        U R                  5      S-
  5      5         U R                  S   S   R                  " XR40 UR                  S0 5      D6nSSS5        U$ ! , (       d  f       W$ = f)a  Transform the data, and apply `fit_predict` with the final estimator.

Call `fit_transform` of each transformer in the pipeline. The
transformed data are finally passed to the final estimator that calls
`fit_predict` method. Only valid if the final estimator implements
`fit_predict`.

Parameters
----------
X : iterable
    Training data. Must fulfill input requirements of first step of
    the pipeline.

y : iterable, default=None
    Training targets. Must fulfill label requirements for all steps
    of the pipeline.

**params : dict of str -> object
    - If `enable_metadata_routing=False` (default): Parameters to the
      ``predict`` called at the end of all transformations in the pipeline.

    - If `enable_metadata_routing=True`: Parameters requested and accepted by
      steps. Each step must have requested certain metadata for these parameters
      to be forwarded to them.

    .. versionadded:: 0.20

    .. versionchanged:: 1.4
        Parameters are now passed to the ``transform`` method of the
        intermediate steps as well, if requested, and if
        `enable_metadata_routing=True`.

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

    Note that while this may be used to return uncertainties from some
    models with ``return_std`` or ``return_cov``, uncertainties that are
    generated by the transformations in the pipeline are not propagated
    to the final estimator.

Returns
-------
y_pred : ndarray
    Result of calling `fit_predict` on the final estimator.
r   r   rq   r   r&   r
   N)r   r   rR   r   r   r   r   get)r6   r   r   r   r   r   params_last_stepy_preds           r/   r   Pipeline.fit_predict  s    f 11f1UYYq]+(B):; T->->s4::QR?R-STZZ^A&22)--mR@F U 	 UT s   (4B&&
B5predict_probac                 $   [        U 5         Un[        5       (       dV  U R                  SS9 H  u  pEnUR                  U5      nM     U R                  S   S   R
                  " U40 UD6sSSS5        $ [        U S40 UD6nU R                  SS9 H%  u  pEnUR                  " U40 Xu   R                  D6nM'     U R                  S   S   R
                  " U40 XpR                  S   S      R
                  D6sSSS5        $ ! , (       d  f       g= f)a  Transform the data, and apply `predict_proba` with the final estimator.

Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`predict_proba` method. Only valid if the final estimator implements
`predict_proba`.

Parameters
----------
X : iterable
    Data to predict on. Must fulfill input requirements of first step
    of the pipeline.

**params : dict of str -> object
    - If `enable_metadata_routing=False` (default): Parameters to the
      `predict_proba` called at the end of all transformations in the pipeline.

    - If `enable_metadata_routing=True`: Parameters requested and accepted by
      steps. Each step must have requested certain metadata for these parameters
      to be forwarded to them.

    .. versionadded:: 0.20

    .. versionchanged:: 1.4
        Parameters are now passed to the ``transform`` method of the
        intermediate steps as well, if requested, and if
        `enable_metadata_routing=True`.

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

Returns
-------
y_proba : ndarray of shape (n_samples, n_classes)
    Result of calling `predict_proba` on the final estimator.
Fr   rq   r
   Nr   r   )r0   r   r\   rA   rR   r   r   r   s           r/   r   Pipeline.predict_proba\  s   N *$/B#%%*.****F&AY",,R0B +Gzz"~a(66rDVD 0/ ,D/LVLM&*jjEj&B"((M}/B/L/LM 'C::b>!$22#JJrN1$56DD 0//r   decision_functionc           
         [        U 5         [        X S5        [        U S40 UD6nUnU R                  SS9 H9  u  pVnUR                  " U40 UR                  U0 5      R                  S0 5      D6nM;     U R                  S   S   R                  " U40 UR                  U R                  S   S   0 5      R                  S0 5      D6sSSS5        $ ! , (       d  f       g= f)	a  Transform the data, and apply `decision_function` with the final estimator.

Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`decision_function` method. Only valid if the final estimator
implements `decision_function`.

Parameters
----------
X : iterable
    Data to predict on. Must fulfill input requirements of first step
    of the pipeline.

**params : dict of string -> object
    Parameters requested and accepted by steps. Each step must have
    requested certain metadata for these parameters to be forwarded to
    them.

    .. versionadded:: 1.4
        Only available if `enable_metadata_routing=True`. See
        :ref:`Metadata Routing User Guide <metadata_routing>` for more
        details.

Returns
-------
y_score : ndarray of shape (n_samples, n_classes)
    Result of calling `decision_function` on the final estimator.
r   Fr   rA   rq   r
   r   N)r0   r   r   r\   rA   r   rR   r   r6   r   r   r   r   r]   r   rA   s           r/   r   Pipeline.decision_function  s    > *$/f,?@ ,D2EPPMB&*jjEj&B"(('++D"599+rJ 'C ::b>!$66##DJJrN1$5r:>>?RTVW 0//s   B:C
Cscore_samplesc                     [        U 5         UnU R                  SS9 H  u    p4UR                  U5      nM     U R                  S   S   R	                  U5      sSSS5        $ ! , (       d  f       g= f)a  Transform the data, and apply `score_samples` with the final estimator.

Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`score_samples` method. Only valid if the final estimator implements
`score_samples`.

Parameters
----------
X : iterable
    Data to predict on. Must fulfill input requirements of first step
    of the pipeline.

Returns
-------
y_score : ndarray of shape (n_samples,)
    Result of calling `score_samples` on the final estimator.
Fr   rq   r
   N)r0   r\   rA   rR   r   )r6   r   r   r]   r   s        r/   r   Pipeline.score_samples  sc    * *$/B%)ZZ5Z%A!1 **2. &B::b>!$2226	 0//s   AA##
A1predict_log_probac                 $   [        U 5         Un[        5       (       dV  U R                  SS9 H  u  pEnUR                  U5      nM     U R                  S   S   R
                  " U40 UD6sSSS5        $ [        U S40 UD6nU R                  SS9 H%  u  pEnUR                  " U40 Xu   R                  D6nM'     U R                  S   S   R
                  " U40 XpR                  S   S      R
                  D6sSSS5        $ ! , (       d  f       g= f)a  Transform the data, and apply `predict_log_proba` with the final estimator.

Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`predict_log_proba` method. Only valid if the final estimator
implements `predict_log_proba`.

Parameters
----------
X : iterable
    Data to predict on. Must fulfill input requirements of first step
    of the pipeline.

**params : dict of str -> object
    - If `enable_metadata_routing=False` (default): Parameters to the
      `predict_log_proba` called at the end of all transformations in the
      pipeline.

    - If `enable_metadata_routing=True`: Parameters requested and accepted by
      steps. Each step must have requested certain metadata for these parameters
      to be forwarded to them.

    .. versionadded:: 0.20

    .. versionchanged:: 1.4
        Parameters are now passed to the ``transform`` method of the
        intermediate steps as well, if requested, and if
        `enable_metadata_routing=True`.

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

Returns
-------
y_log_proba : ndarray of shape (n_samples, n_classes)
    Result of calling `predict_log_proba` on the final estimator.
Fr   rq   r
   Nr   r   )r0   r   r\   rA   rR   r   r   r   s           r/   r   Pipeline.predict_log_proba  s   P *$/B#%%*.****F&AY",,R0B +Gzz"~a(::2HH 0/ ,D2EPPM&*jjEj&B"((M}/B/L/LM 'C::b>!$66#JJrN1$56HH 0//r   c                 Z    U R                   S:H  =(       d    [        U R                   S5      $ )Nrr   rA   r   r   s    r/   _can_transformPipeline._can_transform  s,    $$5 
!!;:
 	
r:   c                     [        U 5         [        X S5        [        U S40 UD6nUnU R                  5        H%  u  pVnUR                  " U40 X6   R                  D6nM'     UsSSS5        $ ! , (       d  f       g= f)a  Transform the data, and apply `transform` with the final estimator.

Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`transform` method. Only valid if the final estimator
implements `transform`.

This also works where final estimator is `None` in which case all prior
transformations are applied.

Parameters
----------
X : iterable
    Data to transform. Must fulfill input requirements of first step
    of the pipeline.

**params : dict of str -> object
    Parameters requested and accepted by steps. Each step must have
    requested certain metadata for these parameters to be forwarded to
    them.

    .. versionadded:: 1.4
        Only available if `enable_metadata_routing=True`. See
        :ref:`Metadata Routing User Guide <metadata_routing>` for more
        details.

Returns
-------
Xt : ndarray of shape (n_samples, n_transformed_features)
    Transformed data.
rA   N)r0   r   r   r\   rA   r   s           r/   rA   Pipeline.transform  sq    D *$/fK8 ,D+HHMB&*jjl"((M}/B/L/LM '3 0//s   AA,,
A:c                 B    [        S U R                  5        5       5      $ )Nc              3   @   #    U  H  u    p[        US 5      v   M     g7f)inverse_transformN)rz   )rB   r]   r   s      r/   rF   2Pipeline._can_inverse_transform.<locals>.<genexpr>I  s     O,wq!71122,s   )allr\   r   s    r/   _can_inverse_transformPipeline._can_inverse_transformH  s    O$**,OOOr:   c                    [        U 5         [        X S5        [        U S40 UD6n[        [	        U R                  5       5      5      nU H%  u  pVnUR                  " U40 X6   R                  D6nM'     UsSSS5        $ ! , (       d  f       g= f)a  Apply `inverse_transform` for each step in a reverse order.

All estimators in the pipeline must support `inverse_transform`.

Parameters
----------
X : array-like of shape (n_samples, n_transformed_features)
    Data samples, where ``n_samples`` is the number of samples and
    ``n_features`` is the number of features. Must fulfill
    input requirements of last step of pipeline's
    ``inverse_transform`` method.

**params : dict of str -> object
    Parameters requested and accepted by steps. Each step must have
    requested certain metadata for these parameters to be forwarded to
    them.

    .. versionadded:: 1.4
        Only available if `enable_metadata_routing=True`. See
        :ref:`Metadata Routing User Guide <metadata_routing>` for more
        details.

Returns
-------
X_original : ndarray of shape (n_samples, n_features)
    Inverse transformed data, that is, data in the original feature
    space.
r  N)r0   r   r   reversedr   r\   r  )r6   r   r   r   reverse_iterr]   r   rA   s           r/   r  Pipeline.inverse_transformK  s    > *$/f,?@ ,D2EPPM#D$67L&2"//&,>> '3  0//s   A(A>>
Bscorec                 >   [        U 5         Un[        5       (       d_  U R                  SS9 H  u  pgnUR                  U5      nM     0 n	Ub  X9S'   U R                  S   S   R
                  " XR40 U	D6sSSS5        $ [        U S4SU0UD6n
UnU R                  SS9 H%  u  pgnUR                  " U40 X   R                  D6nM'     U R                  S   S   R
                  " XR40 XR                  S   S      R
                  D6sSSS5        $ ! , (       d  f       g= f)	am  Transform the data, and apply `score` with the final estimator.

Call `transform` of each transformer in the pipeline. The transformed
data are finally passed to the final estimator that calls
`score` method. Only valid if the final estimator implements `score`.

Parameters
----------
X : iterable
    Data to predict on. Must fulfill input requirements of first step
    of the pipeline.

y : iterable, default=None
    Targets used for scoring. Must fulfill label requirements for all
    steps of the pipeline.

sample_weight : array-like, default=None
    If not None, this argument is passed as ``sample_weight`` keyword
    argument to the ``score`` method of the final estimator.

**params : dict of str -> object
    Parameters requested and accepted by steps. Each step must have
    requested certain metadata for these parameters to be forwarded to
    them.

    .. versionadded:: 1.4
        Only available if `enable_metadata_routing=True`. See
        :ref:`Metadata Routing User Guide <metadata_routing>` for more
        details.

Returns
-------
score : float
    Result of calling `score` on the final estimator.
Fr   Nsample_weightrq   r
   r  r   )r0   r   r\   rA   rR   r  r   )r6   r   r   r  r   r   r]   r   rA   score_paramsr   s              r/   r  Pipeline.scorew  s*   L *$/B#%%*.****F&AY",,R0B +G! ,4A1zz"~a(..rEE 0/ ,g-:>DM B&*jjEj&B"((M}/B/L/LM 'C::b>!$**&zz"~a'89??% 0//s   A'D=BD
Dc                 :    U R                   S   S   R                  $ )z@The classes labels. Only exist if the last step is a classifier.rq   r
   )rR   classes_r   s    r/   r  Pipeline.classes_  s     zz"~a )))r:   c                 p  > [         TU ]  5       nU R                  (       d  U$  U R                  S   S   bT  U R                  S   S   S:w  a>  [        U R                  S   S   5      R                  R
                  UR                  l        [        S U R                   5       5      UR                  l         U R                  S   S   b  U R                  S   S   S:w  a  [        U R                  S   S   5      nUR                  Ul        UR                  R                  UR                  l        [        UR                  5      Ul        [        UR                   5      Ul        [        UR"                  5      Ul        U$ ! [        [        [        4 a     Nf = f! [        [        [        4 a     U$ f = f)Nr   r
   rr   c              3   ~   #    U  H3  u  pUc  M
  US:w  d  M  [        U5      R                  R                  v   M5     g 7f)Nrr   r   
input_tagsr	   )rB   r   r^   s      r/   rF   ,Pipeline.__sklearn_tags__.<locals>.<genexpr>  s;      )",JD 1(,(= 1))00",s   	==&=rq   )super__sklearn_tags__rR   r   r  pairwiser  r	   rw   r   r{   estimator_typetarget_tagsmulti_outputr   classifier_tagsregressor_tagstransformer_tags)r6   tagslast_step_tagsr   s      r/   r  Pipeline.__sklearn_tags__  s   w')zzK	zz!}Q+

1a0@M0Q+3JJqM!$,*XX ( &) )"&**) &DOO"	zz"~a ,B1Bm1S!)$**R.*;!<&4&C&C#0>0J0J0W0W  -'/0N0N'O$&.~/L/L&M#(01P1P(Q% % NI6 	 	 NI6 	 	s%   BF 7CF FFF54F5c                     UnU R                  5        HB  u  p4n[        US5      (       d  [        SR                  U5      5      eUR	                  U5      nMD     U$ )a  Get output feature names for transformation.

Transform input features using the pipeline.

Parameters
----------
input_features : array-like of str or None, default=None
    Input features.

Returns
-------
feature_names_out : ndarray of str objects
    Transformed feature names.
get_feature_names_outzpEstimator {} does not provide get_feature_names_out. Did you mean to call pipeline[:-1].get_feature_names_out()?)r\   rz   r   r   r%  )r6   input_featuresfeature_names_outr]   r   rA   s         r/   r%  Pipeline.get_feature_names_out  sd     +"&**,AY9&=>>$ &, 
 !* ? ?@Q R #/ ! r:   c                 :    U R                   S   S   R                  $ )z7Number of features seen during first step `fit` method.r   r
   )rR   n_features_in_r   s    r/   r*  Pipeline.n_features_in_  s     zz!}Q...r:   c                 :    U R                   S   S   R                  $ )z6Names of features seen during first step `fit` method.r   r
   )rR   feature_names_in_r   s    r/   r-  Pipeline.feature_names_in_   s     zz!}Q111r:   c                     Sn[        U R                  5       H  u  p#US:w  d  M  Un  O   Uc  g [        U5        g! [         a     gf = f)zIndicate whether pipeline has been fit.

This is done by checking whether the last non-`passthrough` step of the
pipeline is fitted.

An empty pipeline is considered fitted.
Nrr   TF)r  rR   r#   r   )r6   r   r]   r-   s       r/   __sklearn_is_fitted__Pipeline.__sklearn_is_fitted__  s]     	$TZZ0LAM)%	 1
 	
 I& 		s   < 
A	A	c                     [        U R                  6 u  pS nU R                   VVs/ s H  u  pEU" XE5      PM     nnnU Vs/ s H  n[        U5      PM     nn[        SUUUSS9$ s  snnf s  snf )Nc                 T    Ub  US:X  a  U  S3$ U  SUR                   R                   3$ )Nrr   z: passthroughz: )r   __name__)r   r   s     r/   	_get_name-Pipeline._sk_visual_block_.<locals>._get_name&  s7    {c]2}--V2cmm44566r:   serialF)r}   name_detailsdash_wrapped)rx   rR   strr   )r6   r]   r~   r5  r   r   r}   r8  s           r/   _sk_visual_block_Pipeline._sk_visual_block_#  su    TZZ(	7 8<zzBz)$4%zB,67JSCJ7%
 	
 C7s   A&A,c                    [        U R                  R                  S9nU R                  SSS9 GH,  u  p#n[	        5       n[        US5      (       a-  UR                  SSS9R                  SSS9R                  SSS9  OVUR                  SSS9R                  SS	S9R                  SSS9R                  SS	S9R                  SSS9R                  SS	S9  UR                  S
S	S9R                  S
S	S9R                  SS	S9R                  SS	S9R                  SS	S9R                  S	S	S9R                  SSS9R                  SS	S9  UR                  " SSU0X40D6  GM/     U R                  S   u  pgUb  US:X  a  U$ [	        5       n[        US5      (       a  UR                  SSS9  OUR                  SSS9R                  SS	S9  UR                  SSS9R                  S
S
S9R                  SSS9R                  SSS9R                  SSS9R                  SSS9R                  S	S	S9R                  SSS9R                  SSS9  UR                  " SSU0Xg0D6  U$ )a  Get metadata routing of this object.

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

Returns
-------
routing : MetadataRouter
    A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
    routing information.
ownerFTr   rt   rs   callercalleer   rA   r   r   r   r   r  r  method_mappingrq   rr   r;   )r   r   r4  r\   r   rz   addrR   )r6   routerr]   r   r   rC  
final_name	final_ests           r/   get_metadata_routingPipeline.get_metadata_routing6  s     dnn&=&=> #jjEdjSNAU*_N uo.."&&eO&LSSHSoSF #&&eE&BSkS:SS>SSDSeS<SkSB "")K"HIk:OK@/D/DK</8KLGK8 JJFnFF? TB !%

2
	] :M '9o..ooNeE:>>[ ?  eE:S	)S4SmS<SS@S+4GSHS+4GSHSKS8S+4GSHSS0 	

L.LZ4KLr:   )rT   rR   rS   rU   T)TT)NNNr?   )NN)8r4  
__module____qualname____firstlineno____doc__r   r   rI   r:  r   rV   r   __annotations__rY   r_   rg   rn   r   r\   r   r   propertyr   r   r5   r   r   r   r   r   rs   r   r    rt   r<   r   r   r   r   r   r   r   rA   r  r  r  r  r  r%  r*  r-  r0  r;  rH  __static_attributes____classcell__r   s   @r/   r&   r&   {   s   rl u& $<j'34;	$D  26dE  '+ 64&,#J'"6 1 1 ) ) 	 	W$:K"^0d &+9	9v
 $%&+:	 &
:x &y129 39v &}56&+6	 7
6p &784 94l &':;<- =-^ &787 974 &':;<5 =5n

 .!* "*XP ()) *)V &w/09 19v * *&P!4 / /
 2 2
:
&I Ir:   r&   c                    U  Vs/ s H=  n[        U[        5      (       a  UO"[        U5      R                  R	                  5       PM?     nn[        [        5      n[        X5       H  u  pEX5==   S-  ss'   M     [        UR                  5       5       H  u  pgUS:X  d  M  X6	 M     [        [        [        U 5      5      5       H+  nX(   nXS;   d  M  X(==   SX5   -  -  ss'   X5==   S-  ss'   M-     [        [        X 5      5      $ s  snf )zGenerate names for estimators.r
   z-%d)rH   r:  r|   r4  lowerr   intrx   r   r   r  ranger   )	r~   r-   r}   	namecountr   r   kvis	            r/   _name_estimatorsr\    s    
 $#I  	3//	T)_5M5M5S5S5UU# 
  C I+	1 , Y__&'6 ( eC
O,-xH	//HOq O	 . E&''%s   ADF)rT   rS   rU   c                 ,    [        [        U5      UU US9$ )a  Construct a :class:`Pipeline` from the given estimators.

This is a shorthand for the :class:`Pipeline` constructor; it does not
require, and does not permit, naming the estimators. Instead, their names
will be set to the lowercase of their types automatically.

Parameters
----------
*steps : list of Estimator objects
    List of the scikit-learn estimators that are chained together.

memory : str or object with the joblib.Memory interface, default=None
    Used to cache the fitted transformers of the pipeline. The last step
    will never be cached, even if it is a transformer. By default, no
    caching is performed. If a string is given, it is the path to the
    caching directory. Enabling caching triggers a clone of the transformers
    before fitting. Therefore, the transformer instance given to the
    pipeline cannot be inspected directly. Use the attribute ``named_steps``
    or ``steps`` to inspect estimators within the pipeline. Caching the
    transformers is advantageous when fitting is time consuming.

transform_input : list of str, default=None
    This enables transforming some input arguments to ``fit`` (other than ``X``)
    to be transformed by the steps of the pipeline up to the step which requires
    them. Requirement is defined via :ref:`metadata routing <metadata_routing>`.
    This can be used to pass a validation set through the pipeline for instance.

    You can only set this if metadata routing is enabled, which you
    can enable using ``sklearn.set_config(enable_metadata_routing=True)``.

    .. versionadded:: 1.6

verbose : bool, default=False
    If True, the time elapsed while fitting each step will be printed as it
    is completed.

Returns
-------
p : Pipeline
    Returns a scikit-learn :class:`Pipeline` object.

See Also
--------
Pipeline : Class for creating a pipeline of transforms with a final
    estimator.

Examples
--------
>>> from sklearn.naive_bayes import GaussianNB
>>> from sklearn.preprocessing import StandardScaler
>>> from sklearn.pipeline import make_pipeline
>>> make_pipeline(StandardScaler(), GaussianNB(priors=None))
Pipeline(steps=[('standardscaler', StandardScaler()),
                ('gaussiannb', GaussianNB())])
rW   )r&   r\  )rT   rS   rU   rR   s       r/   r'   r'     s#    p '	 r:   c                 N    U R                   " U40 UR                   D6nUc  U$ XS-  $ )a  Call transform and apply weight to output.

Parameters
----------
transformer : estimator
    Estimator to be used for transformation.

X : {array-like, sparse matrix} of shape (n_samples, n_features)
    Input data to be transformed.

y : ndarray of shape (n_samples,)
    Ignored.

weight : float
    Weight to be applied to the output of the transformation.

params : dict
    Parameters to be passed to the transformer's ``transform`` method.

    This should be of the form ``process_routing()["step_name"]``.
r@   )r   r   r   r   r   ress         r/   _transform_oner`    s1    , 


6V%5%5
6C~
<r:   c           	      p   U=(       d    0 n[        XE5         [        U S5      (       a$  U R                  " X40 UR                  S0 5      D6nODU R                  " X40 UR                  S0 5      D6R
                  " U40 UR                  S0 5      D6nSSS5        Uc  WU 4$ WU-  U 4$ ! , (       d  f       N= f)z
Fits ``transformer`` to ``X`` and ``y``. The transformed result is returned
with the fitted transformer. If ``weight`` is not ``None``, the result will
be multiplied by ``weight``.

``params`` needs to be of the form ``process_routing()["step_name"]``.
rt   rs   rA   N)r   rz   rt   r   rs   rA   )r   r   r   r   r   r   r   r_  s           r/   r   r     s     \rF	_	6;00++ATFJJPR4STC//!@&**UB*?@JJZZR0C	 
7 ~K<$$ 
7	6s   A:B''
B5c                 z    [        XE5         U R                  " X40 US   D6sSSS5        $ ! , (       d  f       g= f)z*
Fits ``transformer`` to ``X`` and ``y``.
rs   N)r   rs   )r   r   r   r   r   r   r   s          r/   _fit_onerc    s-     
_	6q5ve}5 
7	6	6s   ,
:c                      ^  \ rS rSrSrSSSSS.S jrSS.U 4S	 jjr\S
 5       rS!S jr	S r
S rS rS rS"S jrS rS"S jrS"S jrS rS rS rS rS r\S 5       r\S 5       rS rS rS rS rU 4S jrS rU =r$ )#r%   i  a*  Concatenates results of multiple transformer objects.

This estimator applies a list of transformer objects in parallel to the
input data, then concatenates the results. This is useful to combine
several feature extraction mechanisms into a single transformer.

Parameters of the transformers may be set using its name and the parameter
name separated by a '__'. A transformer may be replaced entirely by
setting the parameter with its name to another transformer, removed by
setting to 'drop' or disabled by setting to 'passthrough' (features are
passed without transformation).

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

.. versionadded:: 0.13

Parameters
----------
transformer_list : list of (str, transformer) tuples
    List of transformer objects to be applied to the data. The first
    half of each tuple is the name of the transformer. The transformer can
    be 'drop' for it to be ignored or can be 'passthrough' for features to
    be passed unchanged.

    .. versionadded:: 1.1
       Added the option `"passthrough"`.

    .. versionchanged:: 0.22
       Deprecated `None` as a transformer in favor of 'drop'.

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

    .. versionchanged:: v0.20
       `n_jobs` default changed from 1 to None

transformer_weights : dict, default=None
    Multiplicative weights for features per transformer.
    Keys are transformer names, values the weights.
    Raises ValueError if key not present in ``transformer_list``.

verbose : bool, default=False
    If True, the time elapsed while fitting each transformer will be
    printed as it is completed.

verbose_feature_names_out : bool, default=True
    If True, :meth:`get_feature_names_out` will prefix all feature names
    with the name of the transformer that generated that feature.
    If False, :meth:`get_feature_names_out` will not prefix any feature
    names and will error if feature names are not unique.

    .. versionadded:: 1.5

Attributes
----------
named_transformers : :class:`~sklearn.utils.Bunch`
    Dictionary-like object, with the following attributes.
    Read-only attribute to access any transformer parameter by user
    given name. Keys are transformer names and values are
    transformer parameters.

    .. versionadded:: 1.2

n_features_in_ : int
    Number of features seen during :term:`fit`. Only defined if the
    underlying first transformer in `transformer_list` 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.3

See Also
--------
make_union : Convenience function for simplified feature union
    construction.

Examples
--------
>>> from sklearn.pipeline import FeatureUnion
>>> from sklearn.decomposition import PCA, TruncatedSVD
>>> union = FeatureUnion([("pca", PCA(n_components=1)),
...                       ("svd", TruncatedSVD(n_components=2))])
>>> X = [[0., 1., 3], [2., 2., 5]]
>>> union.fit_transform(X)
array([[-1.5       ,  3.04, -0.872],
       [ 1.5       ,  5.72,  0.463]])
>>> # An estimator's parameter can be set using '__' syntax
>>> union.set_params(svd__n_components=1).fit_transform(X)
array([[-1.5       ,  3.04],
       [ 1.5       ,  5.72]])

For a more detailed example of usage, see
:ref:`sphx_glr_auto_examples_compose_plot_feature_union.py`.
NFT)n_jobstransformer_weightsrU   verbose_feature_names_outc                @    Xl         X l        X0l        X@l        XPl        g r?   )transformer_listre  rf  rU   rg  )r6   ri  re  rf  rU   rg  s         r/   rY   FeatureUnion.__init__  s      !1#6 )B&r:   r@   c                h   > [         TU ]  US9  U R                  5        H  u  p#n[        X1S9  M     U $ )a  Set the output container when `"transform"` and `"fit_transform"` are called.

`set_output` will set the output of all estimators in `transformer_list`.

Parameters
----------
transform : {"default", "pandas", "polars"}, default=None
    Configure output of `transform` and `fit_transform`.

    - `"default"`: Default output format of a transformer
    - `"pandas"`: DataFrame output
    - `"polars"`: Polars output
    - `None`: Transform configuration is unchanged

Returns
-------
self : estimator instance
    Estimator instance.
r@   )r  r_   r\   r   )r6   rA   r]   r^   r   s       r/   r_   FeatureUnion.set_output  s6    ( 	Y/**,JAQT7 'r:   c                 >    [        S0 [        U R                  5      D6$ )Nr;   )r   r   ri  r   s    r/   named_transformersFeatureUnion.named_transformers  s     3tD11233r:   c                 "    U R                  SUS9$ )a  Get parameters for this estimator.

Returns the parameters given in the constructor as well as the
estimators contained within the `transformer_list` of the
`FeatureUnion`.

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

Returns
-------
params : mapping of string to any
    Parameter names mapped to their values.
ri  rb   rd   rf   s     r/   rg   FeatureUnion.get_params  s    $  2>>r:   c                 *    U R                   " S0 UD6  U $ )a  Set the parameters of this estimator.

Valid parameter keys can be listed with ``get_params()``. Note that
you can directly set the parameters of the estimators contained in
`transformer_list`.

Parameters
----------
**kwargs : dict
    Parameters of this estimator or parameters of estimators contained
    in `transform_list`. Parameters of the transformers may be set
    using its name and the parameter name separated by a '__'.

Returns
-------
self : object
    FeatureUnion class instance.
)ri  rj   rl   s     r/   rn   FeatureUnion.set_params  s    & 	6v6r:   c           	         [        U R                  6 u  pU R                  U5        U H[  nUS;   a  M  [        US5      (       d  [        US5      (       a  [        US5      (       a  M@  [	        SU< S[        U5      < S35      e   g )N)droprr   rs   rt   rA   z4All estimators should implement fit and transform. 'ru   rv   )rx   ri  ry   rz   r{   r|   )r6   r}   r   r   s       r/   _validate_transformers#FeatureUnion._validate_transformers  s    !4#8#89 	U# A++Au%%O)D)DW;N N  ;<d1gG  r:   c                     U R                   (       d  g [        S U R                   5       5      nU R                    H  nX!;  d  M
  [        SU S35      e   g )Nc              3   *   #    U  H	  u  pUv   M     g 7fr?   r;   )rB   r   r]   s      r/   rF   =FeatureUnion._validate_transformer_weights.<locals>.<genexpr>  s     J4I4I   z"Attempting to weight transformer "z-", but it is not present in transformer_list.)rf  setri  rw   )r6   transformer_namesr   s      r/   _validate_transformer_weights*FeatureUnion._validate_transformer_weights  s[    ''JD4I4IJJ,,D, 8 ?A A  -r:   c              #      #    U R                   =(       d    0 R                  nU R                   H(  u  p#US:X  a  M  US:X  a	  [        SS9nX#U" U5      4v   M*     g7f)zO
Generate (name, trans, weight) tuples excluding None and
'drop' transformers.
ru  rr   z
one-to-one)r'  N)rf  r   ri  r   )r6   
get_weightr   r   s       r/   r\   FeatureUnion._iter  s[      ..4"99
00KD%+lK
4 011 1s   AAc           	      $   / nU R                  5        Hj  u  p4n[        US5      (       d0  [        S[        U5      < S[	        U5      R
                  < S35      eUR                  U5      nUR                  X645        Ml     U R                  U5      $ )zGet output feature names for transformation.

Parameters
----------
input_features : array-like of str or None, default=None
    Input features.

Returns
-------
feature_names_out : ndarray of str objects
    Transformed feature names.
r%  zTransformer z (type z)) does not provide get_feature_names_out.)	r\   rz   r   r:  r|   r4  r%  append!_add_prefix_for_feature_names_out)r6   r&  "transformer_with_feature_names_outr   r   r]   r'  s          r/   r%  "FeatureUnion.get_feature_names_out  s     .0*"jjlND5"9::$4y$u+"6"68  !& ; ;N K.55t6OP + 55.
 	
r:   c                 `   U R                   (       a?  [        [        R                  " S U 5       5      5      n[        R
                  " U[        S9$ [        [        R                  " S U 5       5      5      nUR                  S5       VVs/ s H  u  pEUS:  d  M  UPM     nnnUR                  5         U(       a>  [        U5      S:X  a  [        USS 5      SS S	-   nO[        U5      n[        S
U S35      e[        R                  " U VVs/ s H  u  pUPM	     snn5      $ s  snnf s  snnf )ai  Add prefix for feature names out that includes the transformer names.

Parameters
----------
transformer_with_feature_names_out : list of tuples of (str, array-like of str)
    The tuple consistent of the transformer's name and its feature names out.

Returns
-------
feature_names_out : ndarray of shape (n_features,), dtype=str
    Transformed feature names.
c              3   B   ^#    U  H  u  mnU4S  jU 5       v   M     g7f)c              3   2   >#    U  H  nT S U 3v   M     g7f)r   Nr;   )rB   r[  r   s     r/   rF   KFeatureUnion._add_prefix_for_feature_names_out.<locals>.<genexpr>.<genexpr>0  s     ?->vRs^->s   Nr;   )rB   r'  r   s     @r/   rF   AFeatureUnion._add_prefix_for_feature_names_out.<locals>.<genexpr>/  s(      $3U// @->??3Us   )dtypec              3   *   #    U  H	  u  pUv   M     g 7fr?   r;   )rB   r]   ss      r/   rF   r  9  s     Q.Pda.Pr{     r
   N   rq   z, ...]zOutput feature names: z[ are not unique. Please set verbose_feature_names_out=True to add prefixes to feature names)rg  r   r   from_iterablenpasarrayobjectr   most_commonsortr   r:  rw   concatenate)	r6   r  r}   feature_names_countr   counttop_6_overlap
names_reprr]   s	            r/   r  .FeatureUnion._add_prefix_for_feature_names_out  s5    ))## $3U$ E ::e622 &Q.PQQ
 %8$C$CA$F
$F[T%RS)D$F 	 
 	=!Q& !r!23CR88C
 /
( 5R R 
 ~~!CD!CgaT!CD
 	
!
" Es   D$D$D*
c                    [        5       (       a  [        U S40 UD6nO3[        5       nU R                   H  u  pV[        0 S9XE'   X4U   l        M     U R                  X[        U5      nU(       d  U $ U R                  U5        U $ )a  Fit all transformers using X.

Parameters
----------
X : iterable or array-like, depending on transformers
    Input data, used to fit transformers.

y : array-like of shape (n_samples, n_outputs), default=None
    Targets for supervised learning.

**fit_params : dict, default=None
    - If `enable_metadata_routing=False` (default):
      Parameters directly passed to the `fit` methods of the
      sub-transformers.

    - If `enable_metadata_routing=True`:
      Parameters safely routed to the `fit` methods of the
      sub-transformers. See :ref:`Metadata Routing User Guide
      <metadata_routing>` for more details.

    .. versionchanged:: 1.5
        `**fit_params` can be routed via metadata routing API.

Returns
-------
self : object
    FeatureUnion class instance.
rs   rs   )r   r   r   ri  rs   _parallel_funcrc  _update_transformer_list)r6   r   r   
fit_paramsr   r   r]   r   s           r/   rs   FeatureUnion.fitO  s    : +D%F:FM "GM00&+m#*4d#' 1 **1=IK%%l3r:   c                    [        5       (       a  [        U S40 UD6nOe[        5       nU R                   HK  u  pV[	        US5      (       a  [        0 S9XE'   X4U   l        M,  [        0 S9XE'   [        0 S9XE'   X4U   l        MM     U R                  X[        U5      nU(       d%  [        R                  " UR                  S   S45      $ [        U6 u  pU R                  U	5        U R                  U5      $ )a  Fit all transformers, transform the data and concatenate results.

Parameters
----------
X : iterable or array-like, depending on transformers
    Input data to be transformed.

y : array-like of shape (n_samples, n_outputs), default=None
    Targets for supervised learning.

**params : dict, default=None
    - If `enable_metadata_routing=False` (default):
      Parameters directly passed to the `fit` methods of the
      sub-transformers.

    - If `enable_metadata_routing=True`:
      Parameters safely routed to the `fit` methods of the
      sub-transformers. See :ref:`Metadata Routing User Guide
      <metadata_routing>` for more details.

    .. versionchanged:: 1.5
        `**params` can now be routed via metadata routing API.

Returns
-------
X_t : array-like or sparse matrix of                 shape (n_samples, sum_n_components)
    The `hstack` of results of transformers. `sum_n_components` is the
    sum of `n_components` (output dimension) over transformers.
rt   )rt   r  r@   r   )r   r   r   ri  rz   rt   rs   r  r   r  zerosshaperx   r  _hstack)
r6   r   r   r   r   r   objresultsXsr   s
             r/   rt   FeatureUnion.fit_transform~  s    > +D/LVLM "GM!22	300*/b*AM'8>$'5*/B-M'*/"*=M'.4$'+ 3 %%a,>N88QWWQZO,,=%%l3||Br:   c                 4    U R                   (       d  g SX#U4-  $ )Nr   )rU   )r6   r   r   totals       r/   r   FeatureUnion._log_message  s    ||.#d1CCCr:   c                   ^ ^^^^^ [        T R                  5      T l        T R                  5         T R                  5         [        T R	                  5       5      m[        T R                  S9" UUUU UU4S j[        TS5       5       5      $ )z Runs func in parallel on X and yre  c              3      >#    U  H<  u  nu  p#n[        T5      " UTT
US TR                  X![        T	5      5      TU   S9v   M>     g7f)r%   )r   r   r   N)r"   r   r   )rB   r   r   r   r   r   funcr   r6   r   r   s        r/   rF   .FeatureUnion._parallel_func.<locals>.<genexpr>  s]      ,
 5O00d DM .))$S5FG$T* 5Os   AAr
   )r   ri  rv  r~  r\   r!   re  r   )r6   r   r   r  r   r   s   `````@r/   r  FeatureUnion._parallel_func  so     $T%:%: ;##%**,DJJL)t{{+ ,
 ,
 5>lA4N,
 
 	
r:   c                   ^^ [        X S5        [        5       (       a  [        U S40 UD6mO+[        5       mU R                   H  u  p4[        0 S9TU'   M     [        U R                  S9" UU4S jU R                  5        5       5      nU(       d%  [        R                  " TR                  S   S45      $ U R                  U5      $ )a  Transform X separately by each transformer, concatenate results.

Parameters
----------
X : iterable or array-like, depending on transformers
    Input data to be transformed.

**params : dict, default=None

    Parameters routed to the `transform` method of the sub-transformers via the
    metadata routing API. See :ref:`Metadata Routing User Guide
    <metadata_routing>` for more details.

    .. versionadded:: 1.5

Returns
-------
X_t : array-like or sparse matrix of shape (n_samples, sum_n_components)
    The `hstack` of results of transformers. `sum_n_components` is the
    sum of `n_components` (output dimension) over transformers.
rA   r@   r  c           	   3   ^   >#    U  H"  u  pn[        [        5      " UTS UTU   S9v   M$     g 7f)N)r   )r"   r`  )rB   r   r   r   r   r   s       r/   rF   )FeatureUnion.transform.<locals>.<genexpr>  s5      *
'3#V N#E1dF=QUCVW'3s   *-r   )r   r   r   r   ri  r!   re  r\   r  r  r  r  )r6   r   r   r   r]   r  r   s    `    @r/   rA   FeatureUnion.transform  s    , 	&4+D+HHM "GM00&+b&9d# 1 T[[) *
'+zz|*
 
 88QWWQZO,,||Br:   c           	        ^ [        XR                  5       HY  u  nu  p4[        US5      (       d  M  [        UR                  5      S:w  d  M6  [        SU S[        UR                  5       S35      e   [        SU 5      mT(       a+  [        U4S jU 5       5      (       a  TR                  U5      $ [        S U 5       5      (       a$  [        R                  " U5      R                  5       $ [        R                  " U5      $ )	Nr     zTransformer 'z&' returned an array or dataframe with z? dimensions, but expected 2 dimensions (n_samples, n_features).rA   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr?   )is_supported_container)rB   r   adapters     r/   rF   'FeatureUnion._hstack.<locals>.<genexpr>  s     Ib799!<<bs   !c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr?   )r	   issparse)rB   fs     r/   rF   r    s     .2avq!!2s   #%)rx   ri  rz   r   r  rw   r   r  hstackanyr	   tocsrr  )r6   r  r   r   r]   r  s        @r/   r  FeatureUnion._hstack  s    $9$9:LAyq'""s177|q'8 #D6)O177|n %//  ; )d;sIbIII>>"%%.2...==$**,,yy}r:   c                     [        U5      nU R                   VVs/ s H  u  p#X#S:X  a  UO
[        U5      4PM     snnU R                  S S & g s  snnf )Nru  )iterri  next)r6   r   r   olds       r/   r  %FeatureUnion._update_transformer_list  sS    L) "22$
2	 -3T,-?@2$
a  $
s    Ac                 :    U R                   S   S   R                  $ )z+Number of features seen during :term:`fit`.r   r
   )ri  r*  r   s    r/   r*  FeatureUnion.n_features_in_  s     
 $$Q'*999r:   c                 :    U R                   S   S   R                  $ )z*Names of features seen during :term:`fit`.r   r
   )ri  r-  r   s    r/   r-  FeatureUnion.feature_names_in_  s      $$Q'*<<<r:   c                 N    U R                  5        H  u  pn[        U5        M     gr3   )r\   r#   )r6   r]   r   s      r/   r0  "FeatureUnion.__sklearn_is_fitted__  s"    !%AAK( ".r:   c                 >    [        U R                  6 u  p[        SX!S9$ )Nparallel)r}   )rx   ri  r   )r6   r}   r   s      r/   r;  FeatureUnion._sk_visual_block_%  s"    !4#8#89JBBr:   c                 `    [        U[        5      (       d  [        S5      eU R                  U   $ )zReturn transformer with name.zOnly string keys are supported)rH   r:  KeyErrorrn  )r6   r   s     r/   r   FeatureUnion.__getitem__)  s,    $$$;<<&&t,,r:   c                 4   [        U R                  R                  S9nU R                   Hj  u  p#UR                  " S0 X#0DS[        5       R	                  SSS9R	                  SSS9R	                  SSS9R	                  SSS9R	                  SSS90D6  Ml     U$ )a"  Get metadata routing of this object.

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

.. versionadded:: 1.5

Returns
-------
routing : MetadataRouter
    A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
    routing information.
r>  rC  rs   r@  rt   rA   r;   )r   r   r4  ri  rD  r   )r6   rE  r   r   s       r/   rH  !FeatureUnion.get_metadata_routing/  s      dnn&=&=>!%!6!6DJJ %,E%0OODOE:OK@K< "7 r:   c                    > [         TU ]  5       n [        S U R                   5       5      UR                  l        U$ ! [         a     U$ f = f)Nc              3   t   #    U  H.  u  pUS ;  d  M  [        U5      R                  R                  v   M0     g7f)>   ru  rr   Nr  )rB   r   r   s      r/   rF   0FeatureUnion.__sklearn_tags__.<locals>.<genexpr>O  s4      )#8KD 77 2**11#8s   8&8)r  r  r  ri  r  r	   	Exception)r6   r!  r   s     r/   r  FeatureUnion.__sklearn_tags__L  s[    w')
	%( )#'#8#8) &DOO"   	 	s   +> 
AA)re  ri  rf  rU   rg  rJ  r?   ) r4  rK  rL  rM  rN  rY   r_   rP  rn  rg   rn   rv  r~  r\   r%  r  rs   rt   r   r  rA   r  r  r*  r-  r0  r;  r   rH  r  rQ  rR  rS  s   @r/   r%   r%     s    eV  "&C '+  2 4 4?(,$
2
8.
`-^5 nD

(( T&
 : : = =
C-: r:   r%   Tre  rU   rg  c                 ,    [        [        U5      U UUS9$ )a  Construct a :class:`FeatureUnion` from the given transformers.

This is a shorthand for the :class:`FeatureUnion` constructor; it does not
require, and does not permit, naming the transformers. Instead, they will
be given names automatically based on their types. It also does not allow
weighting.

Parameters
----------
*transformers : list of estimators
    One or more estimators.

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

    .. versionchanged:: v0.20
       `n_jobs` default changed from 1 to None.

verbose : bool, default=False
    If True, the time elapsed while fitting each transformer will be
    printed as it is completed.

verbose_feature_names_out : bool, default=True
    If True, the feature names generated by `get_feature_names_out` will
    include prefixes derived from the transformer names.

Returns
-------
f : FeatureUnion
    A :class:`FeatureUnion` object for concatenating the results of multiple
    transformer objects.

See Also
--------
FeatureUnion : Class for concatenating the results of multiple transformer
    objects.

Examples
--------
>>> from sklearn.decomposition import PCA, TruncatedSVD
>>> from sklearn.pipeline import make_union
>>> make_union(PCA(), TruncatedSVD())
 FeatureUnion(transformer_list=[('pca', PCA()),
                               ('truncatedsvd', TruncatedSVD())])
r  )r%   r\  )re  rU   rg  r   s       r/   r(   r(   \  s#    f &";	 r:   ) NN)DrN  r*   collectionsr   r   
contextlibr   copyr   	itertoolsr   r   numpyr  scipyr	   baser   r   r   
exceptionsr   preprocessingr   utilsr   utils._metadata_requestsr   utils._param_validationr   r   utils._repr_html.estimatorr   utils._set_outputr   r   utils._tagsr   utils._user_interfacer   utils.metadata_routingr   r   r   r   r   r   utils.metaestimatorsr   r    utils.parallelr!   r"   utils.validationr#   r$   __all__r0   r<   rM   r&   r\  r'   r`  r   rc  r%   r(   r;   r:   r/   <module>r     s    W
  , %  #   7 7 & .  - 7 4 " 6  A - ;
E 
 
4
%PD DN((0 "&tU =@< IM%06B	#%5 B	L 8r:   