
    -i/)                         S 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JrJr  SSK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 jrSS jr " S S\
\	\S9rS r " S S\
\\S9rg)z)Base class for ensemble-based estimators.    )ABCMetaabstractmethodN)effective_n_jobs   )BaseEstimatorMetaEstimatorMixincloneis_classifieris_regressor)Bunchcheck_random_state)get_tags)_print_elapsed_time)_routing_enabled)_BaseCompositionc                    [        5       (       d0  SU;   a*   [        XE5         U R                  XUS   S9  SSS5        U $ [        XE5         U R                  " X40 UD6  SSS5        U $ ! , (       d  f       U $ = f! [         aD  nS[	        U5      ;   a/  [        SR                  U R                  R                  5      5      Uee SnAff = f! , (       d  f       U $ = f)z7Private function used to fit an estimator within a job.sample_weight)r   Nz+unexpected keyword argument 'sample_weight'z8Underlying estimator {} does not support sample weights.)r   r   fit	TypeErrorstrformat	__class____name__)	estimatorXy
fit_paramsmessage_clsnamemessageexcs          I/var/www/html/venv/lib/python3.13/site-packages/sklearn/ensemble/_base.py_fit_single_estimatorr"      s     /Z"?
	$_>a*_2MN ?  !:MM!-*- ; ?>   	<CHNUU!++44 	
 	 ;:s?   A; A)A; C)
A83A; 8A; ;
C	?CC	
Cc                 J   [        U5      n0 n[        U R                  SS95       H`  nUS:X  d  UR                  S5      (       d  M!  UR	                  [
        R                  " [
        R                  5      R                  5      X#'   Mb     U(       a  U R                  " S0 UD6  gg)ae  Set fixed random_state parameters for an estimator.

Finds all parameters ending ``random_state`` and sets them to integers
derived from ``random_state``.

Parameters
----------
estimator : estimator supporting get/set_params
    Estimator with potential randomness managed by random_state
    parameters.

random_state : int, RandomState instance or None, default=None
    Pseudo-random number generator to control the generation of the random
    integers. Pass an int for reproducible output across multiple function
    calls.
    See :term:`Glossary <random_state>`.

Notes
-----
This does not necessarily set *all* ``random_state`` attributes that
control an estimator's randomness, only those accessible through
``estimator.get_params()``.  ``random_state``s not controlled include
those belonging to:

    * cross-validation splitters
    * ``scipy.stats`` rvs
Tdeeprandom_state__random_stateN )
r   sorted
get_paramsendswithrandintnpiinfoint32max
set_params)r   r&   to_setkeys       r!   _set_random_statesr4   +   s    8 &l3LFi***56. CLL1A$B$B&..rxx/A/E/EFFK 7 &v&     c                   h    \ rS rSrSr\ SS\" 5       S.S jj5       rSS jrSS jr	S	 r
S
 rS rSrg)BaseEnsembleQ   a  Base class for all ensemble classes.

Warning: This class should not be used directly. Use derived classes
instead.

Parameters
----------
estimator : object
    The base estimator from which the ensemble is built.

n_estimators : int, default=10
    The number of estimators in the ensemble.

estimator_params : list of str, default=tuple()
    The list of attributes to use as parameters when instantiating a
    new base estimator. If none are given, default parameters are used.

Attributes
----------
estimator_ : estimator
    The base estimator from which the ensemble is grown.

estimators_ : list of estimators
    The collection of fitted base estimators.
N
   )n_estimatorsestimator_paramsc                (    Xl         X l        X0l        g N)r   r:   r;   )selfr   r:   r;   s       r!   __init__BaseEnsemble.__init__l   s     #( 0r5   c                 N    U R                   b  U R                   U l        gXl        g)z=Check the base estimator.

Sets the `estimator_` attributes.
N)r   
estimator_)r>   defaults     r!   _validate_estimator BaseEnsemble._validate_estimator}   s    
 >>%"nnDO%Or5   c                    [        U R                  5      nUR                  " S0 U R                   Vs0 s H  oD[	        X5      _M     snD6  Ub  [        X25        U(       a  U R                  R                  U5        U$ s  snf )zMake and configure a copy of the `estimator_` attribute.

Warning: This method should be used to properly instantiate new
sub-estimators.
r(   )r	   rB   r1   r;   getattrr4   estimators_append)r>   rI   r&   r   ps        r!   _make_estimatorBaseEnsemble._make_estimator   ss     $//*	TT=R=RS=R74#3 3=RST#y7##I.  Ts   A>c                 ,    [        U R                  5      $ )z0Return the number of estimators in the ensemble.)lenrH   r>   s    r!   __len__BaseEnsemble.__len__   s    4##$$r5   c                      U R                   U   $ )z.Return the index'th estimator in the ensemble.)rH   )r>   indexs     r!   __getitem__BaseEnsemble.__getitem__   s    &&r5   c                 ,    [        U R                  5      $ )z0Return iterator over estimators in the ensemble.)iterrH   rO   s    r!   __iter__BaseEnsemble.__iter__   s    D$$%%r5   )r   rB   r;   r:   r=   )TN)r   
__module____qualname____firstlineno____doc__r   tupler?   rD   rK   rP   rT   rX   __static_attributes__r(   r5   r!   r7   r7   Q   sH    4  
1 
1 
1 &"%'&r5   r7   )	metaclassc                     [        [        U5      U 5      n[        R                  " XU-  [        S9nUSX-  === S-  sss& [        R
                  " U5      nXR                  5       S/UR                  5       -   4$ )z;Private function used to partition estimators between jobs.)dtypeN   r   )minr   r-   fullintcumsumtolist)r:   n_jobsn_estimators_per_jobstartss       r!   _partition_estimatorsrl      st     !&)<8F 7766+AM0<01Q61YY+,F..01#2GGGr5   c                   n   ^  \ rS rSrSr\S 5       r\S 5       rS r	U 4S jr
S
U 4S jjrU 4S jrS	rU =r$ )_BaseHeterogeneousEnsemble   aI  Base class for heterogeneous ensemble of learners.

Parameters
----------
estimators : list of (str, estimator) tuples
    The ensemble of estimators to use in the ensemble. Each element of the
    list is defined as a tuple of string (i.e. name of the estimator) and
    an estimator instance. An estimator can be set to `'drop'` using
    `set_params`.

Attributes
----------
estimators_ : list of estimators
    The elements of the estimators parameter, having been fitted on the
    training data. If an estimator has been set to `'drop'`, it will not
    appear in `estimators_`.
c                 >    [        S0 [        U R                  5      D6$ )zgDictionary to access any fitted sub-estimators by name.

Returns
-------
:class:`~sklearn.utils.Bunch`
r(   )r   dict
estimatorsrO   s    r!   named_estimators+_BaseHeterogeneousEnsemble.named_estimators   s     -tDOO,--r5   c                     Xl         g r=   rr   )r>   rr   s     r!   r?   #_BaseHeterogeneousEnsemble.__init__   s    $r5   c           	         [        U R                  5      S:X  d!  [        S U R                   5       5      (       d  [        S5      e[	        U R                  6 u  pU R                  U5        [        S U 5       5      nU(       d  [        S5      e[        U 5      (       a  [        O[        nU HT  nUS:w  d  M  U" U5      (       a  M  [        SR                  UR                  R                  UR                  SS  5      5      e   X4$ )	Nr   c              3      #    U  H5  n[        U[        [        45      =(       a    [        US    [        5      v   M7     g7f)r   N)
isinstancer^   listr   ).0items     r!   	<genexpr>B_BaseHeterogeneousEnsemble._validate_estimators.<locals>.<genexpr>   s5      0
' teT]+H
47C0HH's   =?zfInvalid 'estimators' attribute, 'estimators' should be a non-empty list of (string, estimator) tuples.c              3   *   #    U  H	  oS :g  v   M     g7f)dropNr(   r|   ests     r!   r~   r      s     @Zc6MZs   zHAll estimators are dropped. At least one is required to be an estimator.r   z The estimator {} should be a {}.   )rN   rr   all
ValueErrorzip_validate_namesanyr
   r   r   r   r   )r>   namesrr   has_estimatoris_estimator_typer   s         r!   _validate_estimators/_BaseHeterogeneousEnsemble._validate_estimators   s    t1$C 0
0
 -
 -
 @   1U#@Z@@& 
 .;4-@-@MlCf}%6s%;%; 6==..0A0J0J120N     r5   c                 (   > [         TU ]  " S0 UD6  U $ )a3  
Set the parameters of an estimator from the ensemble.

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

Parameters
----------
**params : keyword arguments
    Specific parameters using e.g.
    `set_params(parameter_name=new_value)`. In addition, to setting the
    parameters of the estimator, the individual estimator of the
    estimators can also be set, or can be removed by setting them to
    'drop'.

Returns
-------
self : object
    Estimator instance.
rv   )super_set_params)r>   paramsr   s     r!   r1   %_BaseHeterogeneousEnsemble.set_params   s    , 	3F3r5   c                     > [         TU ]  SUS9$ )a  
Get the parameters of an estimator from the ensemble.

Returns the parameters given in the constructor as well as the
estimators contained within the `estimators` parameter.

Parameters
----------
deep : bool, default=True
    Setting it to True gets the various estimators and the parameters
    of the estimators as well.

Returns
-------
params : dict
    Parameter and estimator names mapped to their values or parameter
    names mapped to their values.
rr   r$   )r   _get_params)r>   r%   r   s     r!   r*   %_BaseHeterogeneousEnsemble.get_params  s    & w"<d";;r5   c                    > [         TU ]  5       n [        S U R                   5       5      UR                  l        [        S U R                   5       5      UR                  l        U$ ! [         a     U$ f = f)Nc              3   |   #    U  H2  nUS    S:w  a"  [        US    5      R                  R                  OSv   M4     g7frc   r   TN)r   
input_tags	allow_nanr   s     r!   r~   >_BaseHeterogeneousEnsemble.__sklearn_tags__.<locals>.<genexpr>&  s<      ,*C :=Q69IQ ++55tS*   :<c              3   |   #    U  H2  nUS    S:w  a"  [        US    5      R                  R                  OSv   M4     g7fr   )r   r   sparser   s     r!   r~   r   *  s<      )*C 7:!f6FQ ++22DP*r   )r   __sklearn_tags__r   rr   r   r   r   	Exception)r>   tagsr   s     r!   r   +_BaseHeterogeneousEnsemble.__sklearn_tags__#  s}    w')	(+ ,??, )DOO% &) )??) &DOO"   	 	s   AA) )
A76A7rv   )T)r   rZ   r[   r\   r]   propertyrs   r   r?   r   r1   r*   r   r_   __classcell__)r   s   @r!   rn   rn      sJ    $ . . % %!@2<* r5   rn   )NNr=   )r]   abcr   r   numpyr-   joblibr   baser   r   r	   r
   r   utilsr   r   utils._tagsr   utils._user_interfacer   utils.metadata_routingr   utils.metaestimatorsr   r"   r4   r7   rl   rn   r(   r5   r!   <module>r      sh    /
 (  # X X - " 7 5 3 @D0#'LQ&%} Q&h
HA(GAr5   