<s> """<STR_LIT>""" <EOL> import copy <EOL> import numpy as np <EOL> from sklearn . cross_validation import StratifiedKFold <EOL> from . . import common_math <EOL> def predict_proba_cv ( clf , X , y , n_folds = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> X , _ = common_math . pandas_to_ndarray_wrap ( X ) <EOL> y , _ = common_math . pandas_to_ndarray_wrap ( y ) <EOL> n_classes = len ( np . unique ( y ) ) <EOL> clf = copy . deepcopy ( clf ) <EOL> cv = StratifiedKFold ( y , n_folds = n_folds ) <EOL> probas = np . nan * np . ones ( ( len ( y ) , n_classes ) ) <EOL> for i , ( train , test ) in enumerate ( cv ) : <EOL> if len ( np . unique ( y [ train ] ) ) < n_classes : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> probas [ test , : ] = clf . fit ( X [ train ] , y [ train ] ) . predict_proba ( X [ test ] ) <EOL> return probas </s>
