
    h$,f                     ^    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	e      Zy)
zY
Feature agglomeration. Base classes and functions for performing feature
agglomeration.
    N)issparse   )TransformerMixin)metadata_routing)check_is_fittedc                   :    e Zd ZdZdej
                  iZd ZddZy)AgglomerationTransformzH
    A class for feature agglomeration via the transform interface.
    Xredc                    t        |        | j                  |d      }| j                  t        j                  k(  rt        |      st        j                  | j                        }|j                  d   }t        j                  t        |      D cg c],  }t        j                  | j                  ||ddf         |z  . c}      }|S t        j                  | j                        D cg c])  }| j                  |dd| j                  |k(  f   d      + }}t        j                  |      j                  }|S c c}w c c}w )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   N   )axis)r   _validate_datapooling_funcnpmeanr   bincountlabels_shapearrayrangeuniqueT)selfXsize	n_samplesinXls          Flib/python3.12/site-packages/sklearn/cluster/_feature_agglomeration.py	transformz AgglomerationTransform.transform   s     	/';;t||,D
IDI)DTUqT\\1QT73d:UB 	 4<<0 !!!At||q'8$8"9!BB  "B	 Vs   1D=,.ENc                     ||t        d      ||t        d      |t        j                  dt               |}t        |        t        j                  | j                  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.
        z(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)return_inverse.)		TypeError
ValueErrorwarningswarnFutureWarningr   r   r   r   )r   Xtr
   unilinverses        r!   inverse_transformz(AgglomerationTransform.inverse_transformA   s    ( :$,FGGHIIMM(  B		$,,tDg#w,    )NN)	__name__
__module____qualname____doc__r   UNUSED<_AgglomerationTransform__metadata_request__inverse_transformr"   r-    r.   r!   r	   r	      s&     .45E5L5L,M) D' r.   r	   )r2   r'   numpyr   scipy.sparser   baser   utilsr   utils.validationr   r	   r5   r.   r!   <module>r;      s-      ! # $ .S - S r.   