o
    2hZ	                     @   s   d dl Zzd dlZd dlmZ d dlmZ W n ey/   dZG dd dZG dd dZY nw dd	 Zd
d ZG dd deeZ	dS )    N)BaseEstimator)TransformerMixinc                   @      e Zd ZdS )r   N__name__
__module____qualname__ r	   r	   S/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/wrappers/utils.pyr   
       r   c                   @   r   )r   Nr   r	   r	   r	   r
   r      r   r   c                 C   s   t d u rt|  dd S )NzW requires `scikit-learn` to be installed. Run `pip install scikit-learn` to install it.)sklearnImportError)symbol_namer	   r	   r
   assert_sklearn_installed   s
   r   c                 C   s   | j r	| jr	| jstddS )z-Check whether the model need sto be compiled.zCGiven model needs to be compiled, and have a loss and an optimizer.N)compiledloss	optimizerRuntimeError)modelr	   r	   r
   _check_model   s
   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TargetReshapera   Convert 1D targets to 2D and back.

    For use in pipelines with transformers that only accept
    2D inputs, like OneHotEncoder and OrdinalEncoder.

    Attributes:
        ndim_ : int
            Dimensions of y that the transformer was trained on.
    c                 C   s   |j | _| S )zFit the transformer to a target y.

        Returns:
            TargetReshaper
                A reference to the current instance of TargetReshaper.
        )ndimndim_selfyr	   r	   r
   fit.   s   zTargetReshaper.fitc                 C   s   |j dkr|ddS |S )zMakes 1D y 2D.

        Args:
            y : np.ndarray
                Target y to be transformed.

        Returns:
            np.ndarray
                A numpy array, of dimension at least 2.
           )r   reshaper   r	   r	   r
   	transform8   s   
zTargetReshaper.transformc                 C   s:   ddl m} ||  | jdkr|jdkrtj|ddS |S )a  Revert the transformation of transform.

        Args:
            y: np.ndarray
                Transformed numpy array.

        Returns:
            np.ndarray
                If the transformer was fit to a 1D numpy array,
                and a 2D numpy array with a singleton second dimension
                is passed, it will be squeezed back to 1D. Otherwise, it
                will eb left untouched.
        r   )check_is_fittedr      )axis)sklearn.utils.validationr!   r   r   npsqueeze)r   r   r!   r	   r	   r
   inverse_transformG   s
   z TargetReshaper.inverse_transformN)r   r   r   __doc__r   r    r'   r	   r	   r	   r
   r   #   s
    

r   )
numpyr%   r   sklearn.baser   r   r   r   r   r   r	   r	   r	   r
   <module>   s    

