ó
‡ˆ\c           @  sÑ  d  Z  d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l	 Z
 d d l j Z d d l m Z 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 m Z d d l 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 d d d d g Z+ d d d d d d d d d e- d d „ Z. d d d d d d d d d d „	 Z/ e- e- e- e- e- d d  „ Z0 e- d! „ Z1 d" „  Z2 d d d d d d d d# d$ „ Z3 d% „  Z4 d& „  Z5 d' „  Z6 d d d( d d d d d) „ Z7 d* „  Z8 d+ „  Z9 d e
 j: d, d- d. ƒ d d e- d d/ d e- d d d0 „ Z; d1 „  Z< d2 „  Z= d d d d d/ d d d3 „ Z> d4 „  Z? d S(5   sm   
The :mod:`sklearn.model_selection._validation` module includes classes and
functions to validate the model.
iÿÿÿÿ(   t   print_function(   t   divisionN(   t   format_exception_onlyi   (   t   is_classifiert   clone(   t	   indexablet   check_random_statet   safe_indexing(   t   DeprecationDict(   t   _is_arrayliket   _num_samples(   t   _safe_split(   t   Parallelt   delayed(   t   logger(   t   zip(   t   check_scoringt   _check_multimetric_scoring(   t   FitFailedWarningi   (   t   check_cv(   t   LabelEncodert   cross_validatet   cross_val_scoret   cross_val_predictt   permutation_test_scoret   learning_curvet   validation_curvet   warni    s   2*n_jobss   raise-deprecatingc      
     sñ  t  ˆ  ˆ | ƒ \ ‰  ‰ } t | ˆ d t ˆ ƒ ƒ} t ˆ d | ƒ\ ‰ } t d | d ˆ d |	 ƒ } | ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ f	 d †  | j ˆ  ˆ | ƒ Dƒ ƒ } t t | Œ  ƒ } ˆ râ | j d ƒ } t	 | ƒ } n  ˆ r÷ | j ƒ  } n  | \ } } } t	 | ƒ } ˆ d k r't
 ƒ  n i  } t j | ƒ | d	 <t j | ƒ | d
 <ˆ rf| | d <n  x„ ˆ D]| } t j | | ƒ | d | <ˆ rmd | } t j | | ƒ | | <ˆ d k réd j | ƒ } | j | | t ƒ qéqmqmW| S(   sè  Evaluate metric(s) by cross-validation and also record fit/score times.

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

    Parameters
    ----------
    estimator : estimator object implementing 'fit'
        The object to use to fit the data.

    X : array-like
        The data to fit. Can be for example a list, or an array.

    y : array-like, optional, default: None
        The target variable to try to predict in the case of
        supervised learning.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    scoring : string, callable, list/tuple, dict or None, default: None
        A single string (see :ref:`scoring_parameter`) or a callable
        (see :ref:`scoring`) to evaluate the predictions on the test set.

        For evaluating multiple metrics, either give a list of (unique) strings
        or a dict with names as keys and callables as values.

        NOTE that when using custom scorers, each scorer should return a single
        value. Metric functions returning a list/array of values can be wrapped
        into multiple scorers that return one value each.

        See :ref:`multimetric_grid_search` for an example.

        If None, the estimator's default scorer (if available) is used.

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-fold cross validation,
        - integer, to specify the number of folds in a `(Stratified)KFold`,
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if the estimator is a classifier and ``y`` is
        either binary or multiclass, :class:`StratifiedKFold` is used. In all
        other cases, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.20
            ``cv`` default value if None will change from 3-fold to 5-fold
            in v0.22.

    n_jobs : int or None, optional (default=None)
        The number of CPUs to use to do the computation.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    verbose : integer, optional
        The verbosity level.

    fit_params : dict, optional
        Parameters to pass to the fit method of the estimator.

    pre_dispatch : int, or string, optional
        Controls the number of jobs that get dispatched during parallel
        execution. Reducing this number can be useful to avoid an
        explosion of memory consumption when more jobs get dispatched
        than CPUs can process. This parameter can be:

            - None, in which case all the jobs are immediately
              created and spawned. Use this for lightweight and
              fast-running jobs, to avoid delays due to on-demand
              spawning of the jobs

            - An int, giving the exact number of total jobs that are
              spawned

            - A string, giving an expression as a function of n_jobs,
              as in '2*n_jobs'

    return_train_score : boolean, optional
        Whether to include train scores.

        Current default is ``'warn'``, which behaves as ``True`` in addition
        to raising a warning when a training score is looked up.
        That default will be changed to ``False`` in 0.21.
        Computing training scores is used to get insights on how different
        parameter settings impact the overfitting/underfitting trade-off.
        However computing the scores on the training set can be computationally
        expensive and is not strictly required to select the parameters that
        yield the best generalization performance.

    return_estimator : boolean, default False
        Whether to return the estimators fitted on each split.

    error_score : 'raise' | 'raise-deprecating' or numeric
        Value to assign to the score if an error occurs in estimator fitting.
        If set to 'raise', the error is raised.
        If set to 'raise-deprecating', a FutureWarning is printed before the
        error is raised.
        If a numeric value is given, FitFailedWarning is raised. This parameter
        does not affect the refit step, which will always raise the error.
        Default is 'raise-deprecating' but from version 0.22 it will change
        to np.nan.

    Returns
    -------
    scores : dict of float arrays of shape=(n_splits,)
        Array of scores of the estimator for each run of the cross validation.

        A dict of arrays containing the score/time arrays for each scorer is
        returned. The possible keys for this ``dict`` are:

            ``test_score``
                The score array for test scores on each cv split.
            ``train_score``
                The score array for train scores on each cv split.
                This is available only if ``return_train_score`` parameter
                is ``True``.
            ``fit_time``
                The time for fitting the estimator on the train
                set for each cv split.
            ``score_time``
                The time for scoring the estimator on the test set for each
                cv split. (Note time for scoring on the train set is not
                included even if ``return_train_score`` is set to ``True``
            ``estimator``
                The estimator objects for each cv split.
                This is available only if ``return_estimator`` parameter
                is set to ``True``.

    Examples
    --------
    >>> from sklearn import datasets, linear_model
    >>> from sklearn.model_selection import cross_validate
    >>> from sklearn.metrics.scorer import make_scorer
    >>> from sklearn.metrics import confusion_matrix
    >>> from sklearn.svm import LinearSVC
    >>> diabetes = datasets.load_diabetes()
    >>> X = diabetes.data[:150]
    >>> y = diabetes.target[:150]
    >>> lasso = linear_model.Lasso()

    Single metric evaluation using ``cross_validate``

    >>> cv_results = cross_validate(lasso, X, y, cv=3,
    ...                             return_train_score=False)
    >>> sorted(cv_results.keys())                         # doctest: +ELLIPSIS
    ['fit_time', 'score_time', 'test_score']
    >>> cv_results['test_score']    # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    array([0.33150734, 0.08022311, 0.03531764])

    Multiple metric evaluation using ``cross_validate``
    (please refer the ``scoring`` parameter doc for more information)

    >>> scores = cross_validate(lasso, X, y, cv=3,
    ...                         scoring=('r2', 'neg_mean_squared_error'),
    ...                         return_train_score=True)
    >>> print(scores['test_neg_mean_squared_error'])      # doctest: +ELLIPSIS
    [-3635.5... -3573.3... -6114.7...]
    >>> print(scores['train_r2'])                         # doctest: +ELLIPSIS
    [0.28010158 0.39088426 0.22784852]

    See Also
    ---------
    :func:`sklearn.model_selection.cross_val_score`:
        Run cross-validation for single metric evaluation.

    :func:`sklearn.model_selection.cross_val_predict`:
        Get predictions from each split of cross-validation for diagnostic
        purposes.

    :func:`sklearn.metrics.make_scorer`:
        Make a scorer from a performance metric or loss function.

    t
   classifiert   scoringt   n_jobst   verboset   pre_dispatchc         3  s]   |  ]S \ } } t  t ƒ t ˆ ƒ ˆ  ˆ ˆ | | ˆ d ˆ d  ˆ d t d ˆ d ˆ ƒ	Vq d S(   t   return_train_scoret   return_timest   return_estimatort   error_scoreN(   R   t   _fit_and_scoreR   t   Nonet   True(   t   .0t   traint   test(	   t   XR$   t	   estimatort
   fit_paramsR#   R!   t   scorersR   t   y(    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>ë   s   i    R   t   fit_timet
   score_timeR,   s   test_%ss   train_%ss£   You are accessing a training score ({!r}), which will not be available by default any more in 0.21. If you need training scores, please set return_train_score=True(   R   R   R   R   R   t   splitt   listR   t   popt   _aggregate_score_dictsR   t   npt   arrayt   formatt   add_warningt   FutureWarning(   R,   R+   R/   t   groupsR   t   cvR   R   R-   R    R!   R#   R$   t   _t   parallelt   scorest   zipped_scorest   train_scorest   fitted_estimatorst   test_scorest	   fit_timest   score_timest   rett   namet   keyt   message(    (	   R+   R$   R,   R-   R#   R!   R.   R   R/   sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR   )   s>    ¸	$
	c         C  sr   t  |  d | ƒ} t d |  d | d | d | d i | d 6d | d t d	 | d
 | d | d |	 d |
 ƒ } | d S(   s:  Evaluate a score by cross-validation

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

    Parameters
    ----------
    estimator : estimator object implementing 'fit'
        The object to use to fit the data.

    X : array-like
        The data to fit. Can be for example a list, or an array.

    y : array-like, optional, default: None
        The target variable to try to predict in the case of
        supervised learning.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    scoring : string, callable or None, optional, default: None
        A string (see model evaluation documentation) or
        a scorer callable object / function with signature
        ``scorer(estimator, X, y)``.

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-fold cross validation,
        - integer, to specify the number of folds in a `(Stratified)KFold`,
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if the estimator is a classifier and ``y`` is
        either binary or multiclass, :class:`StratifiedKFold` is used. In all
        other cases, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.20
            ``cv`` default value if None will change from 3-fold to 5-fold
            in v0.22.

    n_jobs : int or None, optional (default=None)
        The number of CPUs to use to do the computation.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    verbose : integer, optional
        The verbosity level.

    fit_params : dict, optional
        Parameters to pass to the fit method of the estimator.

    pre_dispatch : int, or string, optional
        Controls the number of jobs that get dispatched during parallel
        execution. Reducing this number can be useful to avoid an
        explosion of memory consumption when more jobs get dispatched
        than CPUs can process. This parameter can be:

            - None, in which case all the jobs are immediately
              created and spawned. Use this for lightweight and
              fast-running jobs, to avoid delays due to on-demand
              spawning of the jobs

            - An int, giving the exact number of total jobs that are
              spawned

            - A string, giving an expression as a function of n_jobs,
              as in '2*n_jobs'

    error_score : 'raise' | 'raise-deprecating' or numeric
        Value to assign to the score if an error occurs in estimator fitting.
        If set to 'raise', the error is raised.
        If set to 'raise-deprecating', a FutureWarning is printed before the
        error is raised.
        If a numeric value is given, FitFailedWarning is raised. This parameter
        does not affect the refit step, which will always raise the error.
        Default is 'raise-deprecating' but from version 0.22 it will change
        to np.nan.

    Returns
    -------
    scores : array of float, shape=(len(list(cv)),)
        Array of scores of the estimator for each run of the cross validation.

    Examples
    --------
    >>> from sklearn import datasets, linear_model
    >>> from sklearn.model_selection import cross_val_score
    >>> diabetes = datasets.load_diabetes()
    >>> X = diabetes.data[:150]
    >>> y = diabetes.target[:150]
    >>> lasso = linear_model.Lasso()
    >>> print(cross_val_score(lasso, X, y, cv=3))  # doctest: +ELLIPSIS
    [0.33150734 0.08022311 0.03531764]

    See Also
    ---------
    :func:`sklearn.model_selection.cross_validate`:
        To run cross-validation on multiple metrics and also to return
        train scores, fit times and score times.

    :func:`sklearn.model_selection.cross_val_predict`:
        Get predictions from each split of cross-validation for diagnostic
        purposes.

    :func:`sklearn.metrics.make_scorer`:
        Make a scorer from a performance metric or loss function.

    R   R,   R+   R/   R;   t   scoreR<   R!   R   R   R-   R    R$   t
   test_score(   R   R   t   False(   R,   R+   R/   R;   R   R<   R   R   R-   R    R$   t   scorert
   cv_results(    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR     s    v	c   #      C  s*  | d k ri | d k r! d } n# d d j d „  | j ƒ  Dƒ ƒ } t d | d t | ƒ d f ƒ n  | d k	 r{ | n i  } t g  | j ƒ  D]$ \ } } | t | | | ƒ f ^ q‘ ƒ } i  } | d k	 rà |  j |   n  t j ƒ  } t	 |  | | | ƒ \ } } t	 |  | | | | ƒ \ } } t
 | ƒ } | rJt | j ƒ  ƒ n d } y6 | d k rr|  j | |  n |  j | | |  Wnt k
 rž} t j ƒ  | } d	 } | d
 k rÀ‚  qü| d k rât j d t ƒ ‚  qüt | t j ƒ r| rJt t | j ƒ  | g | ƒ ƒ } |	 r_t t | j ƒ  | g | ƒ ƒ } q_n | } |	 r_| } n  t j d | t t | ƒ | ƒ d f t ƒ qüt d ƒ ‚ n^ Xt j ƒ  | } t |  | | | | ƒ } t j ƒ  | | } |	 rüt |  | | | | ƒ } n  | d k rS| rBx? | j ƒ  D]  \ } } | d | | f 7} qWqS| d | 7} n  | d k r§| | }  d | t j |  ƒ f }! t d d t |! ƒ d |! f ƒ n  |	 r¹| | g n | g }" | rÞ|" j t | ƒ ƒ n  | rú|" j | | g ƒ n  |
 r|" j | ƒ n  | r&|" j |  ƒ n  |" S(   sg  Fit estimator and compute scores for a given dataset split.

    Parameters
    ----------
    estimator : estimator object implementing 'fit'
        The object to use to fit the data.

    X : array-like of shape at least 2D
        The data to fit.

    y : array-like, optional, default: None
        The target variable to try to predict in the case of
        supervised learning.

    scorer : A single callable or dict mapping scorer name to the callable
        If it is a single callable, the return value for ``train_scores`` and
        ``test_scores`` is a single float.

        For a dict, it should be one mapping the scorer name to the scorer
        callable object / function.

        The callable object / fn should have signature
        ``scorer(estimator, X, y)``.

    train : array-like, shape (n_train_samples,)
        Indices of training samples.

    test : array-like, shape (n_test_samples,)
        Indices of test samples.

    verbose : integer
        The verbosity level.

    error_score : 'raise' | 'raise-deprecating' or numeric
        Value to assign to the score if an error occurs in estimator fitting.
        If set to 'raise', the error is raised.
        If set to 'raise-deprecating', a FutureWarning is printed before the
        error is raised.
        If a numeric value is given, FitFailedWarning is raised. This parameter
        does not affect the refit step, which will always raise the error.
        Default is 'raise-deprecating' but from version 0.22 it will change
        to np.nan.

    parameters : dict or None
        Parameters to be set on the estimator.

    fit_params : dict or None
        Parameters that will be passed to ``estimator.fit``.

    return_train_score : boolean, optional, default: False
        Compute and return score on training set.

    return_parameters : boolean, optional, default: False
        Return parameters that has been used for the estimator.

    return_n_test_samples : boolean, optional, default: False
        Whether to return the ``n_test_samples``

    return_times : boolean, optional, default: False
        Whether to return the fit/score times.

    return_estimator : boolean, optional, default: False
        Whether to return the fitted estimator.

    Returns
    -------
    train_scores : dict of scorer name -> float, optional
        Score on training set (for all the scorers),
        returned only if `return_train_score` is `True`.

    test_scores : dict of scorer name -> float, optional
        Score on testing set (for all the scorers).

    n_test_samples : int
        Number of test samples.

    fit_time : float
        Time spent for fitting in seconds.

    score_time : float
        Time spent for scoring in seconds.

    parameters : dict or None, optional
        The parameters that have been evaluated.

    estimator : estimator object
        The fitted estimator
    i   t    s   %ss   , c         s  s%   |  ] \ } } d  | | f Vq d S(   s   %s=%sN(    (   R(   t   kt   v(    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>÷  s   s
   [CV] %s %si@   t   .g        t   raises   raise-deprecatingsÖ   From version 0.22, errors during fit will result in a cross validation score of NaN by default. Use error_score='raise' if you want an exception raised or error_score=np.nan to adopt the behavior from version 0.22.sq   Estimator fit failed. The score on this train-test partition for these parameters will be set to %f. Details: 
%si    s‰   error_score must be the string 'raise' or a numeric value. (Hint: if using 'raise', please make sure that it has been spelled correctly.)i   s   , %s=%ss
   , score=%ss   %s, total=%sN(   R&   t   joint   itemst   printt   lent   dictt   _index_param_valuet
   set_paramst   timeR   t   callablet   keyst   fitt	   Exceptiont   warningsR   R:   t
   isinstancet   numberst   NumberR   R   t   typeR   t
   ValueErrort   _scoreR   t   short_format_timet   appendR
   t   extend(#   R,   R+   R/   RM   R)   R*   R   t
   parametersR-   R!   t   return_parameterst   return_n_test_samplesR"   R#   R$   t   msgRP   RQ   RA   t
   start_timet   X_traint   y_traint   X_testt   y_testt   is_multimetrict	   n_scorerst   eR0   R1   RC   t   scorer_nameRJ   t
   total_timet   end_msgRF   (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR%   –  sŠ    ]	%7			

%c         C  s½   | r t  |  | | | ƒ S| d k r7 | |  | ƒ } n | |  | | ƒ } t | d ƒ r y | j ƒ  } Wq t k
 r{ q Xn  t | t j ƒ s¹ t d t | ƒ t	 | ƒ | f ƒ ‚ n  | S(   s­   Compute the score(s) of an estimator on a given test set.

    Will return a single float if is_multimetric is False and a dict of floats,
    if is_multimetric is True
    t   items>   scoring must return a number, got %s (%s) instead. (scorer=%r)N(
   t   _multimetric_scoreR&   t   hasattrRy   Re   Ra   Rb   Rc   t   strRd   (   R,   Rq   Rr   RM   Rs   RJ   (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyRf   V  s    "c         C  sÑ   i  } xÄ | j  ƒ  D]¶ \ } } | d k r= | |  | ƒ } n | |  | | ƒ } t | d ƒ r… y | j ƒ  } Wq… t k
 r q… Xn  | | | <t | t j ƒ s t d t | ƒ t	 | ƒ | f ƒ ‚ q q W| S(   s.   Return a dict of score for multimetric scoringRy   s>   scoring must return a number, got %s (%s) instead. (scorer=%s)N(
   RU   R&   R{   Ry   Re   Ra   Rb   Rc   R|   Rd   (   R,   Rq   Rr   R.   R?   RG   RM   RJ   (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyRz   s  s    
&t   predictc
           sš  t  ˆ  ˆ | ƒ \ ‰  ‰ } t | ˆ d t ˆ ƒ ƒ} ˆ d k r] t ƒ  }
 |
 j ˆ ƒ ‰ n  t d | d ˆ d | ƒ } | ‡  ‡ ‡ ‡ ‡ ‡ f d †  | j ˆ  ˆ | ƒ Dƒ ƒ } g  | D] \ } } | ^ q¹ } t j g  | D] \ } } | ^ qÞ ƒ } t	 | t
 ˆ  ƒ ƒ st d	 ƒ ‚ n  t j t | ƒ d
 t ƒ} t j t | ƒ ƒ | | <t j | d ƒ rƒt j | d | d j ƒ} n t j | ƒ } | | S(   s  Generate cross-validated estimates for each input data point

    It is not appropriate to pass these predictions into an evaluation
    metric. Use :func:`cross_validate` to measure generalization error.

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

    Parameters
    ----------
    estimator : estimator object implementing 'fit' and 'predict'
        The object to use to fit the data.

    X : array-like
        The data to fit. Can be, for example a list, or an array at least 2d.

    y : array-like, optional, default: None
        The target variable to try to predict in the case of
        supervised learning.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-fold cross validation,
        - integer, to specify the number of folds in a `(Stratified)KFold`,
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if the estimator is a classifier and ``y`` is
        either binary or multiclass, :class:`StratifiedKFold` is used. In all
        other cases, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.20
            ``cv`` default value if None will change from 3-fold to 5-fold
            in v0.22.

    n_jobs : int or None, optional (default=None)
        The number of CPUs to use to do the computation.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    verbose : integer, optional
        The verbosity level.

    fit_params : dict, optional
        Parameters to pass to the fit method of the estimator.

    pre_dispatch : int, or string, optional
        Controls the number of jobs that get dispatched during parallel
        execution. Reducing this number can be useful to avoid an
        explosion of memory consumption when more jobs get dispatched
        than CPUs can process. This parameter can be:

            - None, in which case all the jobs are immediately
              created and spawned. Use this for lightweight and
              fast-running jobs, to avoid delays due to on-demand
              spawning of the jobs

            - An int, giving the exact number of total jobs that are
              spawned

            - A string, giving an expression as a function of n_jobs,
              as in '2*n_jobs'

    method : string, optional, default: 'predict'
        Invokes the passed method name of the passed estimator. For
        method='predict_proba', the columns correspond to the classes
        in sorted order.

    Returns
    -------
    predictions : ndarray
        This is the result of calling ``method``

    See also
    --------
    cross_val_score : calculate score for each CV split

    cross_validate : calculate one or more scores and timings for each CV split

    Notes
    -----
    In the case that one or more classes are absent in a training portion, a
    default score needs to be assigned to all instances for that class if
    ``method`` produces columns per class, as in {'decision_function',
    'predict_proba', 'predict_log_proba'}.  For ``predict_proba`` this value is
    0.  In order to ensure finite output, we approximate negative infinity by
    the minimum finite float value for the dtype in other cases.

    Examples
    --------
    >>> from sklearn import datasets, linear_model
    >>> from sklearn.model_selection import cross_val_predict
    >>> diabetes = datasets.load_diabetes()
    >>> X = diabetes.data[:150]
    >>> y = diabetes.target[:150]
    >>> lasso = linear_model.Lasso()
    >>> y_pred = cross_val_predict(lasso, X, y, cv=3)
    R   t   decision_functiont   predict_probat   predict_log_probaR   R   R    c      
   3  sB   |  ]8 \ } } t  t ƒ t ˆ ƒ ˆ  ˆ | | ˆ ˆ ˆ ƒ Vq d  S(   N(   R   t   _fit_and_predictR   (   R(   R)   R*   (   R+   R,   R-   t   methodR   R/   (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>  s   s+   cross_val_predict only works for partitionst   dtypei    R8   (   R~   R   R€   (   R   R   R   R   t   fit_transformR   R2   R6   t   concatenatet   _check_is_permutationR
   Re   t   emptyRW   t   intt   aranget   spt   issparset   vstackR8   (   R,   R+   R/   R;   R<   R   R   R-   R    R‚   t   leR>   t   prediction_blockst   pred_block_iR=   t   predictionst	   indices_it   test_indicest   inv_test_indices(    (   R+   R,   R-   R‚   R   R/   sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR     s(    n			c         C  s]  | d k	 r | n i  } t g  | j ƒ  D]$ \ } }	 | t | |	 | ƒ f ^ q( ƒ } t |  | | | ƒ \ }
 } t |  | | | | ƒ \ } } | d k r­ |  j |
 |  n |  j |
 | |  t |  | ƒ } | | ƒ } | d k rSt t | ƒ ƒ } | t |  j	 ƒ k rSd } t
 j d j t |  j	 ƒ | | ƒ t ƒ | d k rÜ| j d k r | j d t |  j	 ƒ k r t d j | j | t |  j	 ƒ | ƒ ƒ ‚ n  t |  j	 ƒ d k rÜt d	 j t |  j	 ƒ | ƒ ƒ ‚ qÜn  t j | j ƒ j } i | d 6| d 6d
 d 6} t j t | ƒ | f | | ƒ } | | d d … |  j	 f <| } qSn  | | f S(   s  Fit estimator and predict values for a given dataset split.

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

    Parameters
    ----------
    estimator : estimator object implementing 'fit' and 'predict'
        The object to use to fit the data.

    X : array-like of shape at least 2D
        The data to fit.

    y : array-like, optional, default: None
        The target variable to try to predict in the case of
        supervised learning.

    train : array-like, shape (n_train_samples,)
        Indices of training samples.

    test : array-like, shape (n_test_samples,)
        Indices of test samples.

    verbose : integer
        The verbosity level.

    fit_params : dict or None
        Parameters that will be passed to ``estimator.fit``.

    method : string
        Invokes the passed method name of the passed estimator.

    Returns
    -------
    predictions : sequence
        Result of calling 'estimator.method'

    test : array-like
        This is the value of the test parameter
    R~   R   R€   sT   To fix this, use a cross-validation technique resulting in properly stratified foldss‰   Number of classes in training fold ({}) does not match total number of classes ({}). Results may not be appropriate for your use case. {}i   i   s™   Output shape {} of {} does not match number of classes ({}) in fold. Irregular decision_function outputs are not currently supported by cross_val_predictsh   Only {} class/es in training fold, this is not supported for decision_function with imbalanced folds. {}i    N(   R~   R   R€   (   R&   RX   RU   RY   R   R^   t   getattrRW   t   sett   classes_R`   R   R8   t   RuntimeWarningt   ndimt   shapeRe   R6   t   finfoRƒ   t   mint   fullR
   (   R,   R+   R/   R)   R*   R   R-   R‚   RP   RQ   Ro   Rp   Rq   R=   t   funcR   t	   n_classest   recommendationt	   float_mint   default_valuest   predictions_for_all_classes(    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR     sN    *7				

c         C  sL   t  |  ƒ | k r t St j | d t ƒ} t | |  <t j | ƒ sH t St S(   s9  Check whether indices is a reordering of the array np.arange(n_samples)

    Parameters
    ----------
    indices : ndarray
        integer array to test
    n_samples : int
        number of expected elements

    Returns
    -------
    is_partition : bool
        True iff sorted(indices) is np.arange(n)
    Rƒ   (   RW   RL   R6   t   zerost   boolR'   t   all(   t   indicest	   n_samplest   hit(    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR†   …  s    
c         C  sT   t  | ƒ s% t | ƒ t |  ƒ k r) | St j | ƒ rG | j ƒ  } n  t | | ƒ S(   s5   Private helper function for parameter value indexing.(   R	   R
   RŠ   R‹   t   tocsrR   (   R+   RQ   R¦   (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyRY     s
    %id   c
           sõ   t  ˆ  ˆ ˆ ƒ \ ‰  ‰ ‰ t ˆ ˆ d t ˆ ƒ ƒ‰ t ˆ d |	 ƒ‰ t ˆ ƒ ‰ t t ˆ ƒ ˆ  ˆ ˆ ˆ ˆ ƒ }
 t d | d | ƒ ‡  ‡ ‡ ‡ ‡ ‡ ‡ f d †  t | ƒ Dƒ ƒ } t	 j
 | ƒ } t	 j | |
 k ƒ d | d } |
 | | f S(   sB  Evaluate the significance of a cross-validated score with permutations

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

    Parameters
    ----------
    estimator : estimator object implementing 'fit'
        The object to use to fit the data.

    X : array-like of shape at least 2D
        The data to fit.

    y : array-like
        The target variable to try to predict in the case of
        supervised learning.

    groups : array-like, with shape (n_samples,), optional
        Labels to constrain permutation within groups, i.e. ``y`` values
        are permuted among samples with the same group identifier.
        When not specified, ``y`` values are permuted among all samples.

        When a grouped cross-validator is used, the group labels are
        also passed on to the ``split`` method of the cross-validator. The
        cross-validator uses them for grouping the samples  while splitting
        the dataset into train/test set.

    scoring : string, callable or None, optional, default: None
        A single string (see :ref:`scoring_parameter`) or a callable
        (see :ref:`scoring`) to evaluate the predictions on the test set.

        If None the estimator's default scorer, if available, is used.

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-fold cross validation,
        - integer, to specify the number of folds in a `(Stratified)KFold`,
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if the estimator is a classifier and ``y`` is
        either binary or multiclass, :class:`StratifiedKFold` is used. In all
        other cases, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.20
            ``cv`` default value if None will change from 3-fold to 5-fold
            in v0.22.

    n_permutations : integer, optional
        Number of times to permute ``y``.

    n_jobs : int or None, optional (default=None)
        The number of CPUs to use to do the computation.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    random_state : int, RandomState instance or None, optional (default=0)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    verbose : integer, optional
        The verbosity level.

    Returns
    -------
    score : float
        The true score without permuting targets.

    permutation_scores : array, shape (n_permutations,)
        The scores obtained for each permutations.

    pvalue : float
        The p-value, which approximates the probability that the score would
        be obtained by chance. This is calculated as:

        `(C + 1) / (n_permutations + 1)`

        Where C is the number of permutations whose score >= the true score.

        The best possible p-value is 1/(n_permutations + 1), the worst is 1.0.

    Notes
    -----
    This function implements Test 1 in:

        Ojala and Garriga. Permutation Tests for Studying Classifier
        Performance.  The Journal of Machine Learning Research (2010)
        vol. 11

    R   R   R   R   c         3  sB   |  ]8 } t  t ƒ t ˆ ƒ ˆ  t ˆ ˆ ˆ ƒ ˆ ˆ ˆ ƒ Vq d  S(   N(   R   t   _permutation_test_scoreR   t   _shuffle(   R(   R=   (   R+   R<   R,   R;   t   random_stateRM   R/   (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>  s   g      ð?i   (   R   R   R   R   R   Rª   R   R   t   rangeR6   R7   t   sum(   R,   R+   R/   R;   R<   t   n_permutationsR   R¬   R   R   RJ   t   permutation_scorest   pvalue(    (   R+   R<   R,   R;   R¬   RM   R/   sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR   §  s    d!!c         C  s›   g  } x… | j  | | | ƒ D]n \ } } t |  | | | ƒ \ }	 }
 t |  | | | | ƒ \ } } |  j |	 |
 ƒ | j | |  | | ƒ ƒ q Wt j | ƒ S(   s-   Auxiliary function for permutation_test_score(   R2   R   R^   Rh   R6   t   mean(   R,   R+   R/   R;   R<   RM   t	   avg_scoreR)   R*   Ro   Rp   Rq   Rr   (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyRª     s    "c         C  sƒ   | d k r$ | j t |  ƒ ƒ } nR t j t | ƒ ƒ } x: t j | ƒ D]) } | | k } | j | | ƒ | | <qI Wt |  | ƒ S(   sA   Return a shuffled copy of y eventually shuffle among same groups.N(   R&   t   permutationRW   R6   R‰   t   uniqueR   (   R/   R;   R¬   R¦   t   groupt	   this_mask(    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR«   )  s    gš™™™™™¹?g      ð?i   R¥   c           sK  | r% t  ˆ d ƒ r% t d ƒ ‚ n  t ˆ  ˆ | ƒ \ ‰  ‰ } t | ˆ d t ˆ ƒ ƒ} t | j ˆ  ˆ | ƒ ƒ } t ˆ d | ƒ‰ t | d d ƒ } t	 | | ƒ ‰ ˆ j
 d } ˆ d k rÛ t d t ˆ ƒ ƒ n  t d | d |	 d	 ˆ ƒ } | r!t | ƒ ‰ ‡ f d
 †  | Dƒ } n  | ryt ˆ ƒ rBt j ˆ ƒ n d ‰ | ‡  ‡ ‡ ‡ ‡ ‡ ‡ f d †  | Dƒ ƒ } n¥ g  } x< | D]4 \ } } x% ˆ D] } | j | |  | f ƒ q™Wq†W| ‡  ‡ ‡ ‡ ‡ ‡ f d †  | Dƒ ƒ } t j | ƒ } | j
 d | } | j | | d ƒ } t j | ƒ j d ƒ } ˆ | d | d f S(   s  Learning curve.

    Determines cross-validated training and test scores for different training
    set sizes.

    A cross-validation generator splits the whole dataset k times in training
    and test data. Subsets of the training set with varying sizes will be used
    to train the estimator and a score for each training subset size and the
    test set will be computed. Afterwards, the scores will be averaged over
    all k runs for each training subset size.

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

    Parameters
    ----------
    estimator : object type that implements the "fit" and "predict" methods
        An object of that type which is cloned for each validation.

    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-like, shape (n_samples) or (n_samples, n_features), optional
        Target relative to X for classification or regression;
        None for unsupervised learning.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    train_sizes : array-like, shape (n_ticks,), dtype float or int
        Relative or absolute numbers of training examples that will be used to
        generate the learning curve. If the dtype is float, it is regarded as a
        fraction of the maximum size of the training set (that is determined
        by the selected validation method), i.e. it has to be within (0, 1].
        Otherwise it is interpreted as absolute sizes of the training sets.
        Note that for classification the number of samples usually have to
        be big enough to contain at least one sample from each class.
        (default: np.linspace(0.1, 1.0, 5))

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-fold cross validation,
        - integer, to specify the number of folds in a `(Stratified)KFold`,
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if the estimator is a classifier and ``y`` is
        either binary or multiclass, :class:`StratifiedKFold` is used. In all
        other cases, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.20
            ``cv`` default value if None will change from 3-fold to 5-fold
            in v0.22.

    scoring : string, callable or None, optional, default: None
        A string (see model evaluation documentation) or
        a scorer callable object / function with signature
        ``scorer(estimator, X, y)``.

    exploit_incremental_learning : boolean, optional, default: False
        If the estimator supports incremental learning, this will be
        used to speed up fitting for different training set sizes.

    n_jobs : int or None, optional (default=None)
        Number of jobs to run in parallel.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    pre_dispatch : integer or string, optional
        Number of predispatched jobs for parallel execution (default is
        all). The option can reduce the allocated memory. The string can
        be an expression like '2*n_jobs'.

    verbose : integer, optional
        Controls the verbosity: the higher, the more messages.

    shuffle : boolean, optional
        Whether to shuffle training data before taking prefixes of it
        based on``train_sizes``.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`. Used when ``shuffle`` is True.

    error_score : 'raise' | 'raise-deprecating' or numeric
        Value to assign to the score if an error occurs in estimator fitting.
        If set to 'raise', the error is raised.
        If set to 'raise-deprecating', a FutureWarning is printed before the
        error is raised.
        If a numeric value is given, FitFailedWarning is raised. This parameter
        does not affect the refit step, which will always raise the error.
        Default is 'raise-deprecating' but from version 0.22 it will change
        to np.nan.

    Returns
    -------
    train_sizes_abs : array, shape (n_unique_ticks,), dtype int
        Numbers of training examples that has been used to generate the
        learning curve. Note that the number of ticks might be less
        than n_ticks because duplicate entries will be removed.

    train_scores : array, shape (n_ticks, n_cv_folds)
        Scores on training sets.

    test_scores : array, shape (n_ticks, n_cv_folds)
        Scores on test set.

    Notes
    -----
    See :ref:`examples/model_selection/plot_learning_curve.py
    <sphx_glr_auto_examples_model_selection_plot_learning_curve.py>`
    t   partial_fitsS   An estimator must support the partial_fit interface to exploit incremental learningR   R   i    s%   [learning_curve] Training set sizes: R   R    R   c         3  s*   |  ]  \ } } ˆ  j  | ƒ | f Vq d  S(   N(   R´   (   R(   R)   R*   (   t   rng(    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>Í  s    c         3  sE   |  ]; \ } } t  t ƒ t ˆ ƒ ˆ  ˆ ˆ | | ˆ ˆ ˆ ƒ	 Vq d  S(   N(   R   t   _incremental_fit_estimatorR   (   R(   R)   R*   (   R+   t   classesR,   RM   t   train_sizes_absR   R/   (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>Ñ  s   c         3  sW   |  ]M \ } } t  t ƒ t ˆ ƒ ˆ  ˆ ˆ | | ˆ d  d d d d t d ˆ ƒVq d S(   Rj   R-   R!   R$   N(   R   R%   R   R&   R'   (   R(   R)   R*   (   R+   R$   R,   RM   R   R/   (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>Ú  s   i   i   N(   i   i   i    (   R{   Re   R   R   R   R3   R2   R   RW   t   _translate_train_sizesR™   RV   R|   R   R   R6   Rµ   R&   Rh   R7   t   reshapet   asarrayt	   transpose(   R,   R+   R/   R;   t   train_sizesR<   R   t   exploit_incremental_learningR   R    R   t   shuffleR¬   R$   t   cv_itert   n_max_training_samplest   n_unique_ticksR>   t   outt   train_test_proportionsR)   R*   t   n_train_samplest
   n_cv_folds(    (	   R+   R»   R$   R,   R¹   RM   R¼   R   R/   sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR   5  s@    ~		!!c         C  s8  t  j |  ƒ } | j d } t  j | ƒ } t  j | ƒ } t  j | j t  j ƒ rº | d k sj | d k rƒ t d | | f ƒ ‚ n  | | j	 d t  j
 d t ƒ } t  j | d | ƒ } n4 | d k sÒ | | k rî t d | | | f ƒ ‚ n  t  j | ƒ } | | j d k r4t j d	 | j d | f t ƒ n  | S(
   s™  Determine absolute sizes of training subsets and validate 'train_sizes'.

    Examples:
        _translate_train_sizes([0.5, 1.0], 10) -> [5, 10]
        _translate_train_sizes([5, 10], 10) -> [5, 10]

    Parameters
    ----------
    train_sizes : array-like, shape (n_ticks,), dtype float or int
        Numbers of training examples that will be used to generate the
        learning curve. If the dtype is float, it is regarded as a
        fraction of 'n_max_training_samples', i.e. it has to be within (0, 1].

    n_max_training_samples : int
        Maximum number of training samples (upper bound of 'train_sizes').

    Returns
    -------
    train_sizes_abs : array, shape (n_unique_ticks,), dtype int
        Numbers of training examples that will be used to generate the
        learning curve. Note that the number of ticks might be less
        than n_ticks because duplicate entries will be removed.
    i    g        g      ð?sŠ   train_sizes has been interpreted as fractions of the maximum number of training samples and must be within (0, 1], but is within [%f, %f].Rƒ   t   copyi   s|   train_sizes has been interpreted as absolute numbers of training samples and must be within (0, %d], but is within [%d, %d].s|   Removed duplicate entries from 'train_sizes'. Number of ticks will be less than the size of 'train_sizes' %d instead of %d).(   R6   R¿   R™   R›   t   maxt
   issubdtypeRƒ   t   floatingRe   t   astypeRˆ   RL   t   clipRµ   R`   R   R—   (   RÁ   RÅ   R¼   t   n_tickst   n_min_required_samplest   n_max_required_samples(    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR½   è  s0    	c	         C  s'  g  g  }	 }
 t  | t j | | ƒ d  ƒ } xâ | D]Ú \ } } | |  } t |  | | | ƒ \ } } t |  | | | ƒ \ } } t |  | | | | ƒ \ } } | d k r¿ |  j | d | ƒn |  j | | d | ƒ|	 j t |  | | | ƒ ƒ |
 j t |  | | | ƒ ƒ q3 Wt j |	 |
 f ƒ j	 S(   sE   Train estimator on training subsets incrementally and compute scores.iÿÿÿÿR»   N(
   R   R6   R2   R   R&   R¸   Rh   Rf   R7   t   T(   R,   R+   R/   R»   R)   R*   RÁ   RM   R   RA   RC   t
   partitionsRÉ   t   partial_traint   train_subsetRo   Rp   t   X_partial_traint   y_partial_trainRq   Rr   (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyRº   #  s    
 c      	     sÿ   t  ˆ  ˆ | ƒ \ ‰  ‰ } t | ˆ d t ˆ ƒ ƒ} t ˆ d | ƒ‰ t d | d |	 d ˆ ƒ } | ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ f d †  | j ˆ  ˆ | ƒ Dƒ ƒ } t j | ƒ } t ˆ ƒ } | j	 d | } | j
 | | d ƒ j d
 ƒ } | d | d	 f S(   sÃ  Validation curve.

    Determine training and test scores for varying parameter values.

    Compute scores for an estimator with different values of a specified
    parameter. This is similar to grid search with one parameter. However, this
    will also compute training scores and is merely a utility for plotting the
    results.

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

    Parameters
    ----------
    estimator : object type that implements the "fit" and "predict" methods
        An object of that type which is cloned for each validation.

    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-like, shape (n_samples) or (n_samples, n_features), optional
        Target relative to X for classification or regression;
        None for unsupervised learning.

    param_name : string
        Name of the parameter that will be varied.

    param_range : array-like, shape (n_values,)
        The values of the parameter that will be evaluated.

    groups : array-like, with shape (n_samples,), optional
        Group labels for the samples used while splitting the dataset into
        train/test set.

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-fold cross validation,
        - integer, to specify the number of folds in a `(Stratified)KFold`,
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs, if the estimator is a classifier and ``y`` is
        either binary or multiclass, :class:`StratifiedKFold` is used. In all
        other cases, :class:`KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.20
            ``cv`` default value if None will change from 3-fold to 5-fold
            in v0.22.

    scoring : string, callable or None, optional, default: None
        A string (see model evaluation documentation) or
        a scorer callable object / function with signature
        ``scorer(estimator, X, y)``.

    n_jobs : int or None, optional (default=None)
        Number of jobs to run in parallel.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    pre_dispatch : integer or string, optional
        Number of predispatched jobs for parallel execution (default is
        all). The option can reduce the allocated memory. The string can
        be an expression like '2*n_jobs'.

    verbose : integer, optional
        Controls the verbosity: the higher, the more messages.

    error_score : 'raise' | 'raise-deprecating' or numeric
        Value to assign to the score if an error occurs in estimator fitting.
        If set to 'raise', the error is raised.
        If set to 'raise-deprecating', a FutureWarning is printed before the
        error is raised.
        If a numeric value is given, FitFailedWarning is raised. This parameter
        does not affect the refit step, which will always raise the error.
        Default is 'raise-deprecating' but from version 0.22 it will change
        to np.nan.

    Returns
    -------
    train_scores : array, shape (n_ticks, n_cv_folds)
        Scores on training sets.

    test_scores : array, shape (n_ticks, n_cv_folds)
        Scores on test set.

    Notes
    -----
    See :ref:`sphx_glr_auto_examples_model_selection_plot_validation_curve.py`

    R   R   R   R    R   c         3  sk   |  ]a \ } } ˆ D]N } t  t ƒ t ˆ ƒ ˆ  ˆ ˆ | | ˆ d  i | ˆ 6d d d t d ˆ ƒVq q d S(   Rj   R-   R!   R$   N(   R   R%   R   R&   R'   (   R(   R)   R*   RQ   (   R+   R$   R,   t
   param_namet   param_rangeRM   R   R/   (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pys	   <genexpr>¢  s   i    i   i   (   i   i   i    (   R   R   R   R   R   R2   R6   R¿   RW   R™   R¾   RÀ   (   R,   R+   R/   RÚ   RÛ   R;   R<   R   R   R    R   R$   R>   RÇ   t   n_paramsRÊ   (    (   R+   R$   R,   RÚ   RÛ   RM   R   R/   sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR   8  s    c	$c         C  sI   i  } x< |  d D]0 } t  j g  |  D] } | | ^ q$ ƒ | | <q W| S(   sü  Aggregate the list of dict to dict of np ndarray

    The aggregated output of _fit_and_score will be a list of dict
    of form [{'prec': 0.1, 'acc':1.0}, {'prec': 0.1, 'acc':1.0}, ...]
    Convert it to a dict of array {'prec': np.array([0.1 ...]), ...}

    Parameters
    ----------

    scores : list of dict
        List of dicts of the scores for all scorers. This is a flat list,
        assumed originally to be of row major order.

    Example
    -------

    >>> scores = [{'a': 1, 'b':10}, {'a': 2, 'b':2}, {'a': 3, 'b':3},
    ...           {'a': 10, 'b': 10}]                         # doctest: +SKIP
    >>> _aggregate_score_dicts(scores)                        # doctest: +SKIP
    {'a': array([1, 2, 3, 10]),
     'b': array([10, 2, 3, 10])}
    i    (   R6   R¿   (   R?   RÇ   RH   RJ   (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyR5   °  s    .(@   t   __doc__t
   __future__R    R   R`   Rb   R[   t	   tracebackR   t   numpyR6   t   scipy.sparset   sparseRŠ   t   baseR   R   t   utilsR   R   R   t   utils.deprecationR   t   utils.validationR	   R
   t   utils.metaestimatorsR   t   utils._joblibR   R   R   t   externals.six.movesR   t   metrics.scorerR   R   t
   exceptionsR   t   _splitR   t   preprocessingR   t   __all__R&   RL   R   R   R%   Rf   Rz   R   R   R†   RY   R   Rª   R«   t   linspaceR   R½   Rº   R   R5   (    (    (    sB   lib/python2.7/site-packages/sklearn/model_selection/_validation.pyt   <module>   sr   		è	¼				g		
	u		¯	;	v