#NEWLINE# def cross_val_predict( estimator , X , y = None , labels = None , cv = None , n_jobs = 1 , verbose = 0 , fit_params = None , pre_dispatch = '2*n_jobs' , method = 'predict' ) : #NEWLINE# #INDENT# "Generate cross-validated estimates for each input data point\n\n    Read more in the :ref:`User Guide <cross_validation>`.\n\n    Parameters\n    ----------\n    estimator : estimator object implementing 'fit' and 'predict'\n        The object to use to fit the data.\n\n    X : array-like\n        The data to fit. Can be, for example a list, or an array at least 2d.\n\n    y : array-like, optional, default: None\n        The target variable to try to predict in the case of\n        supervised learning.\n\n    labels : array-like, with shape (n_samples,), optional\n        Group labels for the samples used while splitting the dataset into\n        train/test set.\n\n    cv : int, cross-validation generator or an iterable, optional\n        Determines the cross-validation splitting strategy.\n        Possible inputs for cv are:\n          - None, to use the default 3-fold cross validation,\n          - integer, to specify the number of folds in a `(Stratified)KFold`,\n          - An object to be used as a cross-validation generator.\n          - An iterable yielding train, test splits.\n\n        For integer/None inputs, if the estimator is a classifier and ``y`` is\n        either binary or multiclass, :class:`StratifiedKFold` used. In all\n        other cases, :class:`KFold` is used.\n\n        Refer :ref:`User Guide <cross_validation>` for the various\n        cross-validation strategies that can be used here.\n\n    n_jobs : integer, optional\n        The number of CPUs to use to do the computation. -1 means\n        'all CPUs'.\n\n    verbose : integer, optional\n        The verbosity level.\n\n    fit_params : dict, optional\n        Parameters to pass to the fit method of the estimator.\n\n    pre_dispatch : int, or string, optional\n        Controls the number of jobs that get dispatched during parallel\n        execution. Reducing this number can be useful to avoid an\n        explosion of memory consumption when more jobs get dispatched\n        than CPUs can process. This parameter can be:\n\n            - None, in which case all the jobs are immediately\n              created and spawned. Use this for lightweight and\n              fast-running jobs, to avoid delays due to on-demand\n              spawning of the jobs\n\n            - An int, giving the exact number of total jobs that are\n              spawned\n\n            - A string, giving an expression as a function of n_jobs,\n              as in '2*n_jobs'\n\n    method : string, optional, default: 'predict'\n        Invokes the passed method name of the passed estimator.\n\n    Returns\n    -------\n    predictions : ndarray\n        This is the result of calling ``method``\n\n    Examples\n    --------\n    >>> from sklearn import datasets, linear_model\n    >>> from sklearn.cross_validation import cross_val_predict\n    >>> diabetes = datasets.load_diabetes()\n    >>> X = diabetes.data[:150]\n    >>> y = diabetes.target[:150]\n    >>> lasso = linear_model.Lasso()\n    >>> y_pred = cross_val_predict(lasso, X, y)\n    " #NEWLINE# ( X , y , labels ) = indexable ( X , y , labels ) #NEWLINE# cv = check_cv ( cv , y , classifier = is_classifier ( estimator ) ) #NEWLINE# if ( not callable ( getattr ( estimator , method ) ) ) : #NEWLINE# #INDENT# raise AttributeError ( '{} not implemented in estimator' . format ( method ) ) #NEWLINE# #UNINDENT# parallel = Parallel ( n_jobs = n_jobs , verbose = verbose , pre_dispatch = pre_dispatch ) #NEWLINE# prediction_blocks = parallel ( ( delayed ( _fit_and_predict ) ( clone ( estimator ) , X , y , train , test , verbose , fit_params , method ) for ( train , test ) in cv . split ( X , y , labels ) ) ) #NEWLINE# predictions = [ pred_block_i for ( pred_block_i , _ ) in prediction_blocks ] #NEWLINE# test_indices = np . concatenate ( [ indices_i for ( _ , indices_i ) in prediction_blocks ] ) #NEWLINE# if ( not _check_is_permutation ( test_indices , _num_samples ( X ) ) ) : #NEWLINE# #INDENT# raise ValueError ( 'cross_val_predict only works for partitions' ) #NEWLINE# #UNINDENT# inv_test_indices = np . empty ( len ( test_indices ) , dtype = int ) #NEWLINE# inv_test_indices [ test_indices ] = np . arange ( len ( test_indices ) ) #NEWLINE# if sp . issparse ( predictions [ 0 ] ) : #NEWLINE# #INDENT# predictions = sp . vstack ( predictions , format = predictions [ 0 ] . format ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# predictions = np . concatenate ( predictions ) #NEWLINE# #UNINDENT# return predictions [ inv_test_indices ]