§
    rŠtj¶  ã                   óŒ   — d Z ddlmZmZ ddl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)ÚsuppressN)ÚBaseEstimator)Ú_safe_indexing)Úavailable_if)Úget_tagsr   c                   óV   ‡ — e Zd ZdZed„ ¦   «         Zd	ˆ fd„	Zˆ fd„Zd„ Zd„ Z	d„ Z
ˆ xZS )
Ú_BaseCompositionaÈ  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                 ó   — d S ©N© )Úselfs    úZ/var/www/html/CA-Chatbot/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ó   ø€ Ý‰gŒg× Ò  dÐ Ñ+Ô+ˆØð 	ØˆJå˜T 4Ñ(Ô(ˆ
ð	Ø�JŠJ�zÑ"Ô"Ð"Ð"øÝ�:Ð&ð 	ð 	ð 	ð ˆJˆJˆJð	øøøð  *ð 	8ð 	8‰OˆD�)Ý�y ,Ñ/Ô/ð 8Ø"+×"6Ò"6¸DÐ"6Ñ"AÔ"A×"GÒ"GÑ"IÔ"Ið 8ð 8‘J�C˜Ø27�C D D D¨#¨#Ð.Ñ/Ð/øØˆ
s   ¹A ÁA%Á$A%c           	      óö  •— ||v r$t          | ||                     |¦  «        ¦  «         t          | |¦  «        }t          |t          ¦  «        r‘|r�t          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_params9   s^  ø€ ð �6ˆ>ˆ>Ý�D˜$ §
¢
¨4Ñ 0Ô 0Ñ1Ô1Ð1å˜˜dÑ#Ô#ˆÝ�e�TÑ"Ô"ð 	N uð 	Nõ �)Ñ$Ô$ð Nð NÝ # U ‘�
˜AÝ  §¢¡¤Ñ/Ô/ð Nð N�DØ 4Ð'Ð'¨D°JÐ,>Ð,>Ø×/Ò/°°d¸F¿JºJÀtÑ<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   )r,   r   Ú	enumerater)   )r   r   r"   Únew_valÚnew_estimatorsÚiÚestimator_namer3   s           r   r/   z#_BaseComposition._replace_estimatorN   sw   € å�g d¨DÑ1Ô1Ñ2Ô2ˆÝ&/°Ñ&?Ô&?ð 	ð 	Ñ"ˆAÑ"� Ø Ò%Ð%Ø%)¨7 O�˜qÑ!Ø�ð &õ 	��d˜NÑ+Ô+Ð+Ð+Ð+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>a   s   € Ð@Ð@Ð@ $°4¸4°<°<˜°<°<°<r   z.Estimator names must not contain __: got {0!r})ÚlenÚsetr   Úformatr,   Úintersectionr   Úsorted)r   ÚnamesÚinvalid_namess      r   Ú_validate_namesz _BaseComposition._validate_namesW   sí   € Ý�s�5‰zŒz‰?Œ?�c %™jœjÒ(Ð(ÝÐC×JÒJÍ4ÐPUÉ;Ì;ÑWÔWÑXÔXÐXÝ˜E™
œ
×/Ò/°·²ÀU°Ñ0KÔ0KÑLÔLˆØð 	ÝØL×SÒSÝ˜=Ñ)Ô)ñô ñô ð ð
 AÐ@¨%Ð@Ñ@Ô@ˆØð 	ÝØ@×GÒGÈÑVÔVñô ð ð	ð 	r   c                 óz   — |D ]7}t          |t          ¦  «        r t          d|j        › d|j        › d�¦  «        ‚Œ8d S )Nz Expected an estimator instance (z"()), got estimator class instead (z).)r+   Útyper   Ú__name__)r   r!   r#   s      r   Ú_check_estimators_are_instancesz0_BaseComposition._check_estimators_are_instancesg   ss   € Ø#ð 	ð 	ˆIÝ˜)¥TÑ*Ô*ð ÝðG°yÔ7Ið Gð GØ09Ô0BðGð Gð Gñô ð ðð	ð 	r   )T)rI   Ú
__module__Ú__qualname__Ú__doc__r   r   r'   r4   r/   rF   rJ   Ú__classcell__)r&   s   @r   r   r      s¨   ø€ € € € € ð	ð 	ð ðð ñ „^ððð ð ð ð ð ð,ð ð ð ð ð*,ð ,ð ,ðð ð ð ð ð ð ð ð ð r   r   )Ú	metaclassc                 óŽ  — t          | ¦  «        j        j        r„t          |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   é   z"X should be a square kernel matrixN)	r	   Ú
input_tagsÚpairwiser   r   rQ   ÚnpÚix_r   )r#   ÚXÚyÚindicesÚtrain_indicesÚX_subsetÚy_subsets          r   Ú_safe_splitr]   p   s×   € õX �	ÑÔÔ%Ô.ð .Ý�q˜'Ñ"Ô"ð 	Ýð=ñô ð ð
 Œ7�1Œ:˜œ œÒ#Ð#ÝÐAÑBÔBÐBØÐ Ø�œ ¨Ñ1Ô1Ô2ˆHˆHà�œ ¨Ñ7Ô7Ô8ˆHˆHå! ! WÑ-Ô-ˆà€}Ý! ! WÑ-Ô-ˆˆàˆà�XÐÐr   r   )rM   Úabcr   r   Ú
contextlibr   ÚnumpyrU   Úsklearn.baser   Úsklearn.utilsr   Úsklearn.utils._available_ifr   Úsklearn.utils._tagsr	   Ú__all__r   r]   r   r   r   ú<module>rf      sò   ðØ $Ð $ð
 (Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø Ð Ð Ð Ð Ð à Ð Ð Ð à &Ð &Ð &Ð &Ð &Ð &Ø (Ð (Ð (Ð (Ð (Ð (Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø (Ð (Ð (Ð (Ð (Ð (àÐ
€ðZð Zð Zð Zð Z�}°ð Zñ Zô Zð ZðzAð Að Að Að Að Ar   