
    0PhD5                        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	          Z G d
 d          Z G d dee          Z edg d          e_         G d de          Zd Z G 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                       e Zd ZdZd Zd ZdS )ArraySlicingWrapper-
    Parameters
    ----------
    array
    c                     || _         d S Narrayselfr   s     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/utils/_mocking.py__init__zArraySlicingWrapper.__init__   s    


    c                 6    t          | j        |                   S r   MockDataFramer   )r   aslices     r   __getitem__zArraySlicingWrapper.__getitem__   s    TZ/000r   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s<           1 1 1 1 1r   r   c                   :    e Zd ZdZd Zd Zd
dZd Zd Zdd	Z	dS )r   r   c                 z    || _         || _        |j        | _        |j        | _        t	          |          | _        d S r   )r   valuesshapendimr   ilocr   s     r   r   zMockDataFrame.__init__)   s5    
[
J	'..			r   c                 *    t          | j                  S r   )lenr   )r   s    r   __len__zMockDataFrame.__len__1   s    4:r   Nc                     | j         S r   r   )r   dtypes     r   	__array__zMockDataFrame.__array__4   s     zr   c                 <    t          | j        |j        k              S r   r   r   others     r   __eq__zMockDataFrame.__eq__:   s    TZ5;6777r   c                     | |k     S r   r#   r1   s     r   __ne__zMockDataFrame.__ne__=   s    5=  r   r   c                 T    t          | j                            ||                    S )Naxis)r   r   take)r   indicesr8   s      r   r9   zMockDataFrame.take@   s"    TZ__W4_@@AAAr   r   )r   )
r   r    r!   r"   r   r,   r/   r3   r5   r9   r#   r   r   r   r       s         / / /     8 8 8! ! !B B B B B Br   r   c            
       h     e Zd ZdZdddddddddd	dZddZdd	Zd
 Zd Zd Z	ddZ
 fdZ x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       	             || _         || _        || _        || _        || _        || _        || _        || _        |	| _        d S r   r>   )
r   r?   r@   rA   rB   rC   rD   rE   rF   rG   s
             r   r   zCheckingClassifier.__init__   sO     ,, 0"&<##6 (r   Tc                 d   |rt          |            | j        F| j        i n| j        } | j        |fi |}t          |t          t
          j        f          r|sJ n|}|M| j        F| j        i 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
        )	r   rA   rB   
isinstanceboolnpbool_r?   r@   )r   Xyshould_be_fittedparams	checked_X	checked_ys          r   
_check_X_yzCheckingClassifier._check_X_y   s    &  	"D!!!<#.6RRD<OF$Q11&11I)dBH%566      =T\5.6RRD<OF$Q11&11I)dBH%566      !tr   c                    t          |          t          |          k    sJ | j        dk    s	d| j        v r|                     ||d          \  }}t          j        |          d         | _        t          j        t          |dd                    | _        | j	        rt          | j	                  t          |          z
  }|r t          dt          |           d	          |                                D ]X\  }}t          |          t          |          k    r3t          d
| dt          |           dt          |           d          Y| j        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)rP   r   T)	ensure_2d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
   rC   rT   rL   r'   n_features_in_uniquer   classes_rF   setAssertionErrorlistitemsrE   r	   )r   rN   rO   sample_weight
fit_paramsmissingkeyvalues           r   rV   zCheckingClassifier.fit   s   0 A,q//1111 E))Ud6K-K-K??1a%?@@DAq hqkk!n	+a54"P"P"PQQ# 	$233c*ooEG $JgJJJ   )..00  
U&&,q//99(9 9 9,u:M:M 9 9&21oo9 9 9   :
 & 	3$$%JKKK 222r   c                     | j         dk    s	d| j         v r|                     |          \  }}t          | j                  }|                    | j        t          |                    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)rC   rT   r   rG   choicer\   r
   r   rN   rO   rngs       r   rg   zCheckingClassifier.predict   sb      E))Y$:O-O-O??1%%DAq !233zz$-l1ooz>>>r   c                 v   | j         dk    s	d| j         v r|                     |          \  }}t          | j                  }|                    t          |          t          | j                            }t          j	        ||          }|t          j
        |d          ddt          j        f         z  }|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   r7   N)rC   rT   r   rG   randnr
   r+   r\   rL   abssumnewaxis)r   rN   rO   rk   probas        r   rm   z CheckingClassifier.predict_proba  s       E))_@U-U-U??1%%DAq !233		,q//3t}+=+=>>u%(((A&&&qqq"*}55r   c                 `   | j         dk    s	d| j         v r|                     |          \  }}t          | j                  }t	          | j                  dk    r"|                    t          |                    S |                    t          |          t	          | j                            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   )rC   rT   r   rG   r+   r\   ro   r
   rj   s       r   ru   z$CheckingClassifier.decision_function  s     !U**"d&;;;??1%%DAq !233t}"" 99\!__---99\!__c$-.@.@AAAr   c                 z    | j         dk    s	d| j         v r|                     ||           | j        dk    rd}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        )rC   rT   rD   )r   rN   Yrw   s       r   rw   zCheckingClassifier.score7  sQ    &  E))W8M-M-MOOAq!!!>AEEEr   c                     t                                                      }d|_        d|j        _        d|j        _        |S )NTF)super__sklearn_tags__
_skip_test
input_tagstwo_d_arraytarget_tagsone_d_labelsr   tags	__class__s     r   r{   z#CheckingClassifier.__sklearn_tags__R  s9    ww''))&+#(,%r   NTr   )NN)r   r    r!   r"   r   rT   rV   rg   rm   ru   rw   r{   __classcell__r   s   @r   r<   r<   D   s        ? ?H # ) ) ) ) ).# # # #J. . . .`? ? ?$  0B B B6   6        r   r<   rV   F)namekeysvalidate_keysc                   <     e Zd ZdZddZd Zd Zd Z fdZ xZ	S )	NoSampleWeightWrapperzWrap estimator which will not expose `sample_weight`.

    Parameters
    ----------
    est : estimator, default=None
        The estimator to wrap.
    Nc                     || _         d S r   )est)r   r   s     r   r   zNoSampleWeightWrapper.__init__k  s    r   c                 8    | j                             ||          S r   )r   rV   r   rN   rO   s      r   rV   zNoSampleWeightWrapper.fitn  s    x||Aq!!!r   c                 6    | j                             |          S r   )r   rg   r   rN   s     r   rg   zNoSampleWeightWrapper.predictq  s    x"""r   c                 6    | j                             |          S r   )r   rm   r   s     r   rm   z#NoSampleWeightWrapper.predict_probat  s    x%%a(((r   c                 V    t                                                      }d|_        |S r   )rz   r{   r|   r   s     r   r{   z&NoSampleWeightWrapper.__sklearn_tags__w  s$    ww''))r   r   )
r   r    r!   r"   r   rV   rg   rm   r{   r   r   s   @r   r   r   b  s            " " "# # #) ) )        r   r   c                       fd}|S )Nc                 (    | j         d uo| j         v S r   response_methods)r   methods    r   checkz_check_response.<locals>.check~  s    $D0TVt?T5TTr   r#   )r   r   s   ` r   _check_responser   }  s(    U U U U U Lr   c                       e Zd ZdZddZd Z e ed                    d             Z e ed                    d             Z	 e e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                     || _         d S r   r   )r   r   s     r   r   z&_MockEstimatorOnOffPrediction.__init__  s     0r   c                 8    t          j        |          | _        | S r   )rL   r[   r\   r   s      r   rV   z!_MockEstimatorOnOffPrediction.fit  s    	!r   rg   c                     dS )Nrg   r#   r   s     r   rg   z%_MockEstimatorOnOffPrediction.predict  s    yr   rm   c                     dS )Nrm   r#   r   s     r   rm   z+_MockEstimatorOnOffPrediction.predict_proba  s    r   ru   c                     dS )Nru   r#   r   s     r   ru   z/_MockEstimatorOnOffPrediction.decision_function  s    ""r   r   )r   r    r!   r"   r   rV   r   r   rg   rm   ru   r#   r   r   r   r     s         1 1 1 1   \//),,--  .- \///2233  43 \//"56677# # 87# # #r   r   )numpyrL   baser   r   utils._metadata_requestsr   metaestimatorsr   
validationr	   r
   r   r   r   r   r   r<   set_fit_requestr   r   r   r#   r   r   <module>r      s       1 1 1 1 1 1 1 1 4 4 4 4 4 4 ( ( ( ( ( (             1 1 1 1 1 1 1 1!B !B !B !B !B !B !B !BHS S S S S- S S Sr &3]	Ru& & &  "
    M   6  # # # # #M # # # # #r   