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.
8.3.5. nilearn.decoding.SpaceNetClassifier¶
- class nilearn.decoding.SpaceNetClassifier(penalty='graph-net', loss='logistic', 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=200, tol=0.0001, memory=Memory(location=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)[source]¶
Classification learners with sparsity and spatial priors.
SpaceNetClassifier implements Graph-Net and TV-L1 priors / penalties for classification 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
- penaltystring, optional (default ‘graph-net’)
Penalty to used in the model. Can be ‘graph-net’ or ‘tv-l1’.
- lossstring, optional (default “logistic”)
Loss to be used in the classifier. Must be one of “mse”, or “logistic”.
- l1_ratiosfloat 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.
- alphasfloat 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_alphasint, optional (default 10).
Generate this number of alphas per regularization path. This parameter is mutually exclusive with the alphas parameter.
- epsfloat, optional (default 1e-3)
Length of the path. For example,
eps=1e-3
means thatalpha_min / alpha_max = 1e-3
.- maskfilename, 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
numpy.ndarray
, optional. If specified, the image is resampled corresponding to this new affine.
target_affine
can be a 3x3 or a 4x4 matrix. Default=None.- target_shape
tuple
orlist
, optional. If specified, the image will be resized to match this new shape.
len(target_shape)
must be equal to 3.Note
If
target_shape
is specified, atarget_affine
of shape(4, 4)
must also be given.Default=None.
- low_pass
float
or None, optional Low cutoff frequency in Hertz. If specified, signals above this frequency will be filtered out. If None, no low-pass filtering will be performed. Default=None.
- high_pass
float
, optional High cutoff frequency in Hertz. If specified, signals below this frequency will be filtered out. Default=None.
- t_r
float
or None, optional Repetition time, in seconds (sampling period). Set to
None
if not provided. Default=None.- screening_percentilefloat 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 by premultiplying it with the ratio of the volume of the mask of the data and volume of a standard brain. If ‘100’ is given, all the features are used, regardless of the number of voxels.
- standardizebool, 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_interceptbool, optional (default True)
Fit or not an intercept.
- max_iterint (default 200)
Defines the iterations for the solver.
- tolfloat
Defines the tolerance for convergence. Defaults to 1e-4.
- verbose
int
, optional Verbosity level (0 means no message). Default=1.
- n_jobs
int
, optional. The number of CPUs to use to do the computation. -1 means ‘all CPUs’. Default=1.
- memoryinstance of
joblib.Memory
orstr
Used to cache the masking process. By default, no caching is done. If a
str
is given, it is the path to the caching directory.- memory_level
int
, optional. Rough estimator of the amount of memory used by caching. Higher value means more memory for caching. Default=1.
- cvint, 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.
- debiasbool, optional (default False)
If set, then the estimated weights maps will be debiased.
See also
nilearn.decoding.SpaceNetRegressor
Graph-Net and TV-L1 priors/penalties
- 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
- `n_classes_`int
Number of classes
- `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 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
- __init__(penalty='graph-net', loss='logistic', 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=200, tol=0.0001, memory=Memory(location=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)[source]¶
Initialize self. See help(type(self)) for accurate signature.
- score(X, y)[source]¶
Returns the mean accuracy on the given test data and labels.
- Parameters
- Xlist 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.
- yarray or list of length n_samples.
Labels.
- Returns
- scorefloat
Mean accuracy of self.predict(X) w.r.t y.
- SUPPORTED_LOSSES = ['mse', 'logistic']¶
- SUPPORTED_PENALTIES = ['graph-net', 'tv-l1']¶
- decision_function(X)[source]¶
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)[source]¶
Fit the learner
- Parameters
- Xlist 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.
- yarray or list of length n_samples
The dependent variable (age, sex, QI, etc.).
Notes
- selfSpaceNet object
Model selection is via cross-validation with bagging.
- get_params(deep=True)¶
Get parameters for this estimator.
- Parameters
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
- paramsdict
Parameter names mapped to their values.
- predict(X)[source]¶
Predict class labels for samples in X.
- Parameters
- Xlist 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_predndarray, shape (n_samples,)
Predicted class label per sample.
- set_params(**params)¶
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters
- **paramsdict
Estimator parameters.
- Returns
- selfestimator instance
Estimator instance.