
    0Ph                         d Z ddlmZmZ ddlmZ ddlmZmZ ddl	Z
ddlmZ ddlmZ dd	lmZ d
dlmZ dgZ G d dee          ZddZdS )zUtilities for meta-estimators.    )ABCMetaabstractmethod)suppress)AnyListN   )BaseEstimator)_safe_indexing)get_tags   )available_ifr   c                   h     e Zd ZU dZee         ed<   ed             Zd	 fd	Z	 fdZ
d Zd Z xZS )
_BaseCompositionzJHandles parameter management for classifiers composed of named estimators.stepsc                     d S N )selfs    \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/utils/metaestimators.py__init__z_BaseComposition.__init__   s        Tc                 t   t                                          |          }|s|S t          | |          }	 |                    |           n# t          t
          f$ r |cY S w xY w|D ]M\  }}t          |d          r8|                    d                                          D ]\  }}|||d|<   N|S )Ndeep
get_paramsT__)superr   getattrupdate	TypeError
ValueErrorhasattritems)
r   attrr   out
estimatorsname	estimatorkeyvalue	__class__s
            r   _get_paramsz_BaseComposition._get_params   s    gg  d ++ 	JT4((
	JJz"""":& 	 	 	 JJJ	  * 	8 	8OD)y,// 8"+"6"6D"6"A"A"G"G"I"I 8 8JC27CDDD##.//
s   A A%$A%c           	         ||v r$t          | ||                    |                     t          | |          }t          |t                    r|rt          t                    5  t          | \  }}t	          |                                          D ]4}d|vr.||v r*| 	                    |||                    |                     5	 d d d            n# 1 swxY w Y    t                      j        di | | S )Nr   r   )setattrpopr   
isinstancelistr   r    zipkeys_replace_estimatorr   
set_params)r   r$   paramsr#   
item_names_r'   r+   s          r   _set_paramsz_BaseComposition._set_params3   s^    6>>D$

4 0 0111d##eT"" 	Nu 	N )$$ N N #U
A // N ND4''DJ,>,>//dFJJt<L<LMMMNN N N N N N N N N N N N N N N 	$$V$$$s   %A#CCCc                     t          t          | |                    }t          |          D ]\  }\  }}||k    r	||f||<    nt          | ||           d S r   )r1   r   	enumerater.   )r   r$   r'   new_valnew_estimatorsiestimator_namer8   s           r   r4   z#_BaseComposition._replace_estimatorH   sw    gdD1122&/&?&? 	 	"A"%%%)7Oq! & 	dN+++++r   c                    t          t          |                    t          |          k    r/t          d                    t	          |                              t          |                              |                     d                    }|r/t          d                    t          |                              d |D             }|r"t          d                    |                    d S )Nz$Names provided are not unique: {0!r}Fr   z:Estimator names conflict with constructor arguments: {0!r}c                     g | ]}d |v |	S )r   r   ).0r'   s     r   
<listcomp>z4_BaseComposition._validate_names.<locals>.<listcomp>[   s    @@@$44<<<<<r   z.Estimator names must not contain __: got {0!r})lensetr!   formatr1   intersectionr   sorted)r   namesinvalid_namess      r   _validate_namesz _BaseComposition._validate_namesQ   s    s5zz??c%jj((CJJ4PU;;WWXXXE

//U0K0KLL 	LSS=))   
 A@%@@@ 	@GGVV  	 	r   )T)__name__
__module____qualname____doc__r   r   __annotations__r   r   r,   r9   r4   rK   __classcell__)r+   s   @r   r   r      s         TT9  ^     ,    *, , ,      r   r   )	metaclassc                    t          |           j        j        rt          |d          st	          d          |j        d         |j        d         k    rt	          d          ||t          j        ||                   }n,|t          j        ||                   }nt          ||          }|t          ||          }nd}||fS )a  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   r   z"X should be a square kernel matrixN)	r   
input_tagspairwiser"   r!   rT   npix_r
   )r(   Xyindicestrain_indicesX_subsety_subsets          r   _safe_splitr_   b   s    X 	%. .q'"" 	=  
 71:##ABBB 112HH778HH!!W--}!!W--Xr   r   )rO   abcr   r   
contextlibr   typingr   r   numpyrW   baser	   utilsr
   utils._tagsr   _available_ifr   __all__r   r_   r   r   r   <module>ri      s
   $ $
 ( ' ' ' ' ' ' '                               " " " " " " " " " " " " ' ' ' ' ' '
K K K K K} K K K K\A A A A A Ar   