
    0Ph                         d dl mZ d dl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  G d
 dee          ZdS )    )RealN   )BaseEstimator_fit_context)Interval)mean_variance_axismin_max_axis)check_is_fittedvalidate_data   )SelectorMixinc                        e Zd ZU dZd eeddd          giZeed<   dd	Z	 e
d
          dd            Zd Z fdZ xZS )VarianceThresholdat  Feature selector that removes all low-variance features.

    This feature selection algorithm looks only at the features (X), not the
    desired outputs (y), and can thus be used for unsupervised learning.

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

    Parameters
    ----------
    threshold : float, default=0
        Features with a training-set variance lower than this threshold will
        be removed. The default is to keep all features with non-zero variance,
        i.e. remove the features that have the same value in all samples.

    Attributes
    ----------
    variances_ : array, shape (n_features,)
        Variances of individual features.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    SelectFromModel: Meta-transformer for selecting features based on
        importance weights.
    SelectPercentile : Select features according to a percentile of the highest
        scores.
    SequentialFeatureSelector : Transformer that performs Sequential Feature
        Selection.

    Notes
    -----
    Allows NaN in the input.
    Raises ValueError if no feature in X meets the variance threshold.

    Examples
    --------
    The following dataset has integer features, two of which are the same
    in every sample. These are removed with the default setting for threshold::

        >>> from sklearn.feature_selection import VarianceThreshold
        >>> X = [[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]
        >>> selector = VarianceThreshold()
        >>> selector.fit_transform(X)
        array([[2, 0],
               [1, 4],
               [1, 1]])
    	thresholdr   Nleft)closed_parameter_constraints        c                     || _         d S N)r   )selfr   s     m/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/feature_selection/_variance_threshold.py__init__zVarianceThreshold.__init__N   s    "    T)prefer_skip_nested_validationc                    t          | |dt          j        d          }t          |d          r>t	          |d          \  }| _        | j        dk    rt          |d          \  }}||z
  }n<t          j        |d          | _        | j        dk    rt          j	        |d          }| j        dk    r6t          j
        | j        |g          }t          j        |d          | _        t          j        t          j        | j                   | j        | j        k    z            r?d}|j        d         dk    r|d	z  }t          |                    | j                            | S )
a  Learn empirical variances from X.

        Parameters
        ----------
        X : {array-like, sparse matrix}, shape (n_samples, n_features)
            Data from which to compute variances, where `n_samples` is
            the number of samples and `n_features` is the number of features.

        y : any, default=None
            Ignored. This parameter exists only for compatibility with
            sklearn.pipeline.Pipeline.

        Returns
        -------
        self : object
            Returns the instance itself.
        )csrcscz	allow-nan)accept_sparsedtypeensure_all_finitetoarrayr   )axisz4No feature in X meets the variance threshold {0:.5f}r   z (X contains only one sample))r   npfloat64hasattrr   
variances_r   r	   nanvarptparraynanminallisfiniteshape
ValueErrorformat)	r   Xy_minsmaxespeak_to_peakscompare_arrmsgs	            r   fitzVarianceThreshold.fitQ   sd   & (*)
 
 
 1i   	2!3AA!>!>!>At~""*11555e % i222DO~"" "qq 1 1 1>Q (DO]#CDDK i!<<<DO62;t///4?dn3TUVV 	9HCwqzQ66SZZ77888r   c                 @    t          |            | j        | j        k    S r   )r
   r'   r   )r   s    r   _get_support_maskz#VarianceThreshold._get_support_mask   s    //r   c                 x    t                                                      }d|j        _        d|j        _        |S )NT)super__sklearn_tags__
input_tags	allow_nansparse)r   tags	__class__s     r   r>   z"VarianceThreshold.__sklearn_tags__   s1    ww''))$(!!%r   )r   r   )__name__
__module____qualname____doc__r   r   r   dict__annotations__r   r   r9   r;   r>   __classcell__)rC   s   @r   r   r      s         8 8v 	hhtQV<<<=$D   # # # # \5550 0 0 650d0 0 0
        r   r   )numbersr   numpyr$   baser   r   utils._param_validationr   utils.sparsefuncsr   r	   utils.validationr
   r   _baser   r    r   r   <module>rS      s              . . . . . . . . . . . . . . @ @ @ @ @ @ @ @ = = = = = = = =            ~ ~ ~ ~ ~} ~ ~ ~ ~ ~r   