U
    ½mœdï–  ã                   @   sÖ  d Z ddlZddlZddlm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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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lmZ ddlm Z  ddœdd„Z!G dd„ dƒZ"G dd„ dƒZ#G dd„ dƒZ$G dd„ dƒZ%G d d!„ d!ƒZ&G d"d#„ d#eƒZ'G d$d%„ d%ƒZ(G d&d'„ d'ƒZ)G d(d)„ d)ƒZ*G d*d+„ d+ƒZ+G d,d-„ d-ƒZ,G d.d/„ d/ƒZ-G d0d1„ d1ƒZ.d2d3„ Z/d4d5„ Z0d6d7„ Z1dS )8z Base classes for all estimators.é    N)Údefaultdicté   )Ú__version__)Ú
get_config)Ú	_IS_32BIT)Ú_SetOutputMixin©Ú_DEFAULT_TAGS)Ú	check_X_y©Úcheck_array)Ú_check_y)Ú_num_features©Ú_check_feature_names_in)Ú_generate_get_feature_names_out)Úcheck_is_fitted)Ú_get_feature_names©Úestimator_html_repr)Úvalidate_parameter_constraintsT©Úsafec                   s  t | ƒ}|ttttfkr.|‡ fdd„| D ƒƒS t| dƒrBt| t ƒr|ˆ sPt | ¡S t| t ƒrdt	dƒ‚nt	dt
| ƒt | ƒf ƒ‚| j}| jdd�}| ¡ D ]\}}t|dd�||< q–|f |Ž}|jdd�}|D ],}|| }	|| }
|	|
k	rÊtd	| |f ƒ‚qÊt| d
ƒ�rt | j¡|_|S )ar  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.

    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.

    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`.
    c                    s   g | ]}t |ˆ d �‘qS )r   )Úclone)Ú.0Úer   © úE/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/base.pyÚ
<listcomp>C   s     zclone.<locals>.<listcomp>Ú
get_paramszaCannot clone object. You should provide an instance of scikit-learn estimator instead of a class.zƒCannot clone object '%s' (type %s): it does not seem to be a scikit-learn estimator as it does not implement a 'get_params' method.F©Údeepr   zWCannot clone object %s, as the constructor either does not set or modifies parameter %sÚ_sklearn_output_config)ÚtypeÚlistÚtupleÚsetÚ	frozensetÚhasattrÚ
isinstanceÚcopyÚdeepcopyÚ	TypeErrorÚreprÚ	__class__r   Úitemsr   ÚRuntimeErrorr"   )Ú	estimatorr   Zestimator_typeÚklassZnew_object_paramsÚnameÚparamZ
new_objectZ
params_setZparam1Zparam2r   r   r   r   "   sF    

ÿýÿ
ÿÿÿr   c                       s¢   e Zd ZdZedd„ ƒZd$dd„Zdd„ Zd%d
d„Z‡ fdd„Z	‡ fdd„Z
dd„ Zdd„ Zdd„ Zdd„ Zd&dd„Zdd„ Zedd„ ƒZd d!„ Zd"d#„ Z‡  ZS )'ÚBaseEstimatorzüBase class for all estimators in scikit-learn.

    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``).
    c                 C   st   t | jd| jƒ}|tjkrg S t |¡}dd„ |j ¡ D ƒ}|D ] }|j|jkr@t	d| |f ƒ‚q@t
dd„ |D ƒƒS )z%Get parameter names for the estimatorZdeprecated_originalc                 S   s&   g | ]}|j d kr|j|jkr|‘qS ©Úself)r3   ÚkindÚVAR_KEYWORD©r   Úpr   r   r   r   ˆ   s   
 þz2BaseEstimator._get_param_names.<locals>.<listcomp>z§scikit-learn estimators should always specify their parameters in the signature of their __init__ (no varargs). %s with constructor %s doesn't  follow this convention.c                 S   s   g | ]
}|j ‘qS r   )r3   r:   r   r   r   r   —   s     )ÚgetattrÚ__init__ÚobjectÚinspectÚ	signatureÚ
parametersÚvaluesr8   ÚVAR_POSITIONALr0   Úsorted)ÚclsÚinitZinit_signaturerA   r;   r   r   r   Ú_get_param_namesz   s    

þüÿzBaseEstimator._get_param_namesTc                    sf   t ƒ }|  ¡ D ]R‰ t| ˆ ƒ}|rXt|dƒrXt|tƒsX| ¡  ¡ }| ‡ fdd„|D ƒ¡ ||ˆ < q|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.
        r   c                 3   s"   | ]\}}ˆ d  | |fV  qdS )Ú__Nr   )r   ÚkÚval©Úkeyr   r   Ú	<genexpr>­   s     z+BaseEstimator.get_params.<locals>.<genexpr>)	ÚdictrG   r<   r(   r)   r#   r   r/   Úupdate)r7   r!   ÚoutÚvalueZ
deep_itemsr   rK   r   r   ™   s    

zBaseEstimator.get_paramsc           
   	   K   s   |s| S | j dd�}ttƒ}| ¡ D ]j\}}| d¡\}}}||krh|  ¡ }td|›d| › d|›d�ƒ‚|rz||| |< q$t| ||ƒ |||< q$| ¡ D ]b\}}	|dkrê|| d	krê| j 	d
¡rêt
jd| jj› d| jj› d�tdd� d}|| jf |	Ž q˜| 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.
        Tr    rH   zInvalid parameter z for estimator z. Valid parameters are: Ú.Zbase_estimatorÚ
deprecatedúsklearn.zParameter 'base_estimator' of z, is deprecated in favor of 'estimator'. See z's docstring for more details.é   )Ú
stacklevelr1   )r   r   rN   r/   Ú	partitionrG   Ú
ValueErrorÚsetattrÚ
__module__Ú
startswithÚwarningsÚwarnr.   Ú__name__ÚFutureWarningÚ
set_params)
r7   ÚparamsZvalid_paramsZnested_paramsrL   rQ   ÚdelimZsub_keyZlocal_valid_paramsZ
sub_paramsr   r   r   r`   ±   s<    ÿ
ÿ
þ
ýûzBaseEstimator.set_paramsé¼  c                 C   sð   ddl m} d}|ddd|d�}| | ¡}td | ¡ ¡ƒ}||krì|d }d| }t ||¡ ¡ }	t ||d d d	… ¡ ¡ }
d
||	|
 … kr²|d7 }t ||d d d	… ¡ ¡ }
d}|	t|ƒ t|ƒ|
 k rì|d |	… d ||
 d …  }|S )Nr   )Ú_EstimatorPrettyPrinteré   T)ÚcompactÚindentZindent_at_nameZn_max_elements_to_showÚ rU   z^(\s*\S){%d}éÿÿÿÿÚ
z[^\n]*\nz...)	Zutils._pprintrd   ÚpformatÚlenÚjoinÚsplitÚreÚmatchÚend)r7   Z
N_CHAR_MAXrd   ZN_MAX_ELEMENTS_TO_SHOWÚppÚrepr_Z
n_nonblankZlimÚregexZleft_limZ	right_limÚellipsisr   r   r   Ú__repr__ð   s,    ü
	zBaseEstimator.__repr__c                    s|   t | dd ƒrtdƒ‚z tƒ  ¡ }|d kr2| j ¡ }W n tk
rR   | j ¡ }Y nX t| ƒj 	d¡rtt
| ¡ td�S |S d S )NÚ	__slots__zSYou cannot use `__slots__` in objects inheriting from `sklearn.base.BaseEstimator`.rT   )Ú_sklearn_version)r<   r,   ÚsuperÚ__getstate__Ú__dict__r*   ÚAttributeErrorr#   rZ   r[   rN   r/   r   )r7   Ústate©r.   r   r   rz   $  s    ÿ
zBaseEstimator.__getstate__c                    st   t | ƒj d¡r>| dd¡}|tkr>t d | jj	|t¡t
¡ ztƒ  |¡ W n  tk
rn   | j |¡ Y nX d S )NrT   rx   zpre-0.18a  Trying to unpickle estimator {0} from version {1} when using version {2}. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations)r#   rZ   r[   Úpopr   r\   r]   Úformatr.   r^   ÚUserWarningry   Ú__setstate__r|   r{   rO   )r7   r}   Zpickle_versionr~   r   r   r‚   :  s      ú÷zBaseEstimator.__setstate__c                 C   s   t S ©Nr   r6   r   r   r   Ú
_more_tagsN  s    zBaseEstimator._more_tagsc                 C   s<   i }t t | j¡ƒD ]"}t|dƒr| | ¡}| |¡ q|S )Nr„   )Úreversedr?   Úgetmror.   r(   r„   rO   )r7   Zcollected_tagsZ
base_classZ	more_tagsr   r   r   Ú	_get_tagsQ  s    

zBaseEstimator._get_tagsc              
   C   s®   zt |ƒ}W nT tk
r` } z6|sJt| dƒrJtd| jj› d| j› d�ƒ|‚W Y ¢dS d}~X Y nX |rp|| _dS t| dƒs~dS || jkrªtd|› d| jj› d| j› d�ƒ‚dS )	aÁ  Set the `n_features_in_` attribute, or check against it.

        Parameters
        ----------
        X : {ndarray, sparse matrix} of shape (n_samples, n_features)
            The input samples.
        reset : bool
            If True, the `n_features_in_` attribute is set to `X.shape[1]`.
            If False and the attribute exists, then check that it is equal to
            `X.shape[1]`. If False and the attribute does *not* exist, then
            the check is skipped.
            .. note::
               It is recommended to call reset=True in `fit` and in the first
               call to `partial_fit`. All other methods that validate `X`
               should set `reset=False`.
        Ún_features_in_z%X does not contain any features, but z is expecting z	 featuresNzX has z features, but z features as input.)r   r,   r(   rX   r.   r^   rˆ   )r7   ÚXÚresetZ
n_featuresr   r   r   r   Ú_check_n_features\  s&    ÿü

ÿzBaseEstimator._check_n_featuresc                C   sX  |r4t |ƒ}|dk	r|| _nt| dƒr0t| dƒ dS t| ddƒ}t |ƒ}|dkr\|dkr\dS |dk	r†|dkr†t d| jj› d�¡ dS |dkr°|dk	r°t d| jj› d�¡ dS t	|ƒt	|ƒksÐt
 ||k¡�rTd}t|ƒ}t|ƒ}t|| ƒ}	t|| ƒ}
dd	„ }|	�r|d
7 }|||	ƒ7 }|
�r8|d7 }|||
ƒ7 }|
�sL|	�sL|d7 }t|ƒ‚dS )a˜  Set or check the `feature_names_in_` attribute.

        .. versionadded:: 1.0

        Parameters
        ----------
        X : {ndarray, dataframe} of shape (n_samples, n_features)
            The input samples.

        reset : bool
            Whether to reset the `feature_names_in_` attribute.
            If False, the input will be checked for consistency with
            feature names of data provided when reset was last True.
            .. note::
               It is recommended to call `reset=True` in `fit` and in the first
               call to `partial_fit`. All other methods that validate `X`
               should set `reset=False`.
        NÚfeature_names_in_zX has feature names, but z! was fitted without feature namesz)X does not have valid feature names, but z was fitted with feature nameszBThe feature names should match those that were passed during fit.
c                 S   sB   d}d}t | ƒD ],\}}||kr,|d7 } q>|d|› d�7 }q|S )Nrh   é   z- ...
z- rj   )Ú	enumerate)ÚnamesÚoutputZmax_n_namesÚir3   r   r   r   Ú	add_namesÊ  s    z5BaseEstimator._check_feature_names.<locals>.add_namesz"Feature names unseen at fit time:
z1Feature names seen at fit time, yet now missing:
z=Feature names must be in the same order as they were in fit.
)r   rŒ   r(   Údelattrr<   r\   r]   r.   r^   rl   ÚnpÚanyr&   rD   rX   )r7   r‰   rŠ   Zfeature_names_inZfitted_feature_namesZX_feature_namesÚmessageZfitted_feature_names_setZX_feature_names_setZunexpected_namesZmissing_namesr’   r   r   r   Ú_check_feature_namesŠ  sT    

ÿÿÿÿ
ÿz"BaseEstimator._check_feature_namesÚno_validationFc                 K   sZ  | j ||d� |dkr6|  ¡ d r6td| jj› d�ƒ‚t|tƒoF|dk}|dkp`t|tƒo`|dk}d| i}||–}|r„|r„tdƒ‚n°|s¦|r¦t|fd	d
i|—Ž}|}	nŽ|rÀ|sÀt|f|Ž}|}	nt|�r|\}
}d|
krÞ||
–}
t|fd	d
i|
—Ž}d|k�r||–}t|fd	di|—Ž}nt	||f|Ž\}}||f}	|�sV| 
dd¡�rV| j||d� |	S )a}
  Validate input data and set or check the `n_features_in_` attribute.

        Parameters
        ----------
        X : {array-like, sparse matrix, dataframe} of shape                 (n_samples, n_features), default='no validation'
            The input samples.
            If `'no_validation'`, no validation is performed on `X`. This is
            useful for meta-estimator which can delegate input validation to
            their underlying estimator(s). In that case `y` must be passed and
            the only accepted `check_params` are `multi_output` and
            `y_numeric`.

        y : array-like of shape (n_samples,), default='no_validation'
            The targets.

            - If `None`, `check_array` is called on `X`. If the estimator's
              requires_y tag is True, then an error will be raised.
            - If `'no_validation'`, `check_array` is called on `X` and the
              estimator's requires_y tag is ignored. This is a default
              placeholder and is never meant to be explicitly set. In that case
              `X` must be passed.
            - Otherwise, only `y` with `_check_y` or both `X` and `y` are
              checked with either `check_array` or `check_X_y` depending on
              `validate_separately`.

        reset : bool, default=True
            Whether to reset the `n_features_in_` attribute.
            If False, the input will be checked for consistency with data
            provided when reset was last True.
            .. note::
               It is recommended to call reset=True in `fit` and in the first
               call to `partial_fit`. All other methods that validate `X`
               should set `reset=False`.

        validate_separately : False or tuple of dicts, default=False
            Only used if y is not None.
            If False, call validate_X_y(). Else, it must be a tuple of kwargs
            to be used for calling check_array() on X and y respectively.

            `estimator=self` is automatically added to these dicts to generate
            more informative error message in case of invalid input data.

        **check_params : kwargs
            Parameters passed to :func:`sklearn.utils.check_array` or
            :func:`sklearn.utils.check_X_y`. Ignored if validate_separately
            is not False.

            `estimator=self` is automatically added to these params to generate
            more informative error message in case of invalid input data.

        Returns
        -------
        out : {ndarray, sparse matrix} or tuple of these
            The validated input. A tuple is returned if both `X` and `y` are
            validated.
        )rŠ   NÚ
requires_yzThis z= estimator requires y to be passed, but the target y is None.r˜   r1   z*Validation should be done on X, y or both.Z
input_namer‰   ÚyZ	ensure_2dT)r—   r‡   rX   r.   r^   r)   Ústrr   r   r
   Úgetr‹   )r7   r‰   rš   rŠ   Zvalidate_separatelyZcheck_paramsZno_val_XZno_val_yZdefault_check_paramsrP   Zcheck_X_paramsZcheck_y_paramsr   r   r   Ú_validate_dataã  s<    Aÿ

zBaseEstimator._validate_datac                 C   s    t | j| jdd�| jjd� 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.
        Fr    )Zcaller_nameN)r   Z_parameter_constraintsr   r.   r^   r6   r   r   r   Ú_validate_paramsP  s
    
ýzBaseEstimator._validate_paramsc                 C   s   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   r|   Ú_repr_html_innerr6   r   r   r   Ú_repr_html_^  s
    ÿzBaseEstimator._repr_html_c                 C   s   t | ƒS )z½This function is returned by the @property `_repr_html_` to make
        `hasattr(estimator, "_repr_html_") return `True` or `False` depending
        on `get_config()["display"]`.
        r   r6   r   r   r   r¡   n  s    zBaseEstimator._repr_html_innerc                 K   s*   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)r-   r   r   )r7   Úkwargsr�   r   r   r   Ú_repr_mimebundle_u  s    zBaseEstimator._repr_mimebundle_)T)rc   )r˜   r˜   TF)r^   rZ   Ú__qualname__Ú__doc__ÚclassmethodrG   r   r`   rv   rz   r‚   r„   r‡   r‹   r—   r�   rž   Úpropertyr¢   r¡   r¤   Ú__classcell__r   r   r~   r   r5   p   s,   	

?
4.[    û
m
r5   c                   @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	ÚClassifierMixinz0Mixin class for all classifiers in scikit-learn.Ú
classifierNc                 C   s    ddl m} |||  |¡|d�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)r7   r‰   rš   r®   r¬   r   r   r   Úscore‚  s    zClassifierMixin.scorec                 C   s   ddiS ©Nr™   Tr   r6   r   r   r   r„   ž  s    zClassifierMixin._more_tags)N©r^   rZ   r¥   r¦   Ú_estimator_typer±   r„   r   r   r   r   rª   }  s   
rª   c                   @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	ÚRegressorMixinz:Mixin class for all regression estimators in scikit-learn.Ú	regressorNc                 C   s$   ddl m} |  |¡}||||d�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°   )r7   r‰   rš   r®   r·   Zy_predr   r   r   r±   §  s    )
zRegressorMixin.scorec                 C   s   ddiS r²   r   r6   r   r   r   r„   Õ  s    zRegressorMixin._more_tags)Nr³   r   r   r   r   rµ   ¢  s   
.rµ   c                   @   s&   e Zd ZdZdZddd„Zdd„ ZdS )	ÚClusterMixinz7Mixin class for all cluster estimators in scikit-learn.Z	clustererNc                 C   s   |   |¡ | 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.

        Returns
        -------
        labels : ndarray of shape (n_samples,), dtype=np.int64
            Cluster labels.
        )ÚfitZlabels_©r7   r‰   rš   r   r   r   Úfit_predictÞ  s    
zClusterMixin.fit_predictc                 C   s   dg iS )NZpreserves_dtyper   r6   r   r   r   r„   ô  s    zClusterMixin._more_tags)N)r^   rZ   r¥   r¦   r´   r»   r„   r   r   r   r   r¸   Ù  s   
r¸   c                   @   s4   e Zd ZdZedd„ ƒZdd„ Zdd„ Zdd	„ Zd
S )ÚBiclusterMixinz9Mixin class for all bicluster estimators in scikit-learn.c                 C   s   | j | jfS )z{Convenient way to get row and column indicators together.

        Returns the ``rows_`` and ``columns_`` members.
        )Úrows_Úcolumns_r6   r   r   r   Úbiclusters_û  s    zBiclusterMixin.biclusters_c                 C   s0   | j | }| j| }t |¡d t |¡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¾   r”   Znonzero)r7   r‘   ÚrowsÚcolumnsr   r   r   Úget_indices  s    

zBiclusterMixin.get_indicesc                 C   s   |   |¡}td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                 s   s   | ]}t |ƒV  qd S rƒ   )rl   )r   r‘   r   r   r   rM   )  s     z+BiclusterMixin.get_shape.<locals>.<genexpr>)rÂ   r%   )r7   r‘   Úindicesr   r   r   Ú	get_shape  s    
zBiclusterMixin.get_shapec                 C   s@   ddl m} ||d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.
        r   r   Zcsr)Zaccept_sparseN)Úutils.validationr   rÂ   r”   Znewaxis)r7   r‘   Údatar   Zrow_indZcol_indr   r   r   Úget_submatrix+  s    zBiclusterMixin.get_submatrixN)	r^   rZ   r¥   r¦   r¨   r¿   rÂ   rÄ   rÇ   r   r   r   r   r¼   ø  s   
r¼   c                   @   s   e Zd ZdZddd„ZdS )ÚTransformerMixina³  Mixin class for all transformers in scikit-learn.

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

    :class:`base.OneToOneFeatureMixin` and
    :class:`base.ClassNamePrefixFeaturesOutMixin` are helpful mixins for
    defining :term:`get_feature_names_out`.
    Nc                 K   s6   |dkr| j |f|Ž |¡S | j ||f|Ž |¡S d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.
        N)r¹   Z	transform)r7   r‰   rš   Z
fit_paramsr   r   r   Úfit_transformR  s    zTransformerMixin.fit_transform)N)r^   rZ   r¥   r¦   rÉ   r   r   r   r   rÈ   F  s   rÈ   c                   @   s   e Zd ZdZddd„ZdS )ÚOneToOneFeatureMixinzÖ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:`~preprocessing.StandardScaler`.
    Nc                 C   s
   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.
        r   ©r7   Úinput_featuresr   r   r   Úget_feature_names_out{  s    z*OneToOneFeatureMixin.get_feature_names_out)N©r^   rZ   r¥   r¦   rÍ   r   r   r   r   rÊ   t  s   rÊ   c                   @   s   e Zd ZdZddd„ZdS )ÚClassNamePrefixFeaturesOutMixinaE  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:`~decomposition.PCA`. For example, if
    :class:`~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`.
    Nc                 C   s   t | dƒ t| | j|d�S )aL  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 :meth:`fit`.

        Returns
        -------
        feature_names_out : ndarray of str objects
            Transformed feature names.
        Ú_n_features_out)rÌ   )r   r   rÐ   rË   r   r   r   rÍ   Ÿ  s    
  ÿz5ClassNamePrefixFeaturesOutMixin.get_feature_names_out)NrÎ   r   r   r   r   rÏ   ’  s   rÏ   c                   @   s   e Zd ZdZdZddd„ZdS )ÚDensityMixinz7Mixin class for all density estimators in scikit-learn.ZDensityEstimatorNc                 C   s   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
        Nr   rº   r   r   r   r±   »  s    zDensityMixin.score)N)r^   rZ   r¥   r¦   r´   r±   r   r   r   r   rÑ   ¶  s   rÑ   c                   @   s   e Zd ZdZdZddd„ZdS )ÚOutlierMixinzAMixin class for all outlier detection estimators in scikit-learn.Úoutlier_detectorNc                 C   s   |   |¡ |¡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.

        Returns
        -------
        y : ndarray of shape (n_samples,)
            1 for inliers, -1 for outliers.
        )r¹   r°   rº   r   r   r   r»   Ò  s    zOutlierMixin.fit_predict)N)r^   rZ   r¥   r¦   r´   r»   r   r   r   r   rÒ   Í  s   rÒ   c                   @   s   e Zd ZdgZdS )ÚMetaEstimatorMixinr1   N)r^   rZ   r¥   Z_required_parametersr   r   r   r   rÔ   è  s   rÔ   c                   @   s   e Zd ZdZdd„ ZdS )ÚMultiOutputMixinz2Mixin to mark estimators that support multioutput.c                 C   s   ddiS )NZmultioutputTr   r6   r   r   r   r„   ð  s    zMultiOutputMixin._more_tagsN©r^   rZ   r¥   r¦   r„   r   r   r   r   rÕ   í  s   rÕ   c                   @   s   e Zd ZdZdd„ ZdS )Ú_UnstableArchMixinz=Mark estimators that are non-determinstic on 32bit or PowerPCc                 C   s   dt pt ¡  d¡iS )NZnon_deterministic)ÚppcZpowerpc)r   ÚplatformÚmachiner[   r6   r   r   r   r„   ÷  s    þz_UnstableArchMixin._more_tagsNrÖ   r   r   r   r   r×   ô  s   r×   c                 C   s   t | ddƒdkS )a  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.
    r´   Nr«   ©r<   ©r1   r   r   r   Úis_classifierÿ  s    rÝ   c                 C   s   t | ddƒdkS )a  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.
    r´   Nr¶   rÛ   rÜ   r   r   r   Úis_regressor  s    rÞ   c                 C   s   t | ddƒ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.
    r´   NrÓ   rÛ   rÜ   r   r   r   Úis_outlier_detector  s    rß   )2r¦   r*   r\   Úcollectionsr   rÙ   r?   ro   Únumpyr”   rh   r   Ú_configr   Úutilsr   Zutils._set_outputr   Zutils._tagsr	   rÅ   r
   r   r   r   r   r   r   r   Zutils._estimator_html_reprr   Zutils._param_validationr   r   r5   rª   rµ   r¸   r¼   rÈ   rÊ   rÏ   rÑ   rÒ   rÔ   rÕ   r×   rÝ   rÞ   rß   r   r   r   r   Ú<module>   sV   N    %7N.$