def _fit_and_predict(estimator, X, y, train, test, verbose, fit_params, method):
 fit_params = (fit_params if (fit_params is not None) else {})
 fit_params = dict([(k, _index_param_value(X, v, train)) for (k, v) in fit_params.items()])
 (X_train, y_train) = _safe_split(estimator, X, y, train)
 (X_test, _) = _safe_split(estimator, X, y, test, train)
 if (y_train is None):
  estimator.fit(X_train, **fit_params)
 else:
  estimator.fit(X_train, y_train, **fit_params)
 func = getattr(estimator, method)
 predictions = func(X_test)
 if (method in ['decision_function', 'predict_proba', 'predict_log_proba']):
  n_classes = len(set(y))
  predictions_ = np.zeros((X_test.shape[0], n_classes))
  if ((method == 'decision_function') and (len(estimator.classes_) == 2)):
   predictions_[:, estimator.classes_[(-1)]] = predictions
  else:
   predictions_[:, estimator.classes_] = predictions
  predictions = predictions_
 return (predictions, test)

def _fit_and_predict ( estimator , X , y , train , test , verbose , fit_params , method ) : fit_params = ( fit_params if ( fit_params is not None ) else { } ) fit_params = dict ( [ ( k , _index_param_value ( X , v , train ) ) for ( k , v ) in fit_params . items ( ) ] ) ( X_train , y_train ) = _safe_split ( estimator , X , y , train ) ( X_test , _ ) = _safe_split ( estimator , X , y , test , train ) if ( y_train is None ) : estimator . fit ( X_train , ** fit_params ) else : estimator . fit ( X_train , y_train , ** fit_params ) func = getattr ( estimator , method ) predictions = func ( X_test ) if ( method in [ 'decision_function' , 'predict_proba' , 'predict_log_proba' ] ) : n_classes = len ( set ( y ) ) predictions_ = np . zeros ( ( X_test . shape [ 0 ] , n_classes ) ) if ( ( method == 'decision_function' ) and ( len ( estimator . classes_ ) == 2 ) ) : predictions_ [ : , estimator . classes_ [ ( - 1 ) ] ] = predictions else : predictions_ [ : , estimator . classes_ ] = predictions predictions = predictions_ return ( predictions , test )
fit estimator and predict values for a given dataset split .