U
    9%e                     @   sX   d Z ddl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 G dd	 d	eZdS )
zY
Feature agglomeration. Base classes and functions for performing feature
agglomeration.
    N)issparse   )TransformerMixin)metadata_routing)check_is_fittedc                   @   s,   e Zd ZdZdejiZdd ZdddZdS )	AgglomerationTransformzH
    A class for feature agglomeration via the transform interface.
    Xredc                    s   t  j dd jtjkrbt sbtj jd }t	 fddt
|D }n( fddtjD }t	|j}|S )a  
        Transform a new matrix using the built clustering.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or                 (n_samples, n_samples)
            A M by N array of M observations in N dimensions or a length
            M array of M one-dimensional observations.

        Returns
        -------
        Y : ndarray of shape (n_samples, n_clusters) or (n_clusters,)
            The pooled values for each feature cluster.
        F)resetr   c              	      s*   g | ]"}t j |d d f  qS )N)npbincountlabels_).0iXselfsize e/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sklearn/cluster/_feature_agglomeration.py
<listcomp>7   s     z4AgglomerationTransform.transform.<locals>.<listcomp>c                    s,   g | ]$}j  d d j|kf ddqS )N   )Zaxis)pooling_funcr   )r   l)r   r   r   r   r   :   s   )r   Z_validate_datar   r
   Zmeanr   r   r   shapearrayrangeuniqueT)r   r   Z	n_samplesZnXr   r   r   	transform   s    

z AgglomerationTransform.transformNc                 C   sp   |dkr|dkrt d|dk	r0|dk	r0td|dk	rHtdt |}t|  tj| jdd\}}|d|f S )aE  
        Inverse the transformation and return a vector of size `n_features`.

        Parameters
        ----------
        Xt : array-like of shape (n_samples, n_clusters) or (n_clusters,)
            The values to be assigned to each cluster of samples.

        Xred : deprecated
            Use `Xt` instead.

            .. deprecated:: 1.3

        Returns
        -------
        X : ndarray of shape (n_samples, n_features) or (n_features,)
            A vector of size `n_samples` with the values of `Xred` assigned to
            each of the cluster of samples.
        Nz(Missing required positional argument: Xtz)Please provide only `Xt`, and not `Xred`.zNInput argument `Xred` was renamed to `Xt` in v1.3 and will be removed in v1.5.T)Zreturn_inverse.)		TypeError
ValueErrorwarningswarnFutureWarningr   r
   r   r   )r   ZXtr   ZunilZinverser   r   r   inverse_transformA   s    z(AgglomerationTransform.inverse_transform)NN)	__name__
__module____qualname____doc__r   ZUNUSEDZ<_AgglomerationTransform__metadata_request__inverse_transformr   r$   r   r   r   r   r      s   
"r   )r(   r!   numpyr
   Zscipy.sparser   baser   utilsr   Zutils.validationr   r   r   r   r   r   <module>   s   