Skip to content

Documentation for LassoFeatureSelection

Lasso based feature selection - based on feature_importance.

Apply Lasso to ModelSelection.

Source code in photonai/modelwrapper/feature_selection.py
class LassoFeatureSelection(BaseEstimator, TransformerMixin):
    """Lasso based feature selection - based on feature_importance.

    Apply Lasso to ModelSelection.

    """
    def __init__(self, percentile: float = 0.3, alpha: float = 1., **kwargs):
        """
        Initialize the object.

        Parameters:
            percentile: bool, default=False
                Percent of features to keep.

            alpha: float, default=1.
                Weighting parameter for Lasso.

            **kwargs:
                Passed to Lasso object.

        """
        self.percentile = percentile
        self.alpha = alpha
        self.model_selector = None
        self.Lasso_kwargs = kwargs
        self.needs_covariates=False
        self.needs_y = False

    def fit(self, X, y=None, **kwargs):
        self.model_selector = ModelSelector(Lasso(alpha=self.alpha, **self.Lasso_kwargs),
                                            threshold=self.percentile, percentile=True)

        self.model_selector.fit(X, y, **kwargs)
        return self

    def transform(self, X, y=None, **kwargs):
        selected_features = self.model_selector.transform(X, y, **kwargs)
        return selected_features

    def set_params(self, **params):
        super(LassoFeatureSelection, self).set_params(**params)

    def inverse_transform(self, X, y=None, **kwargs):
        return self.model_selector.inverse_transform(X)

__init__(self, percentile=0.3, alpha=1.0, **kwargs) special

Initialize the object.

Parameters:

Name Type Description Default
percentile float

bool, default=False Percent of features to keep.

0.3
alpha float

float, default=1. Weighting parameter for Lasso.

1.0
**kwargs

Passed to Lasso object.

{}
Source code in photonai/modelwrapper/feature_selection.py
def __init__(self, percentile: float = 0.3, alpha: float = 1., **kwargs):
    """
    Initialize the object.

    Parameters:
        percentile: bool, default=False
            Percent of features to keep.

        alpha: float, default=1.
            Weighting parameter for Lasso.

        **kwargs:
            Passed to Lasso object.

    """
    self.percentile = percentile
    self.alpha = alpha
    self.model_selector = None
    self.Lasso_kwargs = kwargs
    self.needs_covariates=False
    self.needs_y = False