#NEWLINE# def fit( self , X , y , sample_weight = None ) : #NEWLINE# #INDENT# 'Fit the calibrated model\n\n        Parameters\n        ----------\n        X : array-like, shape (n_samples, n_features)\n            Training data.\n\n        y : array-like, shape (n_samples,)\n            Target values.\n\n        sample_weight : array-like, shape = [n_samples] or None\n            Sample weights. If None, then samples are equally weighted.\n\n        Returns\n        -------\n        self : object\n            Returns an instance of self.\n        ' #NEWLINE# ( X , y ) = check_X_y ( X , y , accept_sparse = [ 'csc' , 'csr' , 'coo' ] , force_all_finite = False ) #NEWLINE# ( X , y ) = indexable ( X , y ) #NEWLINE# lb = LabelBinarizer ( ) . fit ( y ) #NEWLINE# self . classes_ = lb . classes_ #NEWLINE# n_folds = ( self . cv if isinstance ( self . cv , int ) else ( self . cv . n_folds if hasattr ( self . cv , 'n_folds' ) else None ) ) #NEWLINE# if ( n_folds and np . any ( [ ( np . sum ( ( y == class_ ) ) < n_folds ) for class_ in self . classes_ ] ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Requesting %d-fold cross-validation but provided less than %d examples for at least one class.' % ( n_folds , n_folds ) ) ) #NEWLINE# #UNINDENT# self . calibrated_classifiers_ = [ ] #NEWLINE# if ( self . base_estimator is None ) : #NEWLINE# #INDENT# base_estimator = LinearSVC ( random_state = 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# base_estimator = self . base_estimator #NEWLINE# #UNINDENT# if ( self . cv == 'prefit' ) : #NEWLINE# #INDENT# calibrated_classifier = _CalibratedClassifier ( base_estimator , method = self . method ) #NEWLINE# if ( sample_weight is not None ) : #NEWLINE# #INDENT# calibrated_classifier . fit ( X , y , sample_weight ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# calibrated_classifier . fit ( X , y ) #NEWLINE# #UNINDENT# self . calibrated_classifiers_ . append ( calibrated_classifier ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cv = check_cv ( self . cv , y , classifier = True ) #NEWLINE# fit_parameters = signature ( base_estimator . fit ) . parameters #NEWLINE# estimator_name = type ( base_estimator ) . __name__ #NEWLINE# if ( ( sample_weight is not None ) and ( 'sample_weight' not in fit_parameters ) ) : #NEWLINE# #INDENT# warnings . warn ( ( '%s does not support sample_weight. Samples weights are only used for the calibration itself.' % estimator_name ) ) #NEWLINE# base_estimator_sample_weight = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# base_estimator_sample_weight = sample_weight #NEWLINE# #UNINDENT# for ( train , test ) in cv . split ( X , y ) : #NEWLINE# #INDENT# this_estimator = clone ( base_estimator ) #NEWLINE# if ( base_estimator_sample_weight is not None ) : #NEWLINE# #INDENT# this_estimator . fit ( X [ train ] , y [ train ] , sample_weight = base_estimator_sample_weight [ train ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# this_estimator . fit ( X [ train ] , y [ train ] ) #NEWLINE# #UNINDENT# calibrated_classifier = _CalibratedClassifier ( this_estimator , method = self . method ) #NEWLINE# if ( sample_weight is not None ) : #NEWLINE# #INDENT# calibrated_classifier . fit ( X [ test ] , y [ test ] , sample_weight [ test ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# calibrated_classifier . fit ( X [ test ] , y [ test ] ) #NEWLINE# #UNINDENT# self . calibrated_classifiers_ . append ( calibrated_classifier ) #NEWLINE# #UNINDENT# #UNINDENT# return self