class_docstr: Regression and classification learners with sparsity and spatial priors.
  
  `SpaceNet` implements Graph-Net and TV-L1 priors /
  penalties. Thus, the penalty is a sum of an L1 term and a spatial term. The
  aim of such a hybrid prior is to obtain weights maps which are structured
  (due to the spatial prior) and sparse (enforced by L1 norm).
  
  Parameters
  ----------
  penalty : string, optional (default 'graph-net')
      Penalty to used in the model. Can be 'graph-net' or 'tv-l1'.
  
  loss : string, optional (default None)
      Loss to be used in the model. Must be an one of "mse", or "logistic".
  
  is_classif : bool, optional (default False)
      Flag telling whether the learning task is classification or regression.
  
  l1_ratios : float or list of floats in the interval [0, 1];        optional (default .5)
      Constant that mixes L1 and spatial prior terms in penalization.
      l1_ratios == 1 corresponds to pure LASSO. The larger the value of this
      parameter, the sparser the estimated weights map. If list is provided,
      then the best value will be selected by cross-validation.
  
  alphas : float or list of floats, optional (default None)
      Choices for the constant that scales the overall regularization term.
      This parameter is mutually exclusive with the `n_alphas` parameter.
      If None or list of floats is provided, then the best value will be
      selected by cross-validation.
  
  n_alphas : int, optional (default 10).
      Generate this number of alphas per regularization path.
      This parameter is mutually exclusive with the `alphas` parameter.
  
  eps : float, optional (default 1e-3)
      Length of the path. For example, ``eps=1e-3`` means that
      ``alpha_min / alpha_max = 1e-3``
  
  mask : filename, niimg, NiftiMasker instance, optional (default None)
      Mask to be used on data. If an instance of masker is passed,
      then its mask will be used. If no mask is it will be computed
      automatically by a NiftiMasker.
  %(target_affine)s
      An important use-case of this parameter is for downsampling the
      input data to a coarser resolution (to speed of the model fit).
  %(target_shape)s
  %(low_pass)s
  %(high_pass)s
  %(t_r)s
  screening_percentile : float in the interval [0, 100]; Optional (        default 20)
      Percentile value for ANOVA univariate feature selection. A value of
      100 means 'keep all features'. This percentile is expressed
      w.r.t the volume of a standard (MNI152) brain, and so is corrected
      at runtime to correspond to the volume of the user-supplied mask
      (which is typically smaller). If '100' is given, all the features
      are used, regardless of the number of voxels.
  
  standardize : bool, optional (default True):
      If set, then the data (X, y) are centered to have mean zero along
      axis 0. This is here because nearly all linear models will want
      their data to be centered.
  
  fit_intercept : bool, optional (default True)
      Fit or not an intercept.
  
  max_iter : int (default 200)
      Defines the iterations for the solver.
  
  tol : float, optional (default 5e-4)
      Defines the tolerance for convergence for the backend FISTA solver.
  %(verbose)s
  %(n_jobs)s
  %(memory)s
  %(memory_level1)s
  cv : int, a cv generator instance, or None (default 8)
      The input specifying which cross-validation generator to use.
      It can be an integer, in which case it is the number of folds in a
      KFold, None, in which case 3 fold is used, or another object, that
      will then be used as a cv generator.
  
  debias : bool, optional (default False)
      If set, then the estimated weights maps will be debiased.
  
  Attributes
  ----------
  all_coef_ : ndarray, shape (n_l1_ratios, n_folds, n_features)
      Coefficients for all folds and features.
  
  alpha_grids_ : ndarray, shape (n_folds, n_alphas)
      Alpha values considered for selection of the best ones
      (saved in `best_model_params_`)
  
  best_model_params_ : ndarray, shape (n_folds, n_parameter)
      Best model parameters (alpha, l1_ratio) saved for the different
      cross-validation folds.
  
  classes_ : ndarray of labels (`n_classes_`)
      Labels of the classes (for classification problems)
  
  n_classes_ : int
      Number of classes (for classification problems)
  
  coef_ : ndarray, shape        (1, n_features) for 2 class classification problems        (i.e n_classes = 2)        (n_classes, n_features) for n_classes > 2
      Coefficient of the features in the decision function.
  
  coef_img_ : nifti image
      Masked model coefficients
  
  mask_ : ndarray 3D
      An array contains values of the mask image.
  
  masker_ : instance of NiftiMasker
      The nifti masker used to mask the data.
  
  mask_img_ : Nifti like image
      The mask of the data. If no mask was supplied by the user,
      this attribute is the mask image computed automatically from the
      data `X`.
  
  memory_ : joblib memory cache
  
  intercept_ : narray, shape
      (1,) for 2 class classification problems (i.e n_classes = 2)
      (n_classes,) for n_classes > 2
      Intercept (a.k.a. bias) added to the decision function.
      It is available only when parameter intercept is set to True.
  
  cv_ : list of pairs of lists
      Each pair is the list of indices for the train and test samples
      for the corresponding fold.
  
  cv_scores_ : ndarray, shape (n_folds, n_alphas)        or (n_l1_ratios, n_folds, n_alphas)
      Scores (misclassification) for each alpha, and on each fold
  
  screening_percentile_ : float
      Screening percentile corrected according to volume of mask,
      relative to the volume of standard brain.
  
  w_ : ndarray, shape
      (1, n_features + 1) for 2 class classification problems
      (i.e n_classes = 2)
      (n_classes, n_features + 1) for n_classes > 2, and (n_features,)
      for regression
      Model weights
  
  ymean_ : array, shape (n_samples,)
      Mean of prediction targets
  
  Xmean_ : array, shape (n_features,)
      Mean of X across samples
  
  Xstd_ : array, shape (n_features,)
      Standard deviation of X across samples
class_docstr_tok: ["Regression","and","classification","learners","with","sparsity","and","spatial","priors",".","`","SpaceNet","`","implements","Graph-Net","and","TV-L1","priors","\/","penalties",".","Thus",",","the","penalty","is","a","sum","of","an","L1","term","and","a","spatial","term",".","The","aim","of","such","a","hybrid","prior","is","to","obtain","weights","maps","which","are","structured","(","due","to","the","spatial","prior",")","and","sparse","(","enforced","by","L1","norm",")",".","Parameters","--","--","--","--","--","penalty",":","string",",","optional","(","default","'graph-net","'",")","Penalty","to","used","in","the","model",".","Can","be","'graph-net","'","or","'tv-l1","'",".","loss",":","string",",","optional","(","default","None",")","Loss","to","be","used","in","the","model",".","Must","be","an","one","of","``","mse","''",",","or","``","logistic","''",".","is_classif",":","bool",",","optional","(","default","False",")","Flag","telling","whether","the","learning","task","is","classification","or","regression",".","l1_ratios",":","float","or","list","of","floats","in","the","interval","[","0",",","1","]",";","optional","(","default",".5",")","Constant","that","mixes","L1","and","spatial","prior","terms","in","penalization",".","l1_ratios","==","1","corresponds","to","pure","LASSO",".","The","larger","the","value","of","this","parameter",",","the","sparser","the","estimated","weights","map",".","If","list","is","provided",",","then","the","best","value","will","be","selected","by","cross-validation",".","alphas",":","float","or","list","of","floats",",","optional","(","default","None",")","Choices","for","the","constant","that","scales","the","overall","regularization","term",".","This","parameter","is","mutually","exclusive","with","the","`","n_alphas","`","parameter",".","If","None","or","list","of","floats","is","provided",",","then","the","best","value","will","be","selected","by","cross-validation",".","n_alphas",":","int",",","optional","(","default","10",")",".","Generate","this","number","of","alphas","per","regularization","path",".","This","parameter","is","mutually","exclusive","with","the","`","alphas","`","parameter",".","eps",":","float",",","optional","(","default","1e-3",")","Length","of","the","path",".","For","example",",","``","eps=1e-3","``","means","that","``","alpha_min","\/","alpha_max","=","1e-3","``","mask",":","filename",",","niimg",",","NiftiMasker","instance",",","optional","(","default","None",")","Mask","to","be","used","on","data",".","If","an","instance","of","masker","is","passed",",","then","its","mask","will","be","used",".","If","no","mask","is","it","will","be","computed","automatically","by","a","NiftiMasker",".","%","(","target_affine",")","s","An","important","use-case","of","this","parameter","is","for","downsampling","the","input","data","to","a","coarser","resolution","(","to","speed","of","the","model","fit",")",".","%","(","target_shape",")","s","%","(","low_pass",")","s","%","(","high_pass",")","s","%","(","t_r",")","s","screening_percentile",":","float","in","the","interval","[","0",",","100","]",";","Optional","(","default","20",")","Percentile","value","for","ANOVA","univariate","feature","selection",".","A","value","of","100","means","'keep","all","features","'",".","This","percentile","is","expressed","w.r.t","the","volume","of","a","standard","(","MNI152",")","brain",",","and","so","is","corrected","at","runtime","to","correspond","to","the","volume","of","the","user-supplied","mask","(","which","is","typically","smaller",")",".","If","'100","'","is","given",",","all","the","features","are","used",",","regardless","of","the","number","of","voxels",".","standardize",":","bool",",","optional","(","default","True",")",":","If","set",",","then","the","data","(","X",",","y",")","are","centered","to","have","mean","zero","along","axis","0",".","This","is","here","because","nearly","all","linear","models","will","want","their","data","to","be","centered",".","fit_intercept",":","bool",",","optional","(","default","True",")","Fit","or","not","an","intercept",".","max_iter",":","int","(","default","200",")","Defines","the","iterations","for","the","solver",".","tol",":","float",",","optional","(","default","5e-4",")","Defines","the","tolerance","for","convergence","for","the","backend","FISTA","solver",".","%","(","verbose",")","s","%","(","n_jobs",")","s","%","(","memory",")","s","%","(","memory_level1",")","s","cv",":","int",",","a","cv","generator","instance",",","or","None","(","default","8",")","The","input","specifying","which","cross-validation","generator","to","use",".","It","can","be","an","integer",",","in","which","case","it","is","the","number","of","folds","in","a","KFold",",","None",",","in","which","case","3","fold","is","used",",","or","another","object",",","that","will","then","be","used","as","a","cv","generator",".","debias",":","bool",",","optional","(","default","False",")","If","set",",","then","the","estimated","weights","maps","will","be","debiased",".","Attributes","--","--","--","--","--","all_coef_",":","ndarray",",","shape","(","n_l1_ratios",",","n_folds",",","n_features",")","Coefficients","for","all","folds","and","features",".","alpha_grids_",":","ndarray",",","shape","(","n_folds",",","n_alphas",")","Alpha","values","considered","for","selection","of","the","best","ones","(","saved","in","`","best_model_params_","`",")","best_model_params_",":","ndarray",",","shape","(","n_folds",",","n_parameter",")","Best","model","parameters","(","alpha",",","l1_ratio",")","saved","for","the","different","cross-validation","folds",".","classes_",":","ndarray","of","labels","(","`","n_classes_","`",")","Labels","of","the","classes","(","for","classification","problems",")","n_classes_",":","int","Number","of","classes","(","for","classification","problems",")","coef_",":","ndarray",",","shape","(","1",",","n_features",")","for","2","class","classification","problems","(","i.e","n_classes","=","2",")","(","n_classes",",","n_features",")","for","n_classes",">","2","Coefficient","of","the","features","in","the","decision","function",".","coef_img_",":","nifti","image","Masked","model","coefficients","mask_",":","ndarray","3D","An","array","contains","values","of","the","mask","image",".","masker_",":","instance","of","NiftiMasker","The","nifti","masker","used","to","mask","the","data",".","mask_img_",":","Nifti","like","image","The","mask","of","the","data",".","If","no","mask","was","supplied","by","the","user",",","this","attribute","is","the","mask","image","computed","automatically","from","the","data","`","X","`",".","memory_",":","joblib","memory","cache","intercept_",":","narray",",","shape","(","1",",",")","for","2","class","classification","problems","(","i.e","n_classes","=","2",")","(","n_classes",",",")","for","n_classes",">","2","Intercept","(","a.k.a",".","bias",")","added","to","the","decision","function",".","It","is","available","only","when","parameter","intercept","is","set","to","True",".","cv_",":","list","of","pairs","of","lists","Each","pair","is","the","list","of","indices","for","the","train","and","test","samples","for","the","corresponding","fold",".","cv_scores_",":","ndarray",",","shape","(","n_folds",",","n_alphas",")","or","(","n_l1_ratios",",","n_folds",",","n_alphas",")","Scores","(","misclassification",")","for","each","alpha",",","and","on","each","fold","screening_percentile_",":","float","Screening","percentile","corrected","according","to","volume","of","mask",",","relative","to","the","volume","of","standard","brain",".","w_",":","ndarray",",","shape","(","1",",","n_features","+","1",")","for","2","class","classification","problems","(","i.e","n_classes","=","2",")","(","n_classes",",","n_features","+","1",")","for","n_classes",">","2",",","and","(","n_features",",",")","for","regression","Model","weights","ymean_",":","array",",","shape","(","n_samples",",",")","Mean","of","prediction","targets","Xmean_",":","array",",","shape","(","n_features",",",")","Mean","of","X","across","samples","Xstd_",":","array",",","shape","(","n_features",",",")","Standard","deviation","of","X","across","samples"]
docstr: Predict class labels for samples in X.
  
  Parameters
  ----------
  X : list of Niimg-like objects
      See :ref:`extracting_data`.
      Data on prediction is to be made. If this is a list,
      the affine is considered the same for all.
  
  Returns
  -------
  y_pred : ndarray, shape (n_samples,)
      Predicted class label per sample.
docstr_tok: ["Predict","class","labels","for","samples","in","X.","Parameters","--","--","--","--","--","X",":","list","of","Niimg-like","objects","See",":","ref",":","`","extracting_data","`",".","Data","on","prediction","is","to","be","made",".","If","this","is","a","list",",","the","affine","is","considered","the","same","for","all",".","Returns","--","--","--","-","y_pred",":","ndarray",",","shape","(","n_samples",",",")","Predicted","class","label","per","sample","."]
code: def predict(self, X):
      """Predict class labels for samples in X.
  
      Parameters
      ----------
      X : list of Niimg-like objects
          See :ref:`extracting_data`.
          Data on prediction is to be made. If this is a list,
          the affine is considered the same for all.
  
      Returns
      -------
      y_pred : ndarray, shape (n_samples,)
          Predicted class label per sample.
      """
      # cast X into usual 2D array
      if not hasattr(self, "masker_"):
          raise RuntimeError(
              f"This {self.__class__.__name__} instance is not fitted yet!"
          )
      X = self.masker_.transform(X)
  
      # handle regression (least-squared loss)
      if not self.is_classif:
          return LinearRegression.predict(self, X)
  
      # prediction proper
      scores = self.decision_function(X)
      if len(scores.shape) == 1:
          indices = (scores > 0).astype(int)
      else:
          indices = scores.argmax(axis=1)
      return self.classes_[indices]
  
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 6 for calling the BaseSpaceNet obj's underlying member method code with example usage: obj.predict(X) and returns: self, LinearRegression