a
    �ù»jç6  ã                   @   s¶   d dl ZddlmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZmZ G dd	„ d	ƒZG d
d„ dƒZG dd„ deeƒZedg dd�e_G dd„ deƒZdd„ ZG dd„ deƒZdS )é    Né   )ÚBaseEstimatorÚClassifierMixin)ÚRequestMethodé   )Úavailable_if)Ú_check_sample_weightÚ_num_samplesÚcheck_arrayÚcheck_is_fittedÚcheck_random_statec                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚArraySlicingWrapperú-
    Parameters
    ----------
    array
    c                 C   s
   || _ d S ©N©Úarray©Úselfr   © r   ú<E:\soccer\ml_env\Lib\site-packages\sklearn/utils/_mocking.pyÚ__init__   s    zArraySlicingWrapper.__init__c                 C   s   t | j| ƒS r   ©ÚMockDataFramer   )r   Zaslicer   r   r   Ú__getitem__   s    zArraySlicingWrapper.__getitem__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   c                   @   sD   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zdd„ Zddd„Z	dS )r   r   c                 C   s*   || _ || _|j| _|j| _t|ƒ| _d S r   )r   ÚvaluesÚshapeÚndimr   Zilocr   r   r   r   r   )   s
    zMockDataFrame.__init__c                 C   s
   t | jƒS r   )Úlenr   ©r   r   r   r   Ú__len__1   s    zMockDataFrame.__len__Nc                 C   s   | j S r   r   )r   Zdtyper   r   r   Ú	__array__4   s    zMockDataFrame.__array__c                 C   s   t | j|jkƒS r   r   ©r   Úotherr   r   r   Ú__eq__:   s    zMockDataFrame.__eq__c                 C   s
   | |k S r   r   r%   r   r   r   Ú__ne__=   s    zMockDataFrame.__ne__r   c                 C   s   t | jj||d�ƒS )N©Úaxis)r   r   Útake)r   Úindicesr*   r   r   r   r+   @   s    zMockDataFrame.take)N)r   )
r   r   r   r   r   r#   r$   r'   r(   r+   r   r   r   r   r       s   
r   c                
       st   e Zd ZdZddddddddddœ	dd„Zdd	d
„Zddd„Zdd„ Zdd„ Zdd„ Z	ddd„Z
‡ fdd„Z‡  ZS )ÚCheckingClassifiera$	  Dummy classifier to test pipelining and meta-estimators.

    Checks some property of `X` and `y`in fit / predict.
    This allows testing whether pipelines / cross-validation or metaestimators
    changed the input.

    Can also be used to check if `fit_params` are passed correctly, and
    to force a certain score to be returned.

    Parameters
    ----------
    check_y, check_X : callable, default=None
        The callable used to validate `X` and `y`. These callable should return
        a bool where `False` will trigger an `AssertionError`. If `None`, the
        data is not validated. Default is `None`.

    check_y_params, check_X_params : dict, default=None
        The optional parameters to pass to `check_X` and `check_y`. If `None`,
        then no parameters are passed in.

    methods_to_check : "all" or list of str, default="all"
        The methods in which the checks should be applied. By default,
        all checks will be done on all methods (`fit`, `predict`,
        `predict_proba`, `decision_function` and `score`).

    foo_param : int, default=0
        A `foo` param. When `foo > 1`, the output of :meth:`score` will be 1
        otherwise it is 0.

    expected_sample_weight : bool, default=False
        Whether to check if a valid `sample_weight` was passed to `fit`.

    expected_fit_params : list of str, default=None
        A list of the expected parameters given when calling `fit`.

    Attributes
    ----------
    classes_ : int
        The classes seen during `fit`.

    n_features_in_ : int
        The number of features seen during `fit`.

    Examples
    --------
    >>> from sklearn.utils._mocking import CheckingClassifier

    This helper allow to assert to specificities regarding `X` or `y`. In this
    case we expect `check_X` or `check_y` to return a boolean.

    >>> from sklearn.datasets import load_iris
    >>> X, y = load_iris(return_X_y=True)
    >>> clf = CheckingClassifier(check_X=lambda x: x.shape == (150, 4))
    >>> clf.fit(X, y)
    CheckingClassifier(...)

    We can also provide a check which might raise an error. In this case, we
    expect `check_X` to return `X` and `check_y` to return `y`.

    >>> from sklearn.utils import check_array
    >>> clf = CheckingClassifier(check_X=check_array)
    >>> clf.fit(X, y)
    CheckingClassifier(...)
    NÚallr   ©	Úcheck_yÚcheck_y_paramsÚcheck_XÚcheck_X_paramsÚmethods_to_checkÚ	foo_paramÚexpected_sample_weightÚexpected_fit_paramsÚrandom_statec       	   
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r   r/   )
r   r0   r1   r2   r3   r4   r5   r6   r7   r8   r   r   r   r   †   s    zCheckingClassifier.__init__Tc                 C   s¸   |rt | ƒ | jdurZ| jdu r$i n| j}| j|fi |¤Ž}t|ttjfƒrV|sZJ ‚n|}|dur°| jdur°| jdu rzi n| j}| j|fi |¤Ž}t|ttjfƒr¬|s°J ‚n|}||fS )at  Validate X and y and make extra check.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The data set.
            `X` is checked only if `check_X` is not `None` (default is None).
        y : array-like of shape (n_samples), default=None
            The corresponding target, by default `None`.
            `y` is checked only if `check_y` is not `None` (default is None).
        should_be_fitted : bool, default=True
            Whether or not the classifier should be already fitted.
            By default True.

        Returns
        -------
        X, y
        N)	r   r2   r3   Ú
isinstanceÚboolÚnpZbool_r0   r1   )r   ÚXÚyÚshould_be_fittedÚparamsZ	checked_XZ	checked_yr   r   r   Ú
_check_X_y�   s    


zCheckingClassifier._check_X_yc              	   K   sü   t |ƒt |ƒksJ ‚| jdks(d| jv r<| j||dd�\}}t |¡d | _t t|ddd�¡| _| j	rØt
| j	ƒt
|ƒ }|r’tdt|ƒ› d	�ƒ‚| ¡ D ]<\}}t |ƒt |ƒkrštd
|› dt |ƒ› dt |ƒ› d�ƒ‚qš| jrø|du rîtdƒ‚t||ƒ | S )a   Fit classifier.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training vector, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples, n_outputs) or (n_samples,),                 default=None
            Target relative to X for classification or regression;
            None for unsupervised learning.

        sample_weight : array-like of shape (n_samples,), default=None
            Sample weights. If None, then samples are equally weighted.

        **fit_params : dict of string -> object
            Parameters passed to the ``fit`` method of the estimator

        Returns
        -------
        self
        r.   ÚfitF)r>   r   T)Z	ensure_2dZallow_ndzExpected fit parameter(s) z
 not seen.zFit parameter z has length z; expected Ú.Nz#Expected sample_weight to be passed)r	   r4   r@   r;   r   Zn_features_in_Úuniquer
   Úclasses_r7   ÚsetÚAssertionErrorÚlistÚitemsr6   r   )r   r<   r=   Zsample_weightZ
fit_paramsÚmissingÚkeyÚvaluer   r   r   rA   Â   s.    ÿÿÿ
zCheckingClassifier.fitc                 C   s@   | j dksd| j v r"|  |¡\}}t| jƒ}|j| jt|ƒd�S )a>  Predict the first class seen in `classes_`.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input data.

        Returns
        -------
        preds : ndarray of shape (n_samples,)
            Predictions of the first class seens in `classes_`.
        r.   Úpredict)Úsize)r4   r@   r   r8   ÚchoicerD   r	   ©r   r<   r=   Úrngr   r   r   rL   ò   s    
zCheckingClassifier.predictc                 C   st   | j dksd| j v r"|  |¡\}}t| jƒ}| t|ƒt| jƒ¡}tj	||d�}|tj
|dd�dd…tjf  }|S )aº  Predict probabilities for each class.

        Here, the dummy classifier will provide a probability of 1 for the
        first class of `classes_` and 0 otherwise.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input data.

        Returns
        -------
        proba : ndarray of shape (n_samples, n_classes)
            The probabilities for each sample and class.
        r.   Úpredict_proba)Úoutr   r)   N)r4   r@   r   r8   Úrandnr	   r!   rD   r;   ÚabsÚsumZnewaxis)r   r<   r=   rP   Zprobar   r   r   rQ     s    
 z CheckingClassifier.predict_probac                 C   sb   | j dksd| j v r"|  |¡\}}t| jƒ}t| jƒdkrH| t|ƒ¡S | t|ƒt| jƒ¡S dS )aB  Confidence score.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input data.

        Returns
        -------
        decision : ndarray of shape (n_samples,) if n_classes == 2                else (n_samples, n_classes)
            Confidence score.
        r.   Údecision_functionr   N)r4   r@   r   r8   r!   rD   rS   r	   rO   r   r   r   rV     s    ÿþ
z$CheckingClassifier.decision_functionc                 C   s8   | j dksd| j v r |  ||¡ | jdkr0d}nd}|S )aQ  Fake score.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Input data, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        Y : array-like of shape (n_samples, n_output) or (n_samples,)
            Target relative to X for classification or regression;
            None for unsupervised learning.

        Returns
        -------
        score : float
            Either 0 or 1 depending of `foo_param` (i.e. `foo_param > 1 =>
            score=1` otherwise `score=0`).
        r.   Úscorer   g      ð?g        )r4   r@   r5   )r   r<   ÚYrW   r   r   r   rW   7  s    
zCheckingClassifier.scorec                    s$   t ƒ  ¡ }d|_d|j_d|j_|S )NTF)ÚsuperÚ__sklearn_tags__Ú
_skip_testZ
input_tagsZtwo_d_arrayZtarget_tagsZone_d_labels©r   Útags©Ú	__class__r   r   rZ   R  s
    
z#CheckingClassifier.__sklearn_tags__)NT)N)NN)r   r   r   r   r   r@   rA   rL   rQ   rV   rW   rZ   Ú__classcell__r   r   r^   r   r-   D   s$   Dõ
%
0
r-   rA   F)ÚnameÚkeysZvalidate_keysc                       sB   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Z‡ fdd„Z‡  Z	S )ÚNoSampleWeightWrapperzšWrap estimator which will not expose `sample_weight`.

    Parameters
    ----------
    est : estimator, default=None
        The estimator to wrap.
    Nc                 C   s
   || _ d S r   )Úest)r   rd   r   r   r   r   k  s    zNoSampleWeightWrapper.__init__c                 C   s   | j  ||¡S r   )rd   rA   ©r   r<   r=   r   r   r   rA   n  s    zNoSampleWeightWrapper.fitc                 C   s   | j  |¡S r   )rd   rL   ©r   r<   r   r   r   rL   q  s    zNoSampleWeightWrapper.predictc                 C   s   | j  |¡S r   )rd   rQ   rf   r   r   r   rQ   t  s    z#NoSampleWeightWrapper.predict_probac                    s   t ƒ  ¡ }d|_|S )NT)rY   rZ   r[   r\   r^   r   r   rZ   w  s    
z&NoSampleWeightWrapper.__sklearn_tags__)N)
r   r   r   r   r   rA   rL   rQ   rZ   r`   r   r   r^   r   rc   b  s   
rc   c                    s   ‡ fdd„}|S )Nc                    s   | j d uoˆ | j v S r   ©Úresponse_methodsr"   ©Úmethodr   r   Úcheck~  s    z_check_response.<locals>.checkr   )rj   rk   r   ri   r   Ú_check_response}  s    rl   c                   @   s^   e Zd ZdZddd„Zdd„ Zeedƒƒdd	„ ƒZeed
ƒƒdd„ ƒZ	eedƒƒdd„ ƒZ
dS )Ú_MockEstimatorOnOffPredictiona  Estimator for which we can turn on/off the prediction methods.

    Parameters
    ----------
    response_methods: list of             {"predict", "predict_proba", "decision_function"}, default=None
        List containing the response implemented by the estimator. When, the
        response is in the list, it will return the name of the response method
        when called. Otherwise, an `AttributeError` is raised. It allows to
        use `getattr` as any conventional estimator. By default, no response
        methods are mocked.
    Nc                 C   s
   || _ d S r   rg   )r   rh   r   r   r   r   ’  s    z&_MockEstimatorOnOffPrediction.__init__c                 C   s   t  |¡| _| S r   )r;   rC   rD   re   r   r   r   rA   •  s    z!_MockEstimatorOnOffPrediction.fitrL   c                 C   s   dS )NrL   r   rf   r   r   r   rL   ™  s    z%_MockEstimatorOnOffPrediction.predictrQ   c                 C   s   dS )NrQ   r   rf   r   r   r   rQ   �  s    z+_MockEstimatorOnOffPrediction.predict_probarV   c                 C   s   dS )NrV   r   rf   r   r   r   rV   ¡  s    z/_MockEstimatorOnOffPrediction.decision_function)N)r   r   r   r   r   rA   r   rl   rL   rQ   rV   r   r   r   r   rm   „  s   





rm   )Únumpyr;   Úbaser   r   Zutils._metadata_requestsr   Zmetaestimatorsr   Z
validationr   r	   r
   r   r   r   r   r-   Zset_fit_requestrc   rl   rm   r   r   r   r   Ú<module>   s   	$  ÿ