def _permutation_test_score(estimator, X, y, cv, scorer):
 avg_score = []
 for (train, test) in cv:
  (X_train, y_train) = _safe_split(estimator, X, y, train)
  (X_test, y_test) = _safe_split(estimator, X, y, test, train)
  estimator.fit(X_train, y_train)
  avg_score.append(scorer(estimator, X_test, y_test))
 return np.mean(avg_score)

def _permutation_test_score ( estimator , X , y , cv , scorer ) : avg_score = [ ] for ( train , test ) in cv : ( X_train , y_train ) = _safe_split ( estimator , X , y , train ) ( X_test , y_test ) = _safe_split ( estimator , X , y , test , train ) estimator . fit ( X_train , y_train ) avg_score . append ( scorer ( estimator , X_test , y_test ) ) return np . mean ( avg_score )
auxiliary function for permutation_test_score .