a
    �ù»j  ã                   @   sd   d dl mZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	„ ZG d
d„ deƒZdS )é    )Údeepcopyé   )ÚBaseEstimator)ÚNotFittedError)Úget_tags)Úavailable_if)Úcheck_is_fittedc                    s   ‡ fdd„}|S )zSCheck that final_estimator has `attr`.

    Used together with `available_if`.
    c                    s   t | jˆ ƒ dS ©NT)ÚgetattrÚ	estimator©Úself©Úattr© ú<E:\soccer\ml_env\Lib\site-packages\sklearn/frozen/_frozen.pyÚcheck   s    z_estimator_has.<locals>.checkr   )r   r   r   r   r   Ú_estimator_has   s    r   c                   @   sf   e Zd ZdZdd„ Zeedƒƒdd„ ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zddd„Zdd„ ZdS )ÚFrozenEstimatoraö  Estimator that wraps a fitted estimator to prevent re-fitting.

    This meta-estimator takes an estimator and freezes it, in the sense that calling
    `fit` on it has no effect. `fit_predict` and `fit_transform` are also disabled.
    All other methods are delegated to the original estimator and original estimator's
    attributes are accessible as well.

    This is particularly useful when you have a fitted or a pre-trained model as a
    transformer in a pipeline, and you'd like `pipeline.fit` to have no effect on this
    step.

    Parameters
    ----------
    estimator : estimator
        The estimator which is to be kept frozen.

    See Also
    --------
    None: No similar entry in the scikit-learn documentation.

    Examples
    --------
    >>> from sklearn.datasets import make_classification
    >>> from sklearn.frozen import FrozenEstimator
    >>> from sklearn.linear_model import LogisticRegression
    >>> X, y = make_classification(random_state=0)
    >>> clf = LogisticRegression(random_state=0).fit(X, y)
    >>> frozen_clf = FrozenEstimator(clf)
    >>> frozen_clf.fit(X, y)  # No-op
    FrozenEstimator(estimator=LogisticRegression(random_state=0))
    >>> frozen_clf.predict(X)  # Predictions from `clf.predict`
    array(...)
    c                 C   s
   || _ d S ©N©r   )r   r   r   r   r   Ú__init__>   s    zFrozenEstimator.__init__Ú__getitem__c                 O   s   | j j|i |¤ŽS )zƒ__getitem__ is defined in :class:`~sklearn.pipeline.Pipeline` and             :class:`~sklearn.compose.ColumnTransformer`.
        )r   r   )r   ÚargsÚkwargsr   r   r   r   A   s    zFrozenEstimator.__getitem__c                 C   s"   |dv rt |› d�ƒ‚t| j|ƒS )N)Zfit_predictZfit_transformz( is not available for frozen estimators.)ÚAttributeErrorr
   r   )r   Únamer   r   r   Ú__getattr__H   s    zFrozenEstimator.__getattr__c                 C   s   | S r   r   r   r   r   r   Ú__sklearn_clone__O   s    z!FrozenEstimator.__sklearn_clone__c                 C   s*   zt | jƒ W dS  ty$   Y dS 0 d S )NTF)r   r   r   r   r   r   r   Ú__sklearn_is_fitted__R   s
    
z%FrozenEstimator.__sklearn_is_fitted__c                 O   s   t | jƒ | S )aG  No-op.

        As a frozen estimator, calling `fit` has no effect.

        Parameters
        ----------
        X : object
            Ignored.

        y : object
            Ignored.

        *args : tuple
            Additional positional arguments. Ignored, but present for API compatibility
            with `self.estimator`.

        **kwargs : dict
            Additional keyword arguments. Ignored, but present for API compatibility
            with `self.estimator`.

        Returns
        -------
        self : object
            Returns the instance itself.
        )r   r   )r   ÚXÚyr   r   r   r   r   ÚfitY   s    
zFrozenEstimator.fitc                 K   s*   |  dd¡}|dur|| _|r&tdƒ‚dS )aZ  Set the parameters of this estimator.

        The only valid key here is `estimator`. You cannot set the parameters of the
        inner estimator.

        Parameters
        ----------
        **kwargs : dict
            Estimator parameters.

        Returns
        -------
        self : FrozenEstimator
            This estimator.
        r   NzÆYou cannot set parameters of the inner estimator in a frozen estimator since calling `fit` has no effect. You can use `frozenestimator.estimator.set_params` to set parameters of the inner estimator.)Úpopr   Ú
ValueError)r   r   r   r   r   r   Ú
set_paramsv   s    ÿzFrozenEstimator.set_paramsTc                 C   s
   d| j iS )ah  Get parameters for this estimator.

        Returns a `{"estimator": estimator}` dict. The parameters of the inner
        estimator are not included.

        Parameters
        ----------
        deep : bool, default=True
            Ignored.

        Returns
        -------
        params : dict
            Parameter names mapped to their values.
        r   r   )r   Údeepr   r   r   Ú
get_params‘   s    zFrozenEstimator.get_paramsc                 C   s   t t| jƒƒ}d|_|S r	   )r   r   r   Z
_skip_test)r   Útagsr   r   r   Ú__sklearn_tags__£   s    z FrozenEstimator.__sklearn_tags__N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r"   r%   r'   r)   r   r   r   r   r      s   "


r   N)Úcopyr   Úbaser   Ú
exceptionsr   Úutilsr   Zutils.metaestimatorsr   Zutils.validationr   r   r   r   r   r   r   Ú<module>   s   