Module connectome.models.pipeline_elastic_net

functions to prepare data for elastic net (e.g. calculate squared or absolute values or interactions) and run elastic net model

Functions

def model_elastic_net(X_train, y_train, classification: bool = True, n_alphas_logreg=10, n_alphas_linreg=10, cv_logreg=5, cv_linreg=5, l1_ratios_logreg=[0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0], l1_ratios_linreg=[0.01, 0.109, 0.20800000000000002, 0.30700000000000005, 0.406, 0.505, 0.6040000000000001, 0.7030000000000001, 0.802, 0.901, 1.0], verbose=0, **kwargs)

Function that fits an elastic net model and searches for best parameters via CV. See also https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.ElasticNetCV.html and https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html for further arguments that can be specified. See the documentation of the framework function for examples how to use this function within the framework. Information on arguments: The higher the values for n_alphas and cv and the higher the amount of l1_ratios, the more accurate the search for good parameters, but the longer the runtime. Running this function with the default values on the Connectome dataset (not aggregated) may take a while, especially for classification.

Examples:

>>> model = model_elastic_net(X_train = X_train,
                              y_train = y_train,
                              classification = True) 

Args

X_train
The training dataset
y_train
The true labels
classification
classification task -> logistic regression or regression task -> linear model
n_alphas_logreg
number of alphas along the regularization path (logreg), default 10
n_alphas_linreg
number of alphas along the regularization path (linreg), default 10
cv_logreg
number of folds (logreg), default 5
cv_linreg
number of folds (linreg), default 5
l1_ratios_logreg
(list of) float for l1_ratio, 0 is L2, 1 is L1 (logreg)
l1_ratios_linreg
(list of) float for l1_ratio, 0 is L2, 1 is L1 (linreg). Default with 0.01 instead of 0, because for l1_ratio = 0, automatic alpha grid generation is not supported
verbose
amount of verbosity, default = 0

Returns

Returns fitted model

def prepare_data_elastic_net(data: pandas.core.frame.DataFrame, option: str = 'abs') ‑> pandas.core.frame.DataFrame

Function that transforms the data for elastic net modelling (absolute values, squared values, quadratic functions). Remember to run this function both on X_train and X_test.

Examples:

>>> # calculate absolute values of all features:
>>> X_train = prepare_data_elastic_net(data = X_train,
                                                     option = "abs")
>>> X_test = prepare_data_elastic_net(data = X_test,
                                                     option = "abs")

Args

data
A pd.Dataframe
option
option for transformation (abs = absolute values, squ = squared values, quadr = quadratic functions)

Returns

A pd.Dataframe with transformed values