ó
‡ˆ\c           @  sr  d  Z  d d l m 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 m Z m Z d d
 l m Z d d l m Z m Z m Z d d l m 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 g Z! e" d „ Z# d „  Z$ e" d „ Z% d e e e f d „  ƒ  YZ& d e e f d „  ƒ  YZ' d S(   sB   
Linear Discriminant Analysis and Quadratic Discriminant Analysis
iÿÿÿÿ(   t   print_functionNi   (   t
   deprecated(   t   linalg(   t   string_types(   t   xrange(   t   BaseEstimatort   TransformerMixint   ClassifierMixin(   t   LinearClassifierMixin(   t   ledoit_wolft   empirical_covariancet   shrunk_covariance(   t   unique_labels(   t   check_arrayt	   check_X_y(   t   check_is_fitted(   t   check_classification_targets(   t   StandardScalert   LinearDiscriminantAnalysist   QuadraticDiscriminantAnalysisc         C  s/  | d k r d n | } t | t ƒ rÂ | d k r˜ t ƒ  } | j |  ƒ }  t |  ƒ d } | j d d … t j f | | j t j d d … f } q+| d k r³ t	 |  ƒ } q+t
 d ƒ ‚ ni t | t ƒ sà t | t ƒ r| d k  sø | d k rt
 d ƒ ‚ n  t t	 |  ƒ | ƒ } n t d ƒ ‚ | S(	   s!  Estimate covariance matrix (using optional shrinkage).

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

    shrinkage : string or float, optional
        Shrinkage parameter, possible values:
          - None or 'empirical': no shrinkage (default).
          - 'auto': automatic shrinkage using the Ledoit-Wolf lemma.
          - float between 0 and 1: fixed shrinkage parameter.

    Returns
    -------
    s : array, shape (n_features, n_features)
        Estimated covariance matrix.
    t	   empiricalt   autoi    Ns   unknown shrinkage parameteri   s+   shrinkage parameter must be between 0 and 1s'   shrinkage must be of string or int type(   t   Nonet
   isinstanceR   R   t   fit_transformR	   t   scale_t   npt   newaxisR
   t
   ValueErrort   floatt   intR   t	   TypeError(   t   Xt	   shrinkaget   sct   s(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   _cov!   s     	=c         C  sƒ   t  j | d t ƒ\ } } t  j | ƒ } t  j d t | ƒ |  j d f ƒ } t  j j | | |  ƒ | | d d … d f :} | S(   s;  Compute class means.

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

    y : array-like, shape (n_samples,) or (n_samples, n_targets)
        Target values.

    Returns
    -------
    means : array-like, shape (n_classes, n_features)
        Class means.
    t   return_inverset   shapei   N(
   R   t   uniquet   Truet   bincountt   zerost   lenR&   t   addt   atR   (   R    t   yt   classest   cntt   means(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   _class_meansI   s    %c   	      C  s–   t  j | ƒ } t  j d |  j d |  j d f ƒ } xZ t | ƒ D]L \ } } |  | | k d d … f } | | | t  j t | | ƒ ƒ 7} qB W| S(   s›  Compute class covariance matrix.

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

    y : array-like, shape (n_samples,) or (n_samples, n_targets)
        Target values.

    priors : array-like, shape (n_classes,)
        Class priors.

    shrinkage : string or float, optional
        Shrinkage parameter, possible values:
          - None: no shrinkage (default).
          - 'auto': automatic shrinkage using the Ledoit-Wolf lemma.
          - float between 0 and 1: fixed shrinkage parameter.

    Returns
    -------
    cov : array-like, shape (n_features, n_features)
        Class covariance matrix.
    R&   i   N(   R   R'   R*   R&   t	   enumeratet
   atleast_2dR$   (	   R    R.   t   priorsR!   R/   t   covt   idxt   groupt   Xg(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt
   _class_cova   s    &(c           B  sh   e  Z d  Z d d d d e d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   sâ  Linear Discriminant Analysis

    A classifier with a linear decision boundary, generated by fitting class
    conditional densities to the data and using Bayes' rule.

    The model fits a Gaussian density to each class, assuming that all classes
    share the same covariance matrix.

    The fitted model can also be used to reduce the dimensionality of the input
    by projecting it to the most discriminative directions.

    .. versionadded:: 0.17
       *LinearDiscriminantAnalysis*.

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

    Parameters
    ----------
    solver : string, optional
        Solver to use, possible values:
          - 'svd': Singular value decomposition (default).
            Does not compute the covariance matrix, therefore this solver is
            recommended for data with a large number of features.
          - 'lsqr': Least squares solution, can be combined with shrinkage.
          - 'eigen': Eigenvalue decomposition, can be combined with shrinkage.

    shrinkage : string or float, optional
        Shrinkage parameter, possible values:
          - None: no shrinkage (default).
          - 'auto': automatic shrinkage using the Ledoit-Wolf lemma.
          - float between 0 and 1: fixed shrinkage parameter.

        Note that shrinkage works only with 'lsqr' and 'eigen' solvers.

    priors : array, optional, shape (n_classes,)
        Class priors.

    n_components : int, optional
        Number of components (< n_classes - 1) for dimensionality reduction.

    store_covariance : bool, optional
        Additionally compute class covariance matrix (default False), used
        only in 'svd' solver.

        .. versionadded:: 0.17

    tol : float, optional, (default 1.0e-4)
        Threshold used for rank estimation in SVD solver.

        .. versionadded:: 0.17

    Attributes
    ----------
    coef_ : array, shape (n_features,) or (n_classes, n_features)
        Weight vector(s).

    intercept_ : array, shape (n_features,)
        Intercept term.

    covariance_ : array-like, shape (n_features, n_features)
        Covariance matrix (shared by all classes).

    explained_variance_ratio_ : array, shape (n_components,)
        Percentage of variance explained by each of the selected components.
        If ``n_components`` is not set then all components are stored and the
        sum of explained variances is equal to 1.0. Only available when eigen
        or svd solver is used.

    means_ : array-like, shape (n_classes, n_features)
        Class means.

    priors_ : array-like, shape (n_classes,)
        Class priors (sum to 1).

    scalings_ : array-like, shape (rank, n_classes - 1)
        Scaling of the features in the space spanned by the class centroids.

    xbar_ : array-like, shape (n_features,)
        Overall mean.

    classes_ : array-like, shape (n_classes,)
        Unique class labels.

    See also
    --------
    sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis: Quadratic
        Discriminant Analysis

    Notes
    -----
    The default solver is 'svd'. It can perform both classification and
    transform, and it does not rely on the calculation of the covariance
    matrix. This can be an advantage in situations where the number of features
    is large. However, the 'svd' solver cannot be used with shrinkage.

    The 'lsqr' solver is an efficient algorithm that only works for
    classification. It supports shrinkage.

    The 'eigen' solver is based on the optimization of the between class
    scatter to within class scatter ratio. It can be used for both
    classification and transform, and it supports shrinkage. However, the
    'eigen' solver needs to compute the covariance matrix, so it might not be
    suitable for situations with a high number of features.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
    >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
    >>> y = np.array([1, 1, 1, 2, 2, 2])
    >>> clf = LinearDiscriminantAnalysis()
    >>> clf.fit(X, y)
    LinearDiscriminantAnalysis(n_components=None, priors=None, shrinkage=None,
                  solver='svd', store_covariance=False, tol=0.0001)
    >>> print(clf.predict([[-0.8, -1]]))
    [1]
    t   svdg-Cëâ6?c         C  s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   solverR!   R5   t   n_componentst   store_covariancet   tol(   t   selfR<   R!   R5   R=   R>   R?   (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   __init__ú   s    					c         C  s‘   t  | | ƒ |  _ t | | |  j | ƒ |  _ t j |  j |  j j ƒ d j |  _ d t	 j
 t	 j |  j |  j j ƒ ƒ t	 j |  j ƒ |  _ d S(   s¶  Least squares solver.

        The least squares solver computes a straightforward solution of the
        optimal decision rule based directly on the discriminant functions. It
        can only be used for classification (with optional shrinkage), because
        estimation of eigenvectors is not performed. Therefore, dimensionality
        reduction with the transform is not supported.

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

        y : array-like, shape (n_samples,) or (n_samples, n_classes)
            Target values.

        shrinkage : string or float, optional
            Shrinkage parameter, possible values:
              - None: no shrinkage (default).
              - 'auto': automatic shrinkage using the Ledoit-Wolf lemma.
              - float between 0 and 1: fixed shrinkage parameter.

        Notes
        -----
        This solver is based on [1]_, section 2.6.2, pp. 39-41.

        References
        ----------
        .. [1] R. O. Duda, P. E. Hart, D. G. Stork. Pattern Classification
           (Second Edition). John Wiley & Sons, Inc., New York, 2001. ISBN
           0-471-05669-3.
        i    g      à¿N(   R2   t   means_R:   t   priors_t   covariance_R   t   lstsqt   Tt   coef_R   t   diagt   dott   logt
   intercept_(   R@   R    R.   R!   (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   _solve_lsqr  s
    !%%c   	      C  sN  t  | | ƒ |  _ t | | |  j | ƒ |  _ |  j } t | | ƒ } | | } t j | | ƒ \ } } t j	 | t j
 | ƒ ƒ d d d … |  j  |  _ | d d … t j | ƒ d d d … f } | t j j | d d ƒ:} | |  _ t j |  j | ƒ j | j ƒ |  _ d t j t j |  j |  j j ƒ ƒ t j |  j ƒ |  _ d S(   s]  Eigenvalue solver.

        The eigenvalue solver computes the optimal solution of the Rayleigh
        coefficient (basically the ratio of between class scatter to within
        class scatter). This solver supports both classification and
        dimensionality reduction (with optional shrinkage).

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

        y : array-like, shape (n_samples,) or (n_samples, n_targets)
            Target values.

        shrinkage : string or float, optional
            Shrinkage parameter, possible values:
              - None: no shrinkage (default).
              - 'auto': automatic shrinkage using the Ledoit-Wolf lemma.
              - float between 0 and 1: fixed shrinkage constant.

        Notes
        -----
        This solver is based on [1]_, section 3.8.3, pp. 121-124.

        References
        ----------
        .. [1] R. O. Duda, P. E. Hart, D. G. Stork. Pattern Classification
           (Second Edition). John Wiley & Sons, Inc., New York, 2001. ISBN
           0-471-05669-3.
        Niÿÿÿÿt   axisi    g      à¿(   R2   RB   R:   RC   RD   R$   R   t   eighR   t   sortt   sumt   _max_componentst   explained_variance_ratio_t   argsortt   normt	   scalings_RI   RF   RG   RH   RJ   RK   (	   R@   R    R.   R!   t   Swt   Stt   Sbt   evalst   evecs(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   _solve_eigen*  s     	
,	$%c         C  sí  | j  \ } } t |  j ƒ } t | | ƒ |  _ |  j rT t | | |  j ƒ |  _ n  g  } xQ t	 |  j ƒ D]@ \ } } | | | k d d … f }	 | j
 |	 |  j | ƒ qj Wt j |  j |  j ƒ |  _ t j | d d ƒ} | j d d ƒ }
 d |
 |
 d k <d | | } t j | ƒ | |
 } t j | d t ƒ\ } } } t j | |  j k ƒ } | | k  rwt j d ƒ n  | |  |
 j | |  } t j t j | |  j | ƒ |  j |  j j j | ƒ } t j | d d ƒ\ } } } | d t j | d ƒ |  j  |  _ t j | |  j | d k ƒ } t j | | j d d … d | … f ƒ |  _ t j |  j |  j |  j ƒ } d t j | d d d	 ƒt j |  j ƒ |  _ t j | |  j j ƒ |  _ |  j t j |  j |  j j ƒ 8_ d S(
   sí   SVD solver.

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

        y : array-like, shape (n_samples,) or (n_samples, n_targets)
            Target values.
        NRM   i    g      ð?t   full_matricess   Variables are collinear.i   g      à¿i   (   R&   R+   t   classes_R2   RB   R>   R:   RC   RD   R3   t   appendR   RI   t   xbar_t   concatenatet   stdt   sqrtR   R;   t   FalseRP   R?   t   warningst   warnRF   RQ   RR   RU   RJ   RK   RG   (   R@   R    R.   t	   n_samplest
   n_featurest	   n_classest   XcR7   R8   R9   Ra   t   fact   Ut   St   Vt   rankt   scalingst   _t   coef(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt
   _solve_svd\  s@    	 .c         C  sµ  t  | | d d d |  ƒ\ } } t | ƒ |  _ | j \ } } t |  j ƒ } | | k ri t d ƒ ‚ n  |  j d k r¸ t j	 | d t
 ƒ\ } } t j | ƒ t t | ƒ ƒ |  _ n t j |  j ƒ |  _ |  j d k  j ƒ  rñ t d ƒ ‚ n  t j |  j j ƒ  d ƒ s8t j d	 t ƒ |  j |  j j ƒ  |  _ n  |  j d k r`t |  j ƒ d
 |  _ n" t t |  j ƒ d
 |  j ƒ |  _ |  j d k rÂ|  j d k	 r¯t d ƒ ‚ n  |  j | | ƒ nn |  j d k rí|  j | | d |  j ƒnC |  j d k r|  j | | d |  j ƒn t d j |  j ƒ ƒ ‚ |  j j d k r±t j  |  j! d
 d d … f |  j! d d d … f d d ƒ|  _! t j  |  j" d
 |  j" d d d
 ƒ|  _" n  |  S(   sî  Fit LinearDiscriminantAnalysis model according to the given
           training data and parameters.

           .. versionchanged:: 0.19
              *store_covariance* has been moved to main constructor.

           .. versionchanged:: 0.19
              *tol* has been moved to main constructor.

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

        y : array, shape (n_samples,)
            Target values.
        t   ensure_min_samplesi   t	   estimators>   The number of samples must be more than the number of classes.R%   i    s   priors must be non-negativeg      ð?s)   The priors do not sum to 1. Renormalizingi   R;   s   shrinkage not supportedt   lsqrR!   t   eigensA   unknown solver {} (valid solvers are 'svd', 'lsqr', and 'eigen').Nt   ndmin(#   R   R   R]   R&   R+   R   R5   R   R   R'   R(   R)   R   RC   t   asarrayt   anyt   iscloseRP   Rd   Re   t   UserWarningR=   RQ   t   minR<   R!   t   NotImplementedErrorRr   RL   R[   t   formatt   sizet   arrayRG   RK   (   R@   R    R.   Rf   Rp   Rh   t   y_t(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   fit›  sF    !%		Bc         C  sµ   |  j  d k r t d ƒ ‚ n  t |  d d g d t ƒt | ƒ } |  j  d k rq t j | |  j |  j ƒ } n' |  j  d k r˜ t j | |  j ƒ } n  | d d … d |  j	 … f S(	   s  Project data to maximize class separation.

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

        Returns
        -------
        X_new : array, shape (n_samples, n_components)
            Transformed data.
        Ru   sC   transform not implemented for 'lsqr' solver (use 'svd' or 'eigen').R_   RU   t
   all_or_anyR;   Rv   N(
   R<   R}   R   Ry   R   R   RI   R_   RU   RQ   (   R@   R    t   X_new(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt	   transformÛ  s    c         C  s£   |  j  | ƒ } | d 9} t j | | ƒ | d 7} t j | | ƒ t |  j ƒ d k ro t j d | | g ƒ S| | j d d ƒ j | j	 d d f ƒ :} | Sd S(   s	  Estimate probability.

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

        Returns
        -------
        C : array, shape (n_samples, n_classes)
            Estimated probabilities.
        iÿÿÿÿi   i   RM   i    N(
   t   decision_functionR   t   expt
   reciprocalR+   R]   t   column_stackRP   t   reshapeR&   (   R@   R    t   prob(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   predict_probaõ  s    

,c         C  s   t  j |  j | ƒ ƒ S(   s  Estimate log probability.

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

        Returns
        -------
        C : array, shape (n_samples, n_classes)
            Estimated log probabilities.
        (   R   RJ   RŒ   (   R@   R    (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   predict_log_proba  s    N(   t   __name__t
   __module__t   __doc__R   Rc   RA   RL   R[   Rr   R‚   R…   RŒ   R   (    (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyR   ‚   s   v		'	2	?	@		c           B  sw   e  Z d  Z d d e d d d „ Z e e d ƒ d „  ƒ ƒ Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z RS(   sÃ	  Quadratic Discriminant Analysis

    A classifier with a quadratic decision boundary, generated
    by fitting class conditional densities to the data
    and using Bayes' rule.

    The model fits a Gaussian density to each class.

    .. versionadded:: 0.17
       *QuadraticDiscriminantAnalysis*

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

    Parameters
    ----------
    priors : array, optional, shape = [n_classes]
        Priors on classes

    reg_param : float, optional
        Regularizes the covariance estimate as
        ``(1-reg_param)*Sigma + reg_param*np.eye(n_features)``

    store_covariance : boolean
        If True the covariance matrices are computed and stored in the
        `self.covariance_` attribute.

        .. versionadded:: 0.17

    tol : float, optional, default 1.0e-4
        Threshold used for rank estimation.

        .. versionadded:: 0.17

    store_covariances : boolean
        Deprecated, use `store_covariance`.

    Attributes
    ----------
    covariance_ : list of array-like, shape = [n_features, n_features]
        Covariance matrices of each class.

    means_ : array-like, shape = [n_classes, n_features]
        Class means.

    priors_ : array-like, shape = [n_classes]
        Class priors (sum to 1).

    rotations_ : list of arrays
        For each class k an array of shape [n_features, n_k], with
        ``n_k = min(n_features, number of elements in class k)``
        It is the rotation of the Gaussian distribution, i.e. its
        principal axis.

    scalings_ : list of arrays
        For each class k an array of shape [n_k]. It contains the scaling
        of the Gaussian distributions along its principal axes, i.e. the
        variance in the rotated coordinate system.

    Examples
    --------
    >>> from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
    >>> import numpy as np
    >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
    >>> y = np.array([1, 1, 1, 2, 2, 2])
    >>> clf = QuadraticDiscriminantAnalysis()
    >>> clf.fit(X, y)
    ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
    QuadraticDiscriminantAnalysis(priors=None, reg_param=0.0,
                                  store_covariance=False,
                                  store_covariances=None, tol=0.0001)
    >>> print(clf.predict([[-0.8, -1]]))
    [1]

    See also
    --------
    sklearn.discriminant_analysis.LinearDiscriminantAnalysis: Linear
        Discriminant Analysis
    g        g-Cëâ6?c         C  sL   | d  k	 r t j | ƒ n d  |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   R   Rx   R5   t	   reg_paramt   store_covariancesR>   R?   (   R@   R5   R‘   R>   R?   R’   (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyRA   n  s
    $			sr   Attribute ``covariances_`` was deprecated in version 0.19 and will be removed in 0.21. Use ``covariance_`` insteadc         C  s   |  j  S(   N(   RD   (   R@   (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   covariances_v  s    c         C  s«  t  | | ƒ \ } } t | ƒ t j | d t ƒ\ |  _ } | j \ } } t |  j ƒ } | d k  rz t d | ƒ ‚ n  |  j	 d k r¨ t j | ƒ t | ƒ |  _ n |  j	 |  _ d } |  j pÉ |  j } |  j rè t j d t ƒ n  | r÷ g  } n  g  } g  }	 g  }
 x\t | ƒ D]N} | | | k d d … f } | j d ƒ } | j | ƒ t | ƒ d k r†t d t |  j | ƒ ƒ ‚ n  | | } t j j | d	 t ƒ\ } } } t j | |  j k ƒ } | | k  råt j d
 ƒ n  | d t | ƒ d } d |  j | |  j } |  j s$| rG| j t j | | j | ƒ ƒ n  |	 j | ƒ |
 j | j ƒ qW|  j sw| rƒ| |  _ n  t j  | ƒ |  _! |	 |  _" |
 |  _# |  S(   si  Fit the model according to the given training data and parameters.

            .. versionchanged:: 0.19
               ``store_covariances`` has been moved to main constructor as
               ``store_covariance``

            .. versionchanged:: 0.19
               ``tol`` has been moved to main constructor.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
            Training vector, where n_samples is the number of samples and
            n_features is the number of features.

        y : array, shape = [n_samples]
            Target values (integers)
        R%   i   s>   The number of classes has to be greater than one; got %d classs`   'store_covariances' was renamed to store_covariance in version 0.19 and will be removed in 0.21.Ni    i   s;   y has only 1 sample in class %s, covariance is ill defined.R\   s   Variables are collinear($   R   R   R   R'   R(   R]   R&   R+   R   R5   R   R)   R   RC   R>   R’   Rd   Re   t   DeprecationWarningR   t   meanR^   t   strR   R;   Rc   RP   R?   R‘   RI   RF   RD   Rx   RB   RU   t
   rotations_(   R@   R    R.   Rf   Rg   Rh   R6   R>   R1   Ro   t	   rotationst   indR9   t   meangt   XgcRk   Rl   t   VtRn   t   S2(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyR‚   }  sZ    
		
	
!#		c   
      C  s  t  |  d ƒ t | ƒ } g  } x t t |  j ƒ ƒ D]h } |  j | } |  j | } | |  j | } t j	 | | | d ƒ } | j
 t j | d d ƒ ƒ q5 Wt j | ƒ j } t j g  |  j D] } t j t j | ƒ ƒ ^ qÃ ƒ }	 d | |	 t j |  j ƒ S(   NR]   g      à¿i   i   (   R   R   t   rangeR+   R]   R—   RU   RB   R   RI   R^   RP   R€   RF   Rx   RJ   RC   (
   R@   R    t   norm2t   it   RRl   t   Xmt   X2R#   t   u(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   _decision_functionÃ  s    !7c         C  sP   |  j  | ƒ } t |  j ƒ d k rL | d d … d f | d d … d f S| S(   sð  Apply decision function to an array of samples.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
            Array of samples (test vectors).

        Returns
        -------
        C : array, shape = [n_samples, n_classes] or [n_samples,]
            Decision function values related to each class, per sample.
            In the two-class case, the shape is [n_samples,], giving the
            log likelihood ratio of the positive class.
        i   Ni   i    (   R¥   R+   R]   (   R@   R    t   dec_func(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyR†   Ò  s    (c         C  s.   |  j  | ƒ } |  j j | j d ƒ ƒ } | S(   s&  Perform classification on an array of test vectors X.

        The predicted class C for each sample in X is returned.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]

        Returns
        -------
        C : array, shape = [n_samples]
        i   (   R¥   R]   t   taket   argmax(   R@   R    t   dt   y_pred(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   predictç  s    c         C  sh   |  j  | ƒ } t j | | j d d ƒ d d … t j f ƒ } | | j d d ƒ d d … t j f S(   sX  Return posterior probabilities of classification.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
            Array of samples/test vectors.

        Returns
        -------
        C : array, shape = [n_samples, n_classes]
            Posterior probabilities of classification per class.
        RM   i   N(   R¥   R   R‡   t   maxR   RP   (   R@   R    t   valuest
   likelihood(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyRŒ   ø  s    2c         C  s   |  j  | ƒ } t j | ƒ S(   s\  Return posterior probabilities of classification.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
            Array of samples/test vectors.

        Returns
        -------
        C : array, shape = [n_samples, n_classes]
            Posterior log-probabilities of classification per class.
        (   RŒ   R   RJ   (   R@   R    t   probas_(    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyR     s    N(   RŽ   R   R   R   Rc   RA   t   propertyR   R“   R‚   R¥   R†   R«   RŒ   R   (    (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyR     s   N		F				((   R   t
   __future__R    Rd   t   numpyR   t   utilsR   t   scipyR   t   externals.sixR   t   externals.six.movesR   t   baseR   R   R   t   linear_model.baseR   t
   covarianceR	   R
   R   t   utils.multiclassR   R   R   t   utils.validationR   R   t   preprocessingR   t   __all__R   R$   R2   R:   R   R   (    (    (    s<   lib/python2.7/site-packages/sklearn/discriminant_analysis.pyt   <module>   s.   	(	!	ÿ œ