ó
‡ˆ\c           @   sœ  d  Z  d d l Z d d l Z d d l m Z m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z m Z m Z m Z m Z d d	 l m Z m Z d d
 l m Z d d l	 m Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d e
 e f d „  ƒ  YZ  d e  f d „  ƒ  YZ! d e  f d „  ƒ  YZ" d e  f d „  ƒ  YZ# d e  f d „  ƒ  YZ$ d e  f d „  ƒ  YZ% d e  f d  „  ƒ  YZ& d S(!   s   Univariate features selection.iÿÿÿÿN(   t   specialt   stats(   t   issparsei   (   t   BaseEstimator(   t   LabelBinarizer(   t   as_float_arrayt   check_arrayt	   check_X_yt   safe_sqrt	   safe_mask(   t   safe_sparse_dott	   row_norms(   t   check_is_fittedi   (   t   SelectorMixinc         C   s8   t  |  d t ƒ}  t j |  j ƒ j |  t j |  ƒ <|  S(   s–   
    Fixes Issue #1240: NaNs can't be properly compared, so change them to the
    smallest value of scores's dtype. -inf seems to be unreliable.
    t   copy(   R   t   Truet   npt   finfot   dtypet   mint   isnan(   t   scores(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   _clean_nans   s    "c          G   s	  t  |  ƒ } g  |  D] } t | ƒ ^ q }  t j g  |  D] } | j d ^ q8 ƒ } t j | ƒ } t d „  |  Dƒ ƒ } g  |  D]! } t j | j d d ƒ ƒ ^ q€ } t | ƒ d } g  | D] } | d ^ q¾ }	 | | t | ƒ }
 d } x0 t |  ƒ D]" \ } } | |	 | | | 7} qû W| | t | ƒ 8} |
 | } | d } | | } | t | ƒ } | t | ƒ } t j	 | d k ƒ d } t j
 | ƒ d j | j k rË| j rËt j d | t ƒ n  | | } t j | ƒ j ƒ  } t j | | | ƒ } | | f S(   s*  Performs a 1-way ANOVA.

    The one-way ANOVA tests the null hypothesis that 2 or more groups have
    the same population mean. The test is applied to samples from two or
    more groups, possibly with differing sizes.

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

    Parameters
    ----------
    *args : array_like, sparse matrices
        sample1, sample2... The sample measurements should be given as
        arguments.

    Returns
    -------
    F-value : float
        The computed F-value of the test.
    p-value : float
        The associated p-value from the F-distribution.

    Notes
    -----
    The ANOVA test has important assumptions that must be satisfied in order
    for the associated p-value to be valid.

    1. The samples are independent
    2. Each sample is from a normally distributed population
    3. The population standard deviations of the groups are all equal. This
       property is known as homoscedasticity.

    If these assumptions are not true for a given set of data, it may still be
    possible to use the Kruskal-Wallis H-test (`scipy.stats.kruskal`_) although
    with some loss of power.

    The algorithm is from Heiman[2], pp.394-7.

    See ``scipy.stats.f_oneway`` that should give the same results while
    being less efficient.

    References
    ----------

    .. [1] Lowry, Richard.  "Concepts and Applications of Inferential
           Statistics". Chapter 14.
           http://faculty.vassar.edu/lowry/ch14pt1.html

    .. [2] Heiman, G.W.  Research Methods in Statistics. 2002.

    i    c         s   s'   |  ] } t  | ƒ j d  d ƒ Vq d S(   t   axisi    N(   R   t   sum(   t   .0t   a(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pys	   <genexpr>a   s    R   i   g        i   s   Features %s are constant.(   t   lenR   R   t   arrayt   shapeR   t   asarrayt   floatt	   enumeratet   wheret   nonzerot   sizet   warningst   warnt   UserWarningt   ravelR    t   fdtrc(   t   argst	   n_classesR   t   n_samples_per_classt	   n_samplest
   ss_alldatat	   sums_argst   square_of_sums_alldatat   st   square_of_sums_argst   sstott   ssbnt   kt   _t   sswnt   dfbnt   dfwnt   msbt   mswt   constant_features_idxt   ft   prob(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   f_oneway*   s4    3).


(

c         C   s`   t  |  | d d d g ƒ \ }  } g  t j | ƒ D] } |  t |  | | k ƒ ^ q1 } t | Œ  S(   s¯  Compute the ANOVA F-value for the provided sample.

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

    Parameters
    ----------
    X : {array-like, sparse matrix} shape = [n_samples, n_features]
        The set of regressors that will be tested sequentially.

    y : array of shape(n_samples)
        The data matrix.

    Returns
    -------
    F : array, shape = [n_features,]
        The set of F values.

    pval : array, shape = [n_features,]
        The set of p-values.

    See also
    --------
    chi2: Chi-squared stats of non-negative features for classification tasks.
    f_regression: F-value between label/feature for regression tasks.
    t   csrt   csct   coo(   R   R   t   uniqueR	   R>   (   t   Xt   yR4   R)   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt	   f_classifz   s    !5c         C   s   t  j |  d t  j ƒ}  t |  ƒ } |  } | | 8} | d C} t  j d d ƒ  | | :} Wd QX| j d d ƒ } | t j | d | ƒ f S(	   sŽ   Fast replacement for scipy.stats.chisquare.

    Version from https://github.com/scipy/scipy/pull/2525 with additional
    optimizations.
    R   i   t   invalidt   ignoreNR   i    i   (   R   R   t   float64R   t   errstateR   R    t   chdtrc(   t   f_obst   f_expR4   t   chisq(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt
   _chisquare™   s    

c         C   sÿ   t  |  d d ƒ}  t j t |  ƒ r- |  j n |  d k  ƒ rK t d ƒ ‚ n  t ƒ  j | ƒ } | j d d k r t j	 d | | d d ƒ} n  t
 | j |  ƒ } |  j d d ƒ j d d ƒ } | j d d ƒ j d d ƒ } t j | j | ƒ } t | | ƒ S(   s0  Compute chi-squared stats between each non-negative feature and class.

    This score can be used to select the n_features features with the
    highest values for the test chi-squared statistic from X, which must
    contain only non-negative features such as booleans or frequencies
    (e.g., term counts in document classification), relative to the classes.

    Recall that the chi-square test measures dependence between stochastic
    variables, so using this function "weeds out" the features that are the
    most likely to be independent of class and therefore irrelevant for
    classification.

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

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape = (n_samples, n_features_in)
        Sample vectors.

    y : array-like, shape = (n_samples,)
        Target vector (class labels).

    Returns
    -------
    chi2 : array, shape = (n_features,)
        chi2 statistics of each feature.
    pval : array, shape = (n_features,)
        p-values of each feature.

    Notes
    -----
    Complexity of this algorithm is O(n_classes * n_features).

    See also
    --------
    f_classif: ANOVA F-value between label/feature for classification tasks.
    f_regression: F-value between label/feature for regression tasks.
    t   accept_sparseR?   i    s   Input X must be non-negative.i   R   iÿÿÿÿ(   R   R   t   anyR   t   datat
   ValueErrorR   t   fit_transformR   t   appendR
   t   TR   t   reshapet   meant   dotRN   (   RC   RD   t   Yt   observedt   feature_countt
   class_probt   expected(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   chi2¬   s    **c   
      C   sI  t  |  | d d d g d t j ƒ\ }  } |  j d } | r¶ | t j | ƒ } t |  ƒ rw |  j d d ƒ j ƒ  } n |  j d d ƒ } t j t |  j	 d t
 ƒ| | d ƒ } n t |  j	 ƒ } t | |  ƒ } | | :} | t j j | ƒ :} | j | rd n d	 } | d d	 | d | } t j j | d	 | ƒ }	 | |	 f S(
   st  Univariate linear regression tests.

    Linear model for testing the individual effect of each of many regressors.
    This is a scoring function to be used in a feature selection procedure, not
    a free standing feature selection procedure.

    This is done in 2 steps:

    1. The correlation between each regressor and the target is computed,
       that is, ((X[:, i] - mean(X[:, i])) * (y - mean_y)) / (std(X[:, i]) *
       std(y)).
    2. It is converted to an F score then to a p-value.

    For more on usage see the :ref:`User Guide <univariate_feature_selection>`.

    Parameters
    ----------
    X : {array-like, sparse matrix}  shape = (n_samples, n_features)
        The set of regressors that will be tested sequentially.

    y : array of shape(n_samples).
        The data matrix

    center : True, bool,
        If true, X and y will be centered.

    Returns
    -------
    F : array, shape=(n_features,)
        F values of features.

    pval : array, shape=(n_features,)
        p-values of F-scores.


    See also
    --------
    mutual_info_regression: Mutual information for a continuous target.
    f_classif: ANOVA F-value between label/feature for classification tasks.
    chi2: Chi-squared stats of non-negative features for classification tasks.
    SelectKBest: Select features based on the k highest scores.
    SelectFpr: Select features based on a false positive rate test.
    SelectFdr: Select features based on an estimated false discovery rate.
    SelectFwe: Select features based on family-wise error rate.
    SelectPercentile: Select features based on percentile of the highest
        scores.
    R?   R@   RA   R   i    R   t   squaredi   i   (   R   R   RH   R   RW   R   t   getA1t   sqrtR   RU   R   R
   t   linalgt   normR#   R   R<   t   sf(
   RC   RD   t   centerR,   t   X_meanst   X_normst   corrt   degrees_of_freedomt   Ft   pv(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   f_regressionç   s"    0*
t   _BaseFilterc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sî   Initialize the univariate feature selection.

    Parameters
    ----------
    score_func : callable
        Function taking two arrays X and y, and returning a pair of arrays
        (scores, pvalues) or a single array with scores.
    c         C   s   | |  _  d  S(   N(   t
   score_func(   t   selfRn   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   __init__B  s    c         C   sä   t  | | d d g d t ƒ\ } } t |  j ƒ sX t d |  j t |  j ƒ f ƒ ‚ n  |  j | | ƒ |  j | | ƒ } t | t t	 f ƒ r¹ | \ |  _
 |  _ t j |  j ƒ |  _ n | |  _
 d |  _ t j |  j
 ƒ |  _
 |  S(   sš  Run score function on (X, y) and get the appropriate features.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
            The training input samples.

        y : array-like, shape = [n_samples]
            The target values (class labels in classification, real numbers in
            regression).

        Returns
        -------
        self : object
        R?   R@   t   multi_outputs<   The score function should be a callable, %s (%s) was passed.N(   R   R   t   callableRn   t	   TypeErrort   typet   _check_paramst
   isinstancet   listt   tuplet   scores_t   pvalues_R   R   t   None(   Ro   RC   RD   t   score_func_ret(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   fitE  s    $		c         C   s   d  S(   N(    (   Ro   RC   RD   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRu   i  s    (   t   __name__t
   __module__t   __doc__Rp   R}   Ru   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRm   8  s   		$t   SelectPercentilec           B   s/   e  Z d  Z e d d „ Z d „  Z d „  Z RS(   s–  Select features according to a percentile of the highest scores.

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

    Parameters
    ----------
    score_func : callable
        Function taking two arrays X and y, and returning a pair of arrays
        (scores, pvalues) or a single array with scores.
        Default is f_classif (see below "See also"). The default function only
        works with classification tasks.

    percentile : int, optional, default=10
        Percent of features to keep.

    Attributes
    ----------
    scores_ : array-like, shape=(n_features,)
        Scores of features.

    pvalues_ : array-like, shape=(n_features,)
        p-values of feature scores, None if `score_func` returned only scores.

    Examples
    --------
    >>> from sklearn.datasets import load_digits
    >>> from sklearn.feature_selection import SelectPercentile, chi2
    >>> X, y = load_digits(return_X_y=True)
    >>> X.shape
    (1797, 64)
    >>> X_new = SelectPercentile(chi2, percentile=10).fit_transform(X, y)
    >>> X_new.shape
    (1797, 7)

    Notes
    -----
    Ties between features with equal scores will be broken in an unspecified
    way.

    See also
    --------
    f_classif: ANOVA F-value between label/feature for classification tasks.
    mutual_info_classif: Mutual information for a discrete target.
    chi2: Chi-squared stats of non-negative features for classification tasks.
    f_regression: F-value between label/feature for regression tasks.
    mutual_info_regression: Mutual information for a continuous target.
    SelectKBest: Select features based on the k highest scores.
    SelectFpr: Select features based on a false positive rate test.
    SelectFdr: Select features based on an estimated false discovery rate.
    SelectFwe: Select features based on family-wise error rate.
    GenericUnivariateSelect: Univariate feature selector with configurable mode.
    i
   c         C   s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   t   superR   Rp   t
   percentile(   Ro   Rn   Rƒ   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRp   ¦  s    c         C   s9   d |  j  k o d k n s5 t d |  j  ƒ ‚ n  d  S(   Ni    id   s'   percentile should be >=0, <=100; got %r(   Rƒ   RR   (   Ro   RC   RD   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRu   ª  s    c         C   s  t  |  d ƒ |  j d k r; t j t |  j ƒ d t j ƒS|  j d k ri t j t |  j ƒ d t j ƒSt |  j ƒ } t j | d |  j ƒ } | | k } t j	 | | k ƒ d } t | ƒ r t
 t | ƒ |  j d ƒ } | | | j ƒ   } t | | <n  | S(   NRy   id   R   i    (   R   Rƒ   R   t   onesR   Ry   t   boolt   zerosR   R!   t   intR   R   (   Ro   R   t	   thresholdt   maskt   tiest	   max_featst	   kept_ties(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   _get_support_mask¯  s    (   R~   R   R€   RE   Rp   Ru   R   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR   p  s   4	t   SelectKBestc           B   s/   e  Z d  Z e d d „ Z d „  Z d „  Z RS(   sØ  Select features according to the k highest scores.

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

    Parameters
    ----------
    score_func : callable
        Function taking two arrays X and y, and returning a pair of arrays
        (scores, pvalues) or a single array with scores.
        Default is f_classif (see below "See also"). The default function only
        works with classification tasks.

    k : int or "all", optional, default=10
        Number of top features to select.
        The "all" option bypasses selection, for use in a parameter search.

    Attributes
    ----------
    scores_ : array-like, shape=(n_features,)
        Scores of features.

    pvalues_ : array-like, shape=(n_features,)
        p-values of feature scores, None if `score_func` returned only scores.

    Examples
    --------
    >>> from sklearn.datasets import load_digits
    >>> from sklearn.feature_selection import SelectKBest, chi2
    >>> X, y = load_digits(return_X_y=True)
    >>> X.shape
    (1797, 64)
    >>> X_new = SelectKBest(chi2, k=20).fit_transform(X, y)
    >>> X_new.shape
    (1797, 20)

    Notes
    -----
    Ties between features with equal scores will be broken in an unspecified
    way.

    See also
    --------
    f_classif: ANOVA F-value between label/feature for classification tasks.
    mutual_info_classif: Mutual information for a discrete target.
    chi2: Chi-squared stats of non-negative features for classification tasks.
    f_regression: F-value between label/feature for regression tasks.
    mutual_info_regression: Mutual information for a continuous target.
    SelectPercentile: Select features based on percentile of the highest scores.
    SelectFpr: Select features based on a false positive rate test.
    SelectFdr: Select features based on an estimated false discovery rate.
    SelectFwe: Select features based on family-wise error rate.
    GenericUnivariateSelect: Univariate feature selector with configurable mode.
    i
   c         C   s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   R‚   RŽ   Rp   R4   (   Ro   Rn   R4   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRp   ú  s    c         C   s\   |  j  d k p2 d |  j  k o0 | j d k n sX t d | j d |  j  f ƒ ‚ n  d  S(   Nt   alli    i   sP   k should be >=0, <= n_features = %d; got %r. Use k='all' to return all features.(   R4   R   RR   (   Ro   RC   RD   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRu   þ  s    5c         C   s­   t  |  d ƒ |  j d k r5 t j |  j j d t ƒS|  j d k r] t j |  j j d t ƒSt |  j ƒ } t j | j d t ƒ} d | t j	 | d d ƒ|  j <| Sd  S(   NRy   R   R   i    i   t   kindt	   mergesort(
   R   R4   R   R„   Ry   R   R…   R†   R   t   argsort(   Ro   R   R‰   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR     s    !(   R~   R   R€   RE   Rp   Ru   R   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRŽ   Ã  s   5	t	   SelectFprc           B   s&   e  Z d  Z e d d „ Z d „  Z RS(   s.  Filter: Select the pvalues below alpha based on a FPR test.

    FPR test stands for False Positive Rate test. It controls the total
    amount of false detections.

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

    Parameters
    ----------
    score_func : callable
        Function taking two arrays X and y, and returning a pair of arrays
        (scores, pvalues).
        Default is f_classif (see below "See also"). The default function only
        works with classification tasks.

    alpha : float, optional
        The highest p-value for features to be kept.

    Attributes
    ----------
    scores_ : array-like, shape=(n_features,)
        Scores of features.

    pvalues_ : array-like, shape=(n_features,)
        p-values of feature scores.

    Examples
    --------
    >>> from sklearn.datasets import load_breast_cancer
    >>> from sklearn.feature_selection import SelectFpr, chi2
    >>> X, y = load_breast_cancer(return_X_y=True)
    >>> X.shape
    (569, 30)
    >>> X_new = SelectFpr(chi2, alpha=0.01).fit_transform(X, y)
    >>> X_new.shape
    (569, 16)

    See also
    --------
    f_classif: ANOVA F-value between label/feature for classification tasks.
    chi2: Chi-squared stats of non-negative features for classification tasks.
    mutual_info_classif:
    f_regression: F-value between label/feature for regression tasks.
    mutual_info_regression: Mutual information between features and the target.
    SelectPercentile: Select features based on percentile of the highest scores.
    SelectKBest: Select features based on the k highest scores.
    SelectFdr: Select features based on an estimated false discovery rate.
    SelectFwe: Select features based on family-wise error rate.
    GenericUnivariateSelect: Univariate feature selector with configurable mode.
    gš™™™™™©?c         C   s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   R‚   R“   Rp   t   alpha(   Ro   Rn   R”   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRp   I  s    c         C   s   t  |  d ƒ |  j |  j k  S(   NRy   (   R   Rz   R”   (   Ro   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR   M  s    (   R~   R   R€   RE   Rp   R   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR“     s   2t	   SelectFdrc           B   s&   e  Z d  Z e d d „ Z d „  Z RS(   s»  Filter: Select the p-values for an estimated false discovery rate

    This uses the Benjamini-Hochberg procedure. ``alpha`` is an upper bound
    on the expected false discovery rate.

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

    Parameters
    ----------
    score_func : callable
        Function taking two arrays X and y, and returning a pair of arrays
        (scores, pvalues).
        Default is f_classif (see below "See also"). The default function only
        works with classification tasks.

    alpha : float, optional
        The highest uncorrected p-value for features to keep.

    Examples
    --------
    >>> from sklearn.datasets import load_breast_cancer
    >>> from sklearn.feature_selection import SelectFdr, chi2
    >>> X, y = load_breast_cancer(return_X_y=True)
    >>> X.shape
    (569, 30)
    >>> X_new = SelectFdr(chi2, alpha=0.01).fit_transform(X, y)
    >>> X_new.shape
    (569, 16)

    Attributes
    ----------
    scores_ : array-like, shape=(n_features,)
        Scores of features.

    pvalues_ : array-like, shape=(n_features,)
        p-values of feature scores.

    References
    ----------
    https://en.wikipedia.org/wiki/False_discovery_rate

    See also
    --------
    f_classif: ANOVA F-value between label/feature for classification tasks.
    mutual_info_classif: Mutual information for a discrete target.
    chi2: Chi-squared stats of non-negative features for classification tasks.
    f_regression: F-value between label/feature for regression tasks.
    mutual_info_regression: Mutual information for a contnuous target.
    SelectPercentile: Select features based on percentile of the highest scores.
    SelectKBest: Select features based on the k highest scores.
    SelectFpr: Select features based on a false positive rate test.
    SelectFwe: Select features based on family-wise error rate.
    GenericUnivariateSelect: Univariate feature selector with configurable mode.
    gš™™™™™©?c         C   s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   R‚   R•   Rp   R”   (   Ro   Rn   R”   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRp   ‹  s    c         C   s—   t  |  d ƒ t |  j ƒ } t j |  j ƒ } | | t |  j ƒ | t j d | d ƒ k } | j d k r„ t j	 |  j d t
 ƒS|  j | j ƒ  k S(   NRy   i   i    R   (   R   R   Rz   R   t   sortR   R”   t   arangeR#   t
   zeros_likeR…   t   max(   Ro   t
   n_featurest   svt   selected(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR     s    (   R~   R   R€   RE   Rp   R   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR•   S  s   6t	   SelectFwec           B   s&   e  Z d  Z e d d „ Z d „  Z RS(   sq  Filter: Select the p-values corresponding to Family-wise error rate

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

    Parameters
    ----------
    score_func : callable
        Function taking two arrays X and y, and returning a pair of arrays
        (scores, pvalues).
        Default is f_classif (see below "See also"). The default function only
        works with classification tasks.

    alpha : float, optional
        The highest uncorrected p-value for features to keep.

    Examples
    --------
    >>> from sklearn.datasets import load_breast_cancer
    >>> from sklearn.feature_selection import SelectFwe, chi2
    >>> X, y = load_breast_cancer(return_X_y=True)
    >>> X.shape
    (569, 30)
    >>> X_new = SelectFwe(chi2, alpha=0.01).fit_transform(X, y)
    >>> X_new.shape
    (569, 15)

    Attributes
    ----------
    scores_ : array-like, shape=(n_features,)
        Scores of features.

    pvalues_ : array-like, shape=(n_features,)
        p-values of feature scores.

    See also
    --------
    f_classif: ANOVA F-value between label/feature for classification tasks.
    chi2: Chi-squared stats of non-negative features for classification tasks.
    f_regression: F-value between label/feature for regression tasks.
    SelectPercentile: Select features based on percentile of the highest scores.
    SelectKBest: Select features based on the k highest scores.
    SelectFpr: Select features based on a false positive rate test.
    SelectFdr: Select features based on an estimated false discovery rate.
    GenericUnivariateSelect: Univariate feature selector with configurable mode.
    gš™™™™™©?c         C   s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   R‚   R   Rp   R”   (   Ro   Rn   R”   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRp   Ê  s    c         C   s*   t  |  d ƒ |  j |  j t |  j ƒ k  S(   NRy   (   R   Rz   R”   R   (   Ro   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR   Î  s    (   R~   R   R€   RE   Rp   R   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR   ›  s   -t   GenericUnivariateSelectc           B   sd   e  Z d  Z i e d 6e d 6e d 6e d 6e d 6Z e	 d d d „ Z
 d „  Z d	 „  Z d
 „  Z RS(   s•  Univariate feature selector with configurable strategy.

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

    Parameters
    ----------
    score_func : callable
        Function taking two arrays X and y, and returning a pair of arrays
        (scores, pvalues). For modes 'percentile' or 'kbest' it can return
        a single array scores.

    mode : {'percentile', 'k_best', 'fpr', 'fdr', 'fwe'}
        Feature selection mode.

    param : float or int depending on the feature selection mode
        Parameter of the corresponding mode.

    Attributes
    ----------
    scores_ : array-like, shape=(n_features,)
        Scores of features.

    pvalues_ : array-like, shape=(n_features,)
        p-values of feature scores, None if `score_func` returned scores only.

    Examples
    --------
    >>> from sklearn.datasets import load_breast_cancer
    >>> from sklearn.feature_selection import GenericUnivariateSelect, chi2
    >>> X, y = load_breast_cancer(return_X_y=True)
    >>> X.shape
    (569, 30)
    >>> transformer = GenericUnivariateSelect(chi2, 'k_best', param=20)
    >>> X_new = transformer.fit_transform(X, y)
    >>> X_new.shape
    (569, 20)

    See also
    --------
    f_classif: ANOVA F-value between label/feature for classification tasks.
    mutual_info_classif: Mutual information for a discrete target.
    chi2: Chi-squared stats of non-negative features for classification tasks.
    f_regression: F-value between label/feature for regression tasks.
    mutual_info_regression: Mutual information for a continuous target.
    SelectPercentile: Select features based on percentile of the highest scores.
    SelectKBest: Select features based on the k highest scores.
    SelectFpr: Select features based on a false positive rate test.
    SelectFdr: Select features based on an estimated false discovery rate.
    SelectFwe: Select features based on family-wise error rate.
    Rƒ   t   k_bestt   fprt   fdrt   fwegñhãˆµøä>c         C   s,   t  t |  ƒ j | ƒ | |  _ | |  _ d  S(   N(   R‚   Rž   Rp   t   modet   param(   Ro   Rn   R£   R¤   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRp     s    	c         C   sT   |  j  |  j d |  j ƒ } | j ƒ  } | j d ƒ | j i |  j | d 6  | S(   NRn   i    (   t   _selection_modesR£   Rn   t   _get_param_namest   removet
   set_paramsR¤   (   Ro   t   selectort   possible_params(    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   _make_selector  s
    c         C   s]   |  j  |  j k rC t d |  j j ƒ  |  j  t |  j  ƒ f ƒ ‚ n  |  j ƒ  j | | ƒ d  S(   Ns>   The mode passed should be one of %s, %r, (type %s) was passed.(   R£   R¥   RR   t   keysRt   R«   Ru   (   Ro   RC   RD   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRu   $  s
    c         C   s;   t  |  d ƒ |  j ƒ  } |  j | _ |  j | _ | j ƒ  S(   NRy   (   R   R«   Rz   Ry   R   (   Ro   R©   (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyR   -  s
    (   R~   R   R€   R   RŽ   R“   R•   R   R¥   RE   Rp   R«   Ru   R   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyRž   Ú  s   2

			('   R€   t   numpyR   R$   t   scipyR    R   t   scipy.sparseR   t   baseR   t   preprocessingR   t   utilsR   R   R   R   R	   t   utils.extmathR
   R   t   utils.validationR   R   R   R>   RE   RN   R^   R   Rl   Rm   R   RŽ   R“   R•   R   Rž   (    (    (    sM   lib/python2.7/site-packages/sklearn/feature_selection/univariate_selection.pyt   <module>   s.   (		P			;Q8SR>H?