class_docstr: Out-of-bag early stopping.
  
  A callable that returns True when the test error starts
  rising. We use a Spearman correlation (between X_test.w and y_test)
  for scoring.
class_docstr_tok: ["Out-of-bag","early","stopping",".","A","callable","that","returns","True","when","the","test","error","starts","rising",".","We","use","a","Spearman","correlation","(","between","X_test.w","and","y_test",")","for","scoring","."]
docstr: Perform callback.
docstr_tok: ["Perform","callback","."]
code: def __call__(self, variables):
      """Perform callback."""
      # misc
      if not isinstance(variables, dict):
          variables = dict(w=variables)
      self.counter += 1
      w = variables["w"]
  
      # use Spearman score as stopping criterion
      score = self.test_score(w)[0]
  
      self.test_scores.append(score)
      if self.counter <= 20 or self.counter % 10 != 2:
          return
  
      # check whether score increased on average over last 5 iterations
      if (
          len(self.test_scores) > 4
          and np.mean(np.diff(self.test_scores[-5:][::-1])) >= self.tol
      ):
          if self.verbose:
              if self.verbose > 1:
                  print(
                      "Early stopping. "
                      f"Test score: {score:.8f} {40 * '-'}"
                  )
              else:
                  sys.stderr.write(".")
          return True
  
      if self.verbose > 1:
          print(f"Test score: {score:.8f}")
      return False
  
imports: import collections
  import sys
  import time
  import warnings
  from functools import partial
  import numpy
  from joblib import Memory, Parallel, delayed
  from scipy import stats
  from scipy.ndimage import binary_dilation, binary_erosion, gaussian_filter
  from sklearn.feature_selection import SelectPercentile, f_classif, f_regression
  from sklearn.linear_model import LinearRegression
  from sklearn.linear_model._base import _preprocess_data
  from sklearn.metrics import accuracy_score
  from sklearn.model_selection import check_cv
  from sklearn.preprocessing import LabelBinarizer
  from sklearn.utils import check_array, check_X_y
  from sklearn.utils.extmath import safe_sparse_dot
  from nilearn._utils.masker_validation import check_embedded_masker
  from nilearn.experimental.surface import SurfaceMasker
  from nilearn.image import get_data
  from nilearn.masking import unmask_from_to_3d_array
  from .._utils import fill_doc
  from .._utils.cache_mixin import CacheMixin
  from .._utils.param_validation import adjust_screening_percentile
  from .space_net_solvers import graph_net_logistic, graph_net_squared_loss, tvl1_solver
label_desc: Use image node_id 2 for calling the _EarlyStoppingCallback obj's underlying member method code with example usage: obj.__call__(variables) and returns: False, True