
    0PhR                        d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	Z
ddlmZ ddlmZmZ ddlmZ ddlmZm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!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- dddZ.dddZ/ G d dee          Z0 G d d          Z1 G d d          Z2 G d d          Z3 G d d          Z4 G d de          Z5 G d d           Z6 G d! d"          Z7 G d# d$          Z8 G d% d&          Z9 G d' d(          Z: G d) d*          Z; G d+ d,          Z<d- Z=d. Z>d/ Z?d0 Z@d1 ZAdS )2z>Base classes for all estimators and various utility functions.    N)defaultdict   )__version__)config_context
get_config)InconsistentVersionWarning)_HTMLDocumentationLinkMixinestimator_html_repr)_MetadataRequester_routing_enabled)validate_parameter_constraints)_SetOutputMixin)ClassifierTagsRegressorTagsTags
TargetTagsTransformerTagsget_tags)	_IS_32BIT)_check_feature_names_check_feature_names_in_check_n_features_generate_get_feature_names_out
_is_fittedcheck_arraycheck_is_fittedvalidate_dataTsafec                    t          | d          r(t          j        |           s|                                 S t	          | |          S )a  Construct a new unfitted estimator with the same parameters.

    Clone does a deep copy of the model in an estimator
    without actually copying attached data. It returns a new estimator
    with the same parameters that has not been fitted on any data.

    .. versionchanged:: 1.3
        Delegates to `estimator.__sklearn_clone__` if the method exists.

    Parameters
    ----------
    estimator : {list, tuple, set} of estimator instance or a single             estimator instance
        The estimator or group of estimators to be cloned.
    safe : bool, default=True
        If safe is False, clone will fall back to a deep copy on objects
        that are not estimators. Ignored if `estimator.__sklearn_clone__`
        exists.

    Returns
    -------
    estimator : object
        The deep copy of the input, an estimator if input is an estimator.

    Notes
    -----
    If the estimator's `random_state` parameter is an integer (or if the
    estimator doesn't have a `random_state` parameter), an *exact clone* is
    returned: the clone and the original estimator will give the exact same
    results. Otherwise, *statistical clone* is returned: the clone might
    return different results from the original estimator. More details can be
    found in :ref:`randomness`.

    Examples
    --------
    >>> from sklearn.base import clone
    >>> from sklearn.linear_model import LogisticRegression
    >>> X = [[-1, 0], [0, 1], [0, -1], [1, 0]]
    >>> y = [0, 0, 1, 1]
    >>> classifier = LogisticRegression().fit(X, y)
    >>> cloned_classifier = clone(classifier)
    >>> hasattr(classifier, "classes_")
    True
    >>> hasattr(cloned_classifier, "classes_")
    False
    >>> classifier is cloned_classifier
    False
    __sklearn_clone__r   )hasattrinspectisclassr!   _clone_parametrized)	estimatorr   s     L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/base.pycloner(   ,   sN    b y-.. -wy7Q7Q -**,,,yt4444    c                   t          |           }|t          u r fd|                                 D             S |t          t          t
          t          fv r |fd| D                       S t          | d          rt          | t                     rjst          j
        |           S t          | t                     rt          d          t          dt          |           dt          |           d          | j        }|                     d	          }|                                D ]\  }}t          |d
          ||<    |di |}	 t          j
        | j                  |_        n# t"          $ r Y nw xY w|                    d	          }|D ]+}||         }	||         }
|	|
urt%          d| d|          ,t          | d          rt          j
        | j                  |_        |S )zLDefault implementation of clone. See :func:`sklearn.base.clone` for details.c                 :    i | ]\  }}|t          |           S r   r(   ).0kvr   s      r'   
<dictcomp>z'_clone_parametrized.<locals>.<dictcomp>g   s,    EEE41a5&&&EEEr)   c                 2    g | ]}t          |           S r,   r-   )r.   er   s     r'   
<listcomp>z'_clone_parametrized.<locals>.<listcomp>i   s&    FFFquQT222FFFr)   
get_paramszaCannot clone object. You should provide an instance of scikit-learn estimator instead of a class.zCannot clone object 'z' (type zb): it does not seem to be a scikit-learn estimator as it does not implement a 'get_params' method.Fdeepr   zCannot clone object z?, as the constructor either does not set or modifies parameter _sklearn_output_config )typedictitemslisttupleset	frozensetr"   
isinstancecopydeepcopy	TypeErrorrepr	__class__r5   r(   _metadata_requestAttributeErrorRuntimeErrorr8   )r&   r   estimator_typeklassnew_object_paramsnameparam
new_object
params_setparam1param2s    `         r'   r%   r%   b   sk    )__NEEEE9??3D3DEEEE	D%i8	8	8~FFFFIFFFGGGY-- It1L1L  	=+++)T** C    i /39ooootIP   E!,,%,88(..00 ; ;e"'E":":":$++*++J'+}Y5P'Q'Q
$$    &&E&22J "  "4(D!,BK))TTS     y233 
,0M,-
 -

) s   E/ /
E<;E<c                        e Zd ZdZed             ZddZd Zd ZddZ	 fd	Z
 fd
Zd Zd Zd Zd Zed             Zd Zd Zd Zd Zd Z xZS )BaseEstimatoraq  Base class for all estimators in scikit-learn.

    Inheriting from this class provides default implementations of:

    - setting and getting parameters used by `GridSearchCV` and friends;
    - textual and HTML representation displayed in terminals and IDEs;
    - estimator serialization;
    - parameters validation;
    - data validation;
    - feature names validation.

    Read more in the :ref:`User Guide <rolling_your_own_estimator>`.


    Notes
    -----
    All estimators should specify all the parameters that can be set
    at the class level in their ``__init__`` as explicit keyword
    arguments (no ``*args`` or ``**kwargs``).

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import BaseEstimator
    >>> class MyEstimator(BaseEstimator):
    ...     def __init__(self, *, param=1):
    ...         self.param = param
    ...     def fit(self, X, y=None):
    ...         self.is_fitted_ = True
    ...         return self
    ...     def predict(self, X):
    ...         return np.full(shape=X.shape[0], fill_value=self.param)
    >>> estimator = MyEstimator(param=2)
    >>> estimator.get_params()
    {'param': 2}
    >>> X = np.array([[1, 2], [2, 3], [3, 4]])
    >>> y = np.array([1, 0, 1])
    >>> estimator.fit(X, y).predict(X)
    array([2, 2, 2])
    >>> estimator.set_params(param=3).fit(X, y).predict(X)
    array([3, 3, 3])
    c                 N   t          | j        d| j                  }|t          j        u rg S t          j        |          }d |j                                        D             }|D ](}|j        |j        k    rt          d| d|d          )t          d |D                       S )z%Get parameter names for the estimatordeprecated_originalc                 H    g | ]}|j         d k    |j        |j        k    | S self)rM   kindVAR_KEYWORDr.   ps     r'   r4   z2BaseEstimator._get_param_names.<locals>.<listcomp>   s=     
 
 
vAFam$;$; $;$;$;r)   zpscikit-learn estimators should always specify their parameters in the signature of their __init__ (no varargs). z with constructor z! doesn't  follow this convention.c                     g | ]	}|j         
S r9   )rM   r\   s     r'   r4   z2BaseEstimator._get_param_names.<locals>.<listcomp>   s    222!qv222r)   )getattr__init__objectr#   	signature
parametersvaluesrZ   VAR_POSITIONALrI   sorted)clsinitinit_signaturerc   r]   s        r'   _get_param_nameszBaseEstimator._get_param_names   s    
 s|%:CLII6?""I !*400
 
#.5577
 
 


  	 	Av)))"l
 36##~~~	G   * 22z222333r)   Tc                 X   t                      }|                                 D ]t          |           }|rlt          |d          r\t	          |t
                    sG|                                                                }|                    fd|D                        ||<   |S )ae  
        Get parameters for this estimator.

        Parameters
        ----------
        deep : bool, default=True
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : dict
            Parameter names mapped to their values.
        r5   c              3   2   K   | ]\  }}d z   |z   |fV  dS )__Nr9   )r.   r/   valkeys      r'   	<genexpr>z+BaseEstimator.get_params.<locals>.<genexpr>   s4      JJVQC$JNC0JJJJJJr)   )	r;   rj   r_   r"   rA   r:   r5   r<   update)rY   r7   outvalue
deep_itemsro   s        @r'   r5   zBaseEstimator.get_params   s     ff((** 	 	CD#&&E K|44 KZt=T=T K"--//5577


JJJJzJJJJJJCHH
r)   c           
         |s| S |                      d          }t          t                    }|                                D ]s\  }}|                    d          \  }}}||vr-|                                 }t          d|d|  d|d          |r|||         |<   ]t          | ||           |||<   t|                                D ]\  }}	 ||         j        di |	 | S )	a  Set the parameters of this estimator.

        The method works on simple estimators as well as on nested objects
        (such as :class:`~sklearn.pipeline.Pipeline`). The latter have
        parameters of the form ``<component>__<parameter>`` so that it's
        possible to update each component of a nested object.

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

        Returns
        -------
        self : estimator instance
            Estimator instance.
        Tr6   rm   zInvalid parameter z for estimator z. Valid parameters are: .r9   )	r5   r   r;   r<   	partitionrj   
ValueErrorsetattr
set_params)
rY   paramsvalid_paramsnested_paramsro   rs   delimsub_keylocal_valid_params
sub_paramss
             r'   rz   zBaseEstimator.set_params   sJ   $  	KD11#D)) ,,.. 	* 	*JC"%--"5"5C,&&%)%:%:%<%<" E E Et E E-?E E E  
  *.3c"7++c5)))$)S!!,2244 	7 	7OC(L(66:6666r)   c                      t          |           S N)r%   rX   s    r'   r!   zBaseEstimator.__sklearn_clone__+  s    "4(((r)     c                    ddl m} d} |ddd|          }|                    |           }t          d                    |                                                    }||k    r|dz  }d|z  }t          j        ||                                          }	t          j        ||d d d	                                                   }
d
||	|
          v r5|dz  }t          j        ||d d d	                                                   }
d}|	t          |          z   t          |          |
z
  k     r|d |	         dz   ||
 d          z   }|S )Nr   )_EstimatorPrettyPrinter   T)compactindentindent_at_namen_max_elements_to_show    z^(\s*\S){%d}
z[^\n]*\nz...)	utils._pprintr   pformatlenjoinsplitrematchend)rY   
N_CHAR_MAXr   N_MAX_ELEMENTS_TO_SHOWpprepr_
n_nonblanklimregexleft_lim	right_limellipsiss               r'   __repr__zBaseEstimator.__repr__.  ss   
 	;:::::!# %$#9	
 
 
 

4   //00

""/C#c)E xu--1133Hddd4488::IuXyj0111 $HUE$$B$K88<<>>	H#h--'#e**y*@@@ixi(505)3EEr)   c                    t          | dd           rt          d          	 t                                                      }|| j                                        }n)# t          $ r | j                                        }Y nw xY wt          |           j        	                    d          r(t          |                                t                    S |S )N	__slots__zSYou cannot use `__slots__` in objects inheriting from `sklearn.base.BaseEstimator`.sklearn.)_sklearn_version)r_   rD   super__getstate____dict__rB   rH   r:   
__module__
startswithr;   r<   r   )rY   staterF   s     r'   r   zBaseEstimator.__getstate__b  s    4d++ 	0  
	)GG((**E} **,, 	) 	) 	)M&&((EEE	) :: ++J77 	DDDDLs   ;A #BBc                    t          |           j                            d          rT|                    dd          }|t          k    r3t          j        t          | j        j	        t          |                     	 t                                          |           d S # t          $ r | j                            |           Y d S w xY w)Nr   r   zpre-0.18)estimator_namecurrent_sklearn_versionoriginal_sklearn_version)r:   r   r   popr   warningswarnr   rF   __name__r   __setstate__rH   r   rq   )rY   r   pickle_versionrF   s      r'   r   zBaseEstimator.__setstate__x  s    :: ++J77 		"YY'9:FFN,,.'+~'>0;1?    	(GG  ''''' 	( 	( 	(M  ''''''	(s   >!B! !$C	C	c                 p    ddl m}m} t          j        dt
                      | ||                     S )a  This code should never be reached since our `get_tags` will fallback on
        `__sklearn_tags__` implemented below. We keep it for backward compatibility.
        It is tested in `test_base_estimator_more_tags` in
        `sklearn/utils/testing/test_tags.py`.r   )_to_old_tagsdefault_tagszxThe `_more_tags` method is deprecated in 1.6 and will be removed in 1.7. Please implement the `__sklearn_tags__` method.category)sklearn.utils._tagsr   r   r   r   DeprecationWarning)rY   r   r   s      r'   
_more_tagszBaseEstimator._more_tags  s[    
 	CBBBBBBBC'	
 	
 	
 	

 |LL..///r)   c                 p    ddl m}m} t          j        dt
                      | ||                     S )Nr   )r   r   zwThe `_get_tags` method is deprecated in 1.6 and will be removed in 1.7. Please implement the `__sklearn_tags__` method.r   )r   r   r   r   r   r   )rY   r   r   s      r'   	_get_tagszBaseEstimator._get_tags  sV    >>>>>>>>C'	
 	
 	
 	
 |HHTNN+++r)   c                 F    t          d t          d          d d d           S )NF)required)rJ   target_tagstransformer_tagsregressor_tagsclassifier_tags)r   r   rX   s    r'   __sklearn_tags__zBaseEstimator.__sklearn_tags__  s3    "E222! 
 
 
 	
r)   c                 p    t          | j        |                     d          | j        j                   dS )aY  Validate types and values of constructor parameters

        The expected type and values must be defined in the `_parameter_constraints`
        class attribute, which is a dictionary `param_name: list of constraints`. See
        the docstring of `validate_parameter_constraints` for a description of the
        accepted constraints.
        Fr6   )caller_nameN)r   _parameter_constraintsr5   rF   r   rX   s    r'   _validate_paramszBaseEstimator._validate_params  sD     	''OOO''/	
 	
 	
 	
 	
 	
r)   c                 ^    t                      d         dk    rt          d          | j        S )a  HTML representation of estimator.

        This is redundant with the logic of `_repr_mimebundle_`. The latter
        should be favorted in the long term, `_repr_html_` is only
        implemented for consumers who do not interpret `_repr_mimbundle_`.
        displaydiagramzW_repr_html_ is only defined when the 'display' configuration option is set to 'diagram')r   rH   _repr_html_innerrX   s    r'   _repr_html_zBaseEstimator._repr_html_  s:     <<	"i//   
 $$r)   c                      t          |           S )zThis function is returned by the @property `_repr_html_` to make
        `hasattr(estimator, "_repr_html_") return `True` or `False` depending
        on `get_config()["display"]`.
        )r
   rX   s    r'   r   zBaseEstimator._repr_html_inner  s    
 #4(((r)   c                 |    dt          |           i}t                      d         dk    rt          |           |d<   |S )z8Mime bundle used by jupyter kernels to display estimatorz
text/plainr   r   z	text/html)rE   r   r
   )rY   kwargsoutputs      r'   _repr_mimebundle_zBaseEstimator._repr_mimebundle_  s=    T

+<<	"i//"5d";";F;r)   c                 V    t          j        dt                     t          | g|R i |S )Nz`BaseEstimator._validate_data` is deprecated in 1.6 and will be removed in 1.7. Use `sklearn.utils.validation.validate_data` instead. This function becomes public and is part of the scikit-learn developer API.)r   r   FutureWarningr   rY   argsr   s      r'   _validate_datazBaseEstimator._validate_data  sA    U 		
 	
 	
 T3D333F333r)   c                 Z    t          j        dt                     t          | g|R i | d S )Nz`BaseEstimator._check_n_features` is deprecated in 1.6 and will be removed in 1.7. Use `sklearn.utils.validation._check_n_features` instead.)r   r   r   r   r   s      r'   r   zBaseEstimator._check_n_features  sE    X	
 	
 	

 	$000000000r)   c                 Z    t          j        dt                     t          | g|R i | d S )Nz`BaseEstimator._check_feature_names` is deprecated in 1.6 and will be removed in 1.7. Use `sklearn.utils.validation._check_feature_names` instead.)r   r   r   r   r   s      r'   r   z"BaseEstimator._check_feature_names  sF     		
 	
 	
 	T3D333F33333r)   )T)r   )r   r   __qualname____doc__classmethodrj   r5   rz   r!   r   r   r   r   r   r   r   propertyr   r   r   r   r   r   __classcell__rF   s   @r'   rT   rT      sa       ) )V 4 4 [4<   0* * *X) ) )2 2 2 2h    ,( ( ( ( ("0 0 0	, 	, 	,
 
 

 
 
 % % X%) ) )  4 4 41 1 14 4 4 4 4 4 4r)   rT   c                   .     e Zd ZdZdZ fdZddZ xZS )ClassifierMixina  Mixin class for all classifiers in scikit-learn.

    This mixin defines the following functionality:

    - set estimator type to `"classifier"` through the `estimator_type` tag;
    - `score` method that default to :func:`~sklearn.metrics.accuracy_score`.
    - enforce that `fit` requires `y` to be passed through the `requires_y` tag,
      which is done by setting the classifier type tag.

    Read more in the :ref:`User Guide <rolling_your_own_estimator>`.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import BaseEstimator, ClassifierMixin
    >>> # Mixin classes should always be on the left-hand side for a correct MRO
    >>> class MyEstimator(ClassifierMixin, BaseEstimator):
    ...     def __init__(self, *, param=1):
    ...         self.param = param
    ...     def fit(self, X, y=None):
    ...         self.is_fitted_ = True
    ...         return self
    ...     def predict(self, X):
    ...         return np.full(shape=X.shape[0], fill_value=self.param)
    >>> estimator = MyEstimator(param=1)
    >>> X = np.array([[1, 2], [2, 3], [3, 4]])
    >>> y = np.array([1, 0, 1])
    >>> estimator.fit(X, y).predict(X)
    array([1, 1, 1])
    >>> estimator.score(X, y)
    0.66...
    
classifierc                     t                                                      }d|_        t                      |_        d|j        _        |S )Nr   T)r   r   rJ   r   r   r   r   rY   tagsrF   s     r'   r   z ClassifierMixin.__sklearn_tags__  s>    ww''))*-//$(!r)   Nc                 P    ddl m}  |||                     |          |          S )a  
        Return the mean accuracy on the given test data and labels.

        In multi-label classification, this is the subset accuracy
        which is a harsh metric since you require for each sample that
        each label set be correctly predicted.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Test samples.

        y : array-like of shape (n_samples,) or (n_samples, n_outputs)
            True labels for `X`.

        sample_weight : array-like of shape (n_samples,), default=None
            Sample weights.

        Returns
        -------
        score : float
            Mean accuracy of ``self.predict(X)`` w.r.t. `y`.
        r   )accuracy_scoresample_weight)metricsr   predict)rY   Xyr   r   s        r'   scorezClassifierMixin.score"  s7    0 	,+++++~aaNNNNr)   r   r   r   r   r   _estimator_typer   r   r   r   s   @r'   r   r     sf         D #O    O O O O O O O Or)   r   c                   .     e Zd ZdZdZ fdZddZ xZS )RegressorMixina  Mixin class for all regression estimators in scikit-learn.

    This mixin defines the following functionality:

    - set estimator type to `"regressor"` through the `estimator_type` tag;
    - `score` method that default to :func:`~sklearn.metrics.r2_score`.
    - enforce that `fit` requires `y` to be passed through the `requires_y` tag,
      which is done by setting the regressor type tag.

    Read more in the :ref:`User Guide <rolling_your_own_estimator>`.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import BaseEstimator, RegressorMixin
    >>> # Mixin classes should always be on the left-hand side for a correct MRO
    >>> class MyEstimator(RegressorMixin, BaseEstimator):
    ...     def __init__(self, *, param=1):
    ...         self.param = param
    ...     def fit(self, X, y=None):
    ...         self.is_fitted_ = True
    ...         return self
    ...     def predict(self, X):
    ...         return np.full(shape=X.shape[0], fill_value=self.param)
    >>> estimator = MyEstimator(param=0)
    >>> X = np.array([[1, 2], [2, 3], [3, 4]])
    >>> y = np.array([-1, 0, 1])
    >>> estimator.fit(X, y).predict(X)
    array([0, 0, 0])
    >>> estimator.score(X, y)
    0.0
    	regressorc                     t                                                      }d|_        t                      |_        d|j        _        |S )Nr   T)r   r   rJ   r   r   r   r   r   s     r'   r   zRegressorMixin.__sklearn_tags__d  s<    ww'')))+oo$(!r)   Nc                 T    ddl m} |                     |          } ||||          S )a  Return the coefficient of determination of the prediction.

        The coefficient of determination :math:`R^2` is defined as
        :math:`(1 - \frac{u}{v})`, where :math:`u` is the residual
        sum of squares ``((y_true - y_pred)** 2).sum()`` and :math:`v`
        is the total sum of squares ``((y_true - y_true.mean()) ** 2).sum()``.
        The best possible score is 1.0 and it can be negative (because the
        model can be arbitrarily worse). A constant model that always predicts
        the expected value of `y`, disregarding the input features, would get
        a :math:`R^2` score of 0.0.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Test samples. For some estimators this may be a precomputed
            kernel matrix or a list of generic objects instead with shape
            ``(n_samples, n_samples_fitted)``, where ``n_samples_fitted``
            is the number of samples used in the fitting for the estimator.

        y : array-like of shape (n_samples,) or (n_samples, n_outputs)
            True values for `X`.

        sample_weight : array-like of shape (n_samples,), default=None
            Sample weights.

        Returns
        -------
        score : float
            :math:`R^2` of ``self.predict(X)`` w.r.t. `y`.

        Notes
        -----
        The :math:`R^2` score used when calling ``score`` on a regressor uses
        ``multioutput='uniform_average'`` from version 0.23 to keep consistent
        with default value of :func:`~sklearn.metrics.r2_score`.
        This influences the ``score`` method of all the multioutput
        regressors (except for
        :class:`~sklearn.multioutput.MultiOutputRegressor`).
        r   )r2_scorer   )r   r   r   )rY   r   r   r   r   y_preds         r'   r   zRegressorMixin.scorek  s=    R 	&%%%%%ax6????r)   r   r   r   s   @r'   r   r   ?  sf         D "O    ,@ ,@ ,@ ,@ ,@ ,@ ,@ ,@r)   r   c                   .     e Zd ZdZdZ fdZddZ xZS )ClusterMixinap  Mixin class for all cluster estimators in scikit-learn.

    - set estimator type to `"clusterer"` through the `estimator_type` tag;
    - `fit_predict` method returning the cluster labels associated to each sample.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import BaseEstimator, ClusterMixin
    >>> class MyClusterer(ClusterMixin, BaseEstimator):
    ...     def fit(self, X, y=None):
    ...         self.labels_ = np.ones(shape=(len(X),), dtype=np.int64)
    ...         return self
    >>> X = [[1, 2], [2, 3], [3, 4]]
    >>> MyClusterer().fit_predict(X)
    array([1, 1, 1])
    	clustererc                 |    t                                                      }d|_        |j        g |j        _        |S )Nr   )r   r   rJ   r   preserves_dtyper   s     r'   r   zClusterMixin.__sklearn_tags__  s9    ww''))) ,46D!1r)   Nc                 ,     | j         |fi | | j        S )a  
        Perform clustering on `X` and returns cluster labels.

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

        y : Ignored
            Not used, present for API consistency by convention.

        **kwargs : dict
            Arguments to be passed to ``fit``.

            .. versionadded:: 1.4

        Returns
        -------
        labels : ndarray of shape (n_samples,), dtype=np.int64
            Cluster labels.
        )fitlabels_)rY   r   r   r   s       r'   fit_predictzClusterMixin.fit_predict  s&    0 	f|r)   r   r   r   r   r   r   r   r  r   r   s   @r'   r   r     s]         & "O           r)   r   c                   :    e Zd ZdZed             Zd Zd Zd ZdS )BiclusterMixina?  Mixin class for all bicluster estimators in scikit-learn.

    This mixin defines the following functionality:

    - `biclusters_` property that returns the row and column indicators;
    - `get_indices` method that returns the row and column indices of a bicluster;
    - `get_shape` method that returns the shape of a bicluster;
    - `get_submatrix` method that returns the submatrix corresponding to a bicluster.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import BaseEstimator, BiclusterMixin
    >>> class DummyBiClustering(BiclusterMixin, BaseEstimator):
    ...     def fit(self, X, y=None):
    ...         self.rows_ = np.ones(shape=(1, X.shape[0]), dtype=bool)
    ...         self.columns_ = np.ones(shape=(1, X.shape[1]), dtype=bool)
    ...         return self
    >>> X = np.array([[1, 1], [2, 1], [1, 0],
    ...               [4, 7], [3, 5], [3, 6]])
    >>> bicluster = DummyBiClustering().fit(X)
    >>> hasattr(bicluster, "biclusters_")
    True
    >>> bicluster.get_indices(0)
    (array([0, 1, 2, 3, 4, 5]), array([0, 1]))
    c                     | j         | j        fS )z{Convenient way to get row and column indicators together.

        Returns the ``rows_`` and ``columns_`` members.
        )rows_columns_rX   s    r'   biclusters_zBiclusterMixin.biclusters_  s     z4=((r)   c                     | j         |         }| j        |         }t          j        |          d         t          j        |          d         fS )a  Row and column indices of the `i`'th bicluster.

        Only works if ``rows_`` and ``columns_`` attributes exist.

        Parameters
        ----------
        i : int
            The index of the cluster.

        Returns
        -------
        row_ind : ndarray, dtype=np.intp
            Indices of rows in the dataset that belong to the bicluster.
        col_ind : ndarray, dtype=np.intp
            Indices of columns in the dataset that belong to the bicluster.
        r   )r  r	  npnonzero)rY   irowscolumnss       r'   get_indiceszBiclusterMixin.get_indices  sD    " z!}-"z$"BJw$7$7$:::r)   c                 ^    |                      |          }t          d |D                       S )a-  Shape of the `i`'th bicluster.

        Parameters
        ----------
        i : int
            The index of the cluster.

        Returns
        -------
        n_rows : int
            Number of rows in the bicluster.

        n_cols : int
            Number of columns in the bicluster.
        c              3   4   K   | ]}t          |          V  d S r   )r   )r.   r  s     r'   rp   z+BiclusterMixin.get_shape.<locals>.<genexpr>  s(      --SVV------r)   )r  r>   )rY   r  indicess      r'   	get_shapezBiclusterMixin.get_shape  s4      ""1%%--W------r)   c                     t          |d          }|                     |          \  }}||ddt          j        f         |f         S )a   Return the submatrix corresponding to bicluster `i`.

        Parameters
        ----------
        i : int
            The index of the cluster.
        data : array-like of shape (n_samples, n_features)
            The data.

        Returns
        -------
        submatrix : ndarray of shape (n_rows, n_cols)
            The submatrix corresponding to bicluster `i`.

        Notes
        -----
        Works with sparse matrices. Only works if ``rows_`` and
        ``columns_`` attributes exist.
        csr)accept_sparseN)r   r  r  newaxis)rY   r  datarow_indcol_inds        r'   get_submatrixzBiclusterMixin.get_submatrix  sM    * 4u555++A..GAAArzM*G344r)   N)	r   r   r   r   r   r
  r  r  r  r9   r)   r'   r  r    sf         6 ) ) X); ; ;*. . .&5 5 5 5 5r)   r  c                   *     e Zd ZdZ fdZddZ xZS )TransformerMixina  Mixin class for all transformers in scikit-learn.

    This mixin defines the following functionality:

    - a `fit_transform` method that delegates to `fit` and `transform`;
    - a `set_output` method to output `X` as a specific container type.

    If :term:`get_feature_names_out` is defined, then :class:`BaseEstimator` will
    automatically wrap `transform` and `fit_transform` to follow the `set_output`
    API. See the :ref:`developer_api_set_output` for details.

    :class:`OneToOneFeatureMixin` and
    :class:`ClassNamePrefixFeaturesOutMixin` are helpful mixins for
    defining :term:`get_feature_names_out`.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import BaseEstimator, TransformerMixin
    >>> class MyTransformer(TransformerMixin, BaseEstimator):
    ...     def __init__(self, *, param=1):
    ...         self.param = param
    ...     def fit(self, X, y=None):
    ...         return self
    ...     def transform(self, X):
    ...         return np.full(shape=len(X), fill_value=self.param)
    >>> transformer = MyTransformer()
    >>> X = [[1, 2], [2, 3], [3, 4]]
    >>> transformer.fit_transform(X)
    array([1, 1, 1])
    c                 n    t                                                      }t                      |_        |S r   )r   r   r   r   r   s     r'   r   z!TransformerMixin.__sklearn_tags__Z  s+    ww'')) / 1 1r)   Nc                 r   t                      re|                                                     d|                                          }|r(t	          j        d| j        j         dt                     |! | j	        |fi |
                    |          S  | j	        ||fi |
                    |          S )a  
        Fit to data, then transform it.

        Fits transformer to `X` and `y` with optional parameters `fit_params`
        and returns a transformed version of `X`.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Input samples.

        y :  array-like of shape (n_samples,) or (n_samples, n_outputs),                 default=None
            Target values (None for unsupervised transformations).

        **fit_params : dict
            Additional fit parameters.

        Returns
        -------
        X_new : ndarray array of shape (n_samples, n_features_new)
            Transformed array.
        	transformmethodr{   This object (ah  ) has a `transform` method which consumes metadata, but `fit_transform` does not forward metadata to `transform`. Please implement a custom `fit_transform` method to forward metadata to `transform` as well. Alternatively, you can explicitly do `set_transform_request`and set all values to `False` to disable metadata routed to `transform`, if that's an option.)r   get_metadata_routingconsumeskeysr   r   rF   r   UserWarningr  r"  )rY   r   r   
fit_paramstransform_paramss        r'   fit_transformzTransformerMixin.fit_transform_  s    F  	#88::CC":??+<+<  D       X(? X X X     948A,,,,66q999 48Aq//J//99!<<<r)   r   )r   r   r   r   r   r,  r   r   s   @r'   r  r  9  sW         @    
:= := := := := := := :=r)   r  c                       e Zd ZdZddZdS )OneToOneFeatureMixina  Provides `get_feature_names_out` for simple transformers.

    This mixin assumes there's a 1-to-1 correspondence between input features
    and output features, such as :class:`~sklearn.preprocessing.StandardScaler`.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import OneToOneFeatureMixin, BaseEstimator
    >>> class MyEstimator(OneToOneFeatureMixin, BaseEstimator):
    ...     def fit(self, X, y=None):
    ...         self.n_features_in_ = X.shape[1]
    ...         return self
    >>> X = np.array([[1, 2], [3, 4]])
    >>> MyEstimator().fit(X).get_feature_names_out()
    array(['x0', 'x1'], dtype=object)
    Nc                 D    t          | d           t          | |          S )a  Get output feature names for transformation.

        Parameters
        ----------
        input_features : array-like of str or None, default=None
            Input features.

            - If `input_features` is `None`, then `feature_names_in_` is
              used as feature names in. If `feature_names_in_` is not defined,
              then the following input feature names are generated:
              `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
            - If `input_features` is an array-like, then `input_features` must
              match `feature_names_in_` if `feature_names_in_` is defined.

        Returns
        -------
        feature_names_out : ndarray of str objects
            Same as input features.
        n_features_in_)
attributes)r   r   rY   input_featuress     r'   get_feature_names_outz*OneToOneFeatureMixin.get_feature_names_out  s(    . 	)9::::&t^<<<r)   r   r   r   r   r   r4  r9   r)   r'   r.  r.    s2         $= = = = = =r)   r.  c                       e Zd ZdZddZdS )ClassNamePrefixFeaturesOutMixina0  Mixin class for transformers that generate their own names by prefixing.

    This mixin is useful when the transformer needs to generate its own feature
    names out, such as :class:`~sklearn.decomposition.PCA`. For example, if
    :class:`~sklearn.decomposition.PCA` outputs 3 features, then the generated feature
    names out are: `["pca0", "pca1", "pca2"]`.

    This mixin assumes that a `_n_features_out` attribute is defined when the
    transformer is fitted. `_n_features_out` is the number of output features
    that the transformer will return in `transform` of `fit_transform`.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import ClassNamePrefixFeaturesOutMixin, BaseEstimator
    >>> class MyEstimator(ClassNamePrefixFeaturesOutMixin, BaseEstimator):
    ...     def fit(self, X, y=None):
    ...         self._n_features_out = X.shape[1]
    ...         return self
    >>> X = np.array([[1, 2], [3, 4]])
    >>> MyEstimator().fit(X).get_feature_names_out()
    array(['myestimator0', 'myestimator1'], dtype=object)
    Nc                 P    t          | d           t          | | j        |          S )aF  Get output feature names for transformation.

        The feature names out will prefixed by the lowercased class name. For
        example, if the transformer outputs 3 features, then the feature names
        out are: `["class_name0", "class_name1", "class_name2"]`.

        Parameters
        ----------
        input_features : array-like of str or None, default=None
            Only used to validate feature names with the names seen in `fit`.

        Returns
        -------
        feature_names_out : ndarray of str objects
            Transformed feature names.
        _n_features_out)r3  )r   r   r9  r2  s     r'   r4  z5ClassNamePrefixFeaturesOutMixin.get_feature_names_out  s6    " 	/000.$&~
 
 
 	
r)   r   r5  r9   r)   r'   r7  r7    s2         0
 
 
 
 
 
r)   r7  c                   .     e Zd ZdZdZ fdZddZ xZS )DensityMixina"  Mixin class for all density estimators in scikit-learn.

    This mixin defines the following functionality:

    - sets estimator type to `"density_estimator"` through the `estimator_type` tag;
    - `score` method that default that do no-op.

    Examples
    --------
    >>> from sklearn.base import DensityMixin
    >>> class MyEstimator(DensityMixin):
    ...     def fit(self, X, y=None):
    ...         self.is_fitted_ = True
    ...         return self
    >>> estimator = MyEstimator()
    >>> hasattr(estimator, "score")
    True
    DensityEstimatorc                 V    t                                                      }d|_        |S )Ndensity_estimatorr   r   rJ   r   s     r'   r   zDensityMixin.__sklearn_tags__  s%    ww''))1r)   Nc                     dS )a=  Return the score of the model on the data `X`.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Test samples.

        y : Ignored
            Not used, present for API consistency by convention.

        Returns
        -------
        score : float
        Nr9   )rY   r   r   s      r'   r   zDensityMixin.score  s	     	r)   r   r   r   s   @r'   r;  r;    s]         ( )O    
       r)   r;  c                   .     e Zd ZdZdZ fdZddZ xZS )OutlierMixina  Mixin class for all outlier detection estimators in scikit-learn.

    This mixin defines the following functionality:

    - set estimator type to `"outlier_detector"` through the `estimator_type` tag;
    - `fit_predict` method that default to `fit` and `predict`.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.base import BaseEstimator, OutlierMixin
    >>> class MyEstimator(OutlierMixin):
    ...     def fit(self, X, y=None):
    ...         self.is_fitted_ = True
    ...         return self
    ...     def predict(self, X):
    ...         return np.ones(shape=len(X))
    >>> estimator = MyEstimator()
    >>> X = np.array([[1, 2], [2, 3], [3, 4]])
    >>> estimator.fit_predict(X)
    array([1., 1., 1.])
    outlier_detectorc                 V    t                                                      }d|_        |S )NrC  r?  r   s     r'   r   zOutlierMixin.__sklearn_tags__C  s%    ww''))0r)   Nc                 *   t                      re|                                                     d|                                          }|r(t	          j        d| j        j         dt                      | j	        |fi |
                    |          S )a.  Perform fit on X and returns labels for X.

        Returns -1 for outliers and 1 for inliers.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            The input samples.

        y : Ignored
            Not used, present for API consistency by convention.

        **kwargs : dict
            Arguments to be passed to ``fit``.

            .. versionadded:: 1.4

        Returns
        -------
        y : ndarray of shape (n_samples,)
            1 for inliers, -1 for outliers.
        r   r#  r%  aY  ) has a `predict` method which consumes metadata, but `fit_predict` does not forward metadata to `predict`. Please implement a custom `fit_predict` method to forward metadata to `predict` as well.Alternatively, you can explicitly do `set_predict_request`and set all values to `False` to disable metadata routed to `predict`, if that's an option.)r   r&  r'  r(  r   r   rF   r   r)  r  r   )rY   r   r   r   r+  s        r'   r  zOutlierMixin.fit_predictH  s    >  	#88::CC   D       :(? : : :     tx$$V$$,,Q///r)   r   r  r   s   @r'   rB  rB  (  s]         0 )O    
20 20 20 20 20 20 20 20r)   rB  c                       e Zd ZdZdS )MetaEstimatorMixina  Mixin class for all meta estimators in scikit-learn.

    This mixin is empty, and only exists to indicate that the estimator is a
    meta-estimator.

    .. versionchanged:: 1.6
        The `_required_parameters` is now removed and is unnecessary since tests are
        refactored and don't use this anymore.

    Examples
    --------
    >>> from sklearn.base import MetaEstimatorMixin
    >>> from sklearn.datasets import load_iris
    >>> from sklearn.linear_model import LogisticRegression
    >>> class MyEstimator(MetaEstimatorMixin):
    ...     def __init__(self, *, estimator=None):
    ...         self.estimator = estimator
    ...     def fit(self, X, y=None):
    ...         if self.estimator is None:
    ...             self.estimator_ = LogisticRegression()
    ...         else:
    ...             self.estimator_ = self.estimator
    ...         return self
    >>> X, y = load_iris(return_X_y=True)
    >>> estimator = MyEstimator().fit(X, y)
    >>> estimator.estimator_
    LogisticRegression()
    N)r   r   r   r   r9   r)   r'   rG  rG  }  s           r)   rG  c                   "     e Zd ZdZ fdZ xZS )MultiOutputMixinz2Mixin to mark estimators that support multioutput.c                 `    t                                                      }d|j        _        |S )NT)r   r   r   multi_outputr   s     r'   r   z!MultiOutputMixin.__sklearn_tags__  s(    ww''))(,%r)   r   r   r   r   r   r   r   s   @r'   rI  rI    s>        <<        r)   rI  c                   "     e Zd ZdZ fdZ xZS )_UnstableArchMixinz=Mark estimators that are non-determinstic on 32bit or PowerPCc                     t                                                      }t          p%t          j                                        d          |_        |S )N)ppcpowerpc)r   r   r   platformmachiner   non_deterministicr   s     r'   r   z#_UnstableArchMixin.__sklearn_tags__  sJ    ww''))!* "
h.>.@.@.K.K/
 /
 r)   rL  r   s   @r'   rN  rN    s>        GG        r)   rN  c                    t          | t                    r]t          j        dt	          t          j                    d         d                    dt                     t          | dd          dk    S t          |           j
        dk    S )am  Return True if the given estimator is (probably) a classifier.

    Parameters
    ----------
    estimator : object
        Estimator object to test.

    Returns
    -------
    out : bool
        True if estimator is a classifier and False otherwise.

    Examples
    --------
    >>> from sklearn.base import is_classifier
    >>> from sklearn.cluster import KMeans
    >>> from sklearn.svm import SVC, SVR
    >>> classifier = SVC()
    >>> regressor = SVR()
    >>> kmeans = KMeans()
    >>> is_classifier(classifier)
    True
    >>> is_classifier(regressor)
    False
    >>> is_classifier(kmeans)
    False
    passing a class to r      P is deprecated and will be removed in 1.8. Use an instance of the class instead.r   Nr   rA   r:   r   r   printr#   stackr   r_   r   rJ   r&   s    r'   is_classifierr]    s    : )T"" KL%(:1(=">"> L L L	
 	
 	

 y"3T::lJJI-==r)   c                    t          | t                    r]t          j        dt	          t          j                    d         d                    dt                     t          | dd          dk    S t          |           j
        dk    S )as  Return True if the given estimator is (probably) a regressor.

    Parameters
    ----------
    estimator : estimator instance
        Estimator object to test.

    Returns
    -------
    out : bool
        True if estimator is a regressor and False otherwise.

    Examples
    --------
    >>> from sklearn.base import is_regressor
    >>> from sklearn.cluster import KMeans
    >>> from sklearn.svm import SVC, SVR
    >>> classifier = SVC()
    >>> regressor = SVR()
    >>> kmeans = KMeans()
    >>> is_regressor(classifier)
    False
    >>> is_regressor(regressor)
    True
    >>> is_regressor(kmeans)
    False
    rV  r   rW  rX  r   Nr   rY  r\  s    r'   is_regressorr_    s    : )T"" JL%(:1(=">"> L L L	
 	
 	

 y"3T::kIII-<<r)   c                    t          | t                    r]t          j        dt	          t          j                    d         d                    dt                     t          | dd          dk    S t          |           j
        dk    S )a  Return True if the given estimator is (probably) a clusterer.

    .. versionadded:: 1.6

    Parameters
    ----------
    estimator : object
        Estimator object to test.

    Returns
    -------
    out : bool
        True if estimator is a clusterer and False otherwise.

    Examples
    --------
    >>> from sklearn.base import is_clusterer
    >>> from sklearn.cluster import KMeans
    >>> from sklearn.svm import SVC, SVR
    >>> classifier = SVC()
    >>> regressor = SVR()
    >>> kmeans = KMeans()
    >>> is_clusterer(classifier)
    False
    >>> is_clusterer(regressor)
    False
    >>> is_clusterer(kmeans)
    True
    rV  r   rW  rX  r   Nr   rY  r\  s    r'   is_clustererra     s    > )T"" JL%(:1(=">"> L L L	
 	
 	

 y"3T::kIII-<<r)   c                    t          | t                    r]t          j        dt	          t          j                    d         d                    dt                     t          | dd          dk    S t          |           j
        dk    S )a  Return True if the given estimator is (probably) an outlier detector.

    Parameters
    ----------
    estimator : estimator instance
        Estimator object to test.

    Returns
    -------
    out : bool
        True if estimator is an outlier detector and False otherwise.
    rV  r   rW  rX  r   NrC  rY  r\  s    r'   is_outlier_detectorrc  *  s     )T"" QL%(:1(=">"> L L L	
 	
 	

 y"3T::>PPPI-1CCCr)   c                       fd}|S )aC  Decorator to run the fit methods of estimators within context managers.

    Parameters
    ----------
    prefer_skip_nested_validation : bool
        If True, the validation of parameters of inner estimators or functions
        called during fit will be skipped.

        This is useful to avoid validating many times the parameters passed by the
        user from the public facing API. It's also useful to avoid validating
        parameters that we pass internally to inner functions that are guaranteed to
        be valid by the test suite.

        It should be set to True for most estimators, except for those that receive
        non-validated objects as parameters, such as meta-estimators that are given
        estimator objects.

    Returns
    -------
    decorated_fit : method
        The decorated fit method.
    c                 J     t          j                    fd            }|S )Nc                     t                      d         }j        dk    ot          |           }|s|s|                                  t	          p|          5   | g|R i |cd d d            S # 1 swxY w Y   d S )Nskip_parameter_validationpartial_fit)rg  )r   r   r   r   r   )r&   r   r   global_skip_validationpartial_fit_and_fitted
fit_methodprefer_skip_nested_validations        r'   wrapperz0_fit_context.<locals>.decorator.<locals>.wrapper\  s    %/\\2M%N" #}4NI9N9N # * -2H -**,,,1K5K   > >
 "z)=d===f==> > > > > > > > > > > > > > > > > >s   A33A7:A7)	functoolswraps)rk  rm  rl  s   ` r'   	decoratorz_fit_context.<locals>.decorator[  s>    		$	$	> 	> 	> 	> 	> 
%	$	>$ r)   r9   )rl  rp  s   ` r'   _fit_contextrq  C  s$    0    , r)   )Br   rB   rn  r#   rR  r   r   collectionsr   numpyr  r   r   _configr   r   
exceptionsr   utils._estimator_html_reprr	   r
   utils._metadata_requestsr   r   utils._param_validationr   utils._set_outputr   utils._tagsr   r   r   r   r   r   utils.fixesr   utils.validationr   r   r   r   r   r   r   r   r(   r%   rT   r   r   r   r  r  r.  r7  r;  rB  rG  rI  rN  r]  r_  ra  rc  rq  r9   r)   r'   <module>r}     s   D D
        				  # # # # # #           / / / / / / / / 2 2 2 2 2 2 X X X X X X X X J J J J J J J J C C C C C C . . . . . .                # " " " " "	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 " 35 35 35 35 35l ,0 7 7 7 7 7tW4 W4 W4 W4 W4/1C W4 W4 W4t
FO FO FO FO FO FO FO FORX@ X@ X@ X@ X@ X@ X@ X@v6 6 6 6 6 6 6 6rc5 c5 c5 c5 c5 c5 c5 c5L`= `= `= `= `= `= `= `=F+= += += += += += += +=\-
 -
 -
 -
 -
 -
 -
 -
`+ + + + + + + +\R0 R0 R0 R0 R0 R0 R0 R0j       >              %> %> %>P%= %= %=P'= '= '=TD D D2. . . . .r)   