
    KiZ                         S r SSKJrJr  SSKJr  SSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJr  S	/r " S
 S\	\S9rSS jrg)zUtilities for meta-estimators.    )ABCMetaabstractmethod)suppressN)BaseEstimator)_safe_indexing)available_if)get_tagsr   c                   X   ^  \ rS rSrSr\S 5       rS	U 4S jjrU 4S jrS r	S r
SrU =r$ )
_BaseComposition   a  Base class for estimators that are composed of named sub-estimators.

This abstract class provides parameter management functionality for
meta-estimators that contain collections of named estimators. It handles
the complex logic for getting and setting parameters on nested estimators
using the "estimator_name__parameter" syntax.

The class is designed to work with any attribute containing a list of
(name, estimator) tuples.
c                     g N )selfs    ^/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/sklearn/utils/metaestimators.py__init___BaseComposition.__init__   s        c                 <  > [         T	U ]  US9nU(       d  U$ [        X5      n UR                  U5        U HI  u  pV[        US5      (       d  M  UR                  SS9R                  5        H  u  pxXU< SU< 3'   M     MK     U$ ! [        [
        4 a    Us $ f = f)Ndeep
get_paramsT__)superr   getattrupdate	TypeError
ValueErrorhasattritems)
r   attrr   out
estimatorsname	estimatorkeyvalue	__class__s
            r   _get_params_BaseComposition._get_params#   s    g d +JT(
	JJz"  *ODy,//"+"6"6D"6"A"G"G"IJC27D#./ #J  * 
 :& 	 J	s   B BBc           	        > X;   a  [        XUR                  U5      5        [        X5      n[        U[        5      (       ay  U(       ar  [        [        5         [        U6 u  pE[	        UR                  5       5       H3  nSU;  d  M  Xd;   d  M  U R                  XUR                  U5      5        M5     S S S 5        [        TU ],  " S0 UD6  U $ ! , (       d  f       N = f)Nr   r   )setattrpopr   
isinstancelistr   r   zipkeys_replace_estimatorr   
set_params)r   r!   paramsr    
item_names_r$   r(   s          r   _set_params_BaseComposition._set_params9   s     >D

4 01#eT""u )$ #U
 /D4'D,>//FJJt<LM 0 % 	$V$ %$s   +CC%C
Cc                     [        [        X5      5      n[        U5       H  u  nu  pgXb:X  d  M  X#4XE'     O   [        XU5        g r   )r/   r   	enumerater,   )r   r!   r$   new_valnew_estimatorsiestimator_namer6   s           r   r2   #_BaseComposition._replace_estimatorN   sH    gd12&/&?"A"%%)O! '@ 	N+r   c                    [        [        U5      5      [        U5      :w  a#  [        SR                  [	        U5      5      5      e[        U5      R                  U R                  SS95      nU(       a#  [        SR                  [        U5      5      5      eU Vs/ s H  nSU;   d  M  UPM     nnU(       a  [        SR                  U5      5      eg s  snf )Nz$Names provided are not unique: {0!r}Fr   z:Estimator names conflict with constructor arguments: {0!r}r   z.Estimator names must not contain __: got {0!r})lensetr   formatr/   intersectionr   sorted)r   namesinvalid_namesr$   s       r   _validate_names _BaseComposition._validate_namesW   s    s5z?c%j(CJJ4PU;WXXE
//U0KLLSS=) 
 +0@%$44<%@@GGV   As   
C(Cr   )T)__name__
__module____qualname____firstlineno____doc__r   r   r)   r7   r2   rH   __static_attributes____classcell__)r(   s   @r   r   r      s5    	  ,*, r   r   )	metaclassc                    [        U 5      R                  R                  (       a~  [        US5      (       d  [	        S5      eUR
                  S   UR
                  S   :w  a  [	        S5      eUc  U[        R                  " X35         nO%U[        R                  " X45         nO[        X5      nUb  [        X#5      nXV4$ SnXV4$ )aa  Create subset of dataset and properly handle kernels.

Slice X, y according to indices for cross-validation, but take care of
precomputed kernel-matrices or pairwise affinities / distances.

If ``estimator._pairwise is True``, X needs to be square and
we slice rows and columns. If ``train_indices`` is not None,
we slice rows using ``indices`` (assumed the test set) and columns
using ``train_indices``, indicating the training set.

Labels y will always be indexed only along the first axis.

Parameters
----------
estimator : object
    Estimator to determine whether we should slice only rows or rows and
    columns.

X : array-like, sparse matrix or iterable
    Data to be indexed. If ``estimator._pairwise is True``,
    this needs to be a square array-like or sparse matrix.

y : array-like, sparse matrix or iterable
    Targets to be indexed.

indices : array of int
    Rows to select from X and y.
    If ``estimator._pairwise is True`` and ``train_indices is None``
    then ``indices`` will also be used to slice columns.

train_indices : array of int or None, default=None
    If ``estimator._pairwise is True`` and ``train_indices is not None``,
    then ``train_indices`` will be use to slice the columns of X.

Returns
-------
X_subset : array-like, sparse matrix or list
    Indexed data.

y_subset : array-like, sparse matrix or list
    Indexed targets.

shapezXPrecomputed kernels or affinity matrices have to be passed as arrays or sparse matrices.r      z"X should be a square kernel matrixN)	r	   
input_tagspairwiser   r   rS   npix_r   )r%   Xyindicestrain_indicesX_subsety_subsets          r   _safe_splitr_   h   s    X 	%%..q'""= 
 771:#ABB 12H78H!!-}!!-  r   r   )rN   abcr   r   
contextlibr   numpyrW   sklearn.baser   sklearn.utilsr   sklearn.utils._available_ifr   sklearn.utils._tagsr	   __all__r   r_   r   r   r   <module>rh      s>    $
 (   & ( 4 (
R} RjAr   