Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.

7.3.2. nilearn.decoding.SpaceNetRegressor

class nilearn.decoding.SpaceNetRegressor(penalty=’graph-net’, l1_ratios=0.5, alphas=None, n_alphas=10, mask=None, target_affine=None, target_shape=None, low_pass=None, high_pass=None, t_r=None, max_iter=1000, tol=0.0001, memory=Memory(cachedir=None), memory_level=1, standardize=True, verbose=1, n_jobs=1, eps=0.001, cv=8, fit_intercept=True, screening_percentile=20.0, debias=False)

Regression learners with sparsity and spatial priors.

SpaceNetClassifier implements Graph-Net and TV-L1 priors / penalties for regression problems. Thus, the penalty is a sum 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’.

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_ratio == 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 MultiNiftiMasker with default parameters.

target_affine : 3x3 or 4x4 matrix, optional (default None)

This parameter is passed to image.resample_img. Please see the related documentation for details.

target_shape : 3-tuple of integers, optional (default None)

This parameter is passed to image.resample_img. Please see the related documentation for details.

low_pass: None or float, optional

This parameter is passed to signal.clean. Please see the related documentation for details

high_pass: None or float, optional

This parameter is passed to signal.clean. Please see the related documentation for details

t_r : float, optional (default None)

This parameter is passed to signal.clean. Please see the related documentation for details

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 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).

standardize : bool, optional (default True):

If set, then we’ll center the data (X, y) 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 1000)

Defines the iterations for the solver.

tol : float

Defines the tolerance for convergence. Defaults to 1e-4.

verbose : int, optional (default 1)

Verbosity level.

n_jobs : int, optional (default 1)

Number of jobs in solving the sub-problems.

memory: instance of joblib.Memory or string

Used to cache the masking process. By default, no caching is done. If a string is given, it is the path to the caching directory.

memory_level: integer, optional (default 1)

Rough estimator of the amount of memory used by caching. Higher value means more memory for caching.

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

alpha_ (float) Best alpha found by cross-validation
coef_ (array, shape = [n_classes-1, n_features]) Coefficient of the features in the decision function.
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 given at masker creation, contains the automatically computed mask.
intercept_ (array, shape = [n_classes-1]) Intercept (a.k.a. bias) added to the decision function. It is available only when parameter intercept is set to True.
cv_scores_ (2d array of shape (n_alphas, n_folds)) 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.
__init__(penalty=’graph-net’, l1_ratios=0.5, alphas=None, n_alphas=10, mask=None, target_affine=None, target_shape=None, low_pass=None, high_pass=None, t_r=None, max_iter=1000, tol=0.0001, memory=Memory(cachedir=None), memory_level=1, standardize=True, verbose=1, n_jobs=1, eps=0.001, cv=8, fit_intercept=True, screening_percentile=20.0, debias=False)
check_params()

Makes sure parameters are sane

decision_function(X)

Predict confidence scores for samples

The confidence score for a sample is the signed distance of that sample to the hyperplane.

Parameters:

X : {array-like, sparse matrix}, shape = (n_samples, n_features)

Samples.

Returns:

array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes)

Confidence scores per (sample, class) combination. In the binary case, confidence score for self.classes_[1] where >0 means this class would be predicted.

fit(X, y)

Fit the learner

Parameters:

X : list of Niimg-like objects

See http://nilearn.github.io/manipulating_images/input_output.html Data on which model is to be fitted. If this is a list, the affine is considered the same for all.

y : array or list of length n_samples

The dependent variable (age, sex, QI, etc.).

Notes

self : SpaceNet object
Model selection is via cross-validation with bagging.
get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep : boolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params : mapping of string to any

Parameter names mapped to their values.

predict(X)

Predict class labels for samples in X.

Parameters:

X : list of Niimg-like objects

See http://nilearn.github.io/manipulating_images/input_output.html 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.

score(X, y, sample_weight=None)

Returns the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as (1 - u/v), where u is the regression sum of squares ((y_true - y_pred) ** 2).sum() and v is the residual sum of squares ((y_true - y_true.mean()) ** 2).sum(). Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

Parameters:

X : array-like, shape = (n_samples, n_features)

Test samples.

y : array-like, shape = (n_samples) or (n_samples, n_outputs)

True values for X.

sample_weight : array-like, shape = [n_samples], optional

Sample weights.

Returns:

score : float

R^2 of self.predict(X) wrt. y.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:self