Skip to content

Documentation for FClassifSelectPercentile

Feature Selection for classification data - percentile based.

Apply VarianceThreshold -> SelectPercentile to data. SelectPercentile based on f_classif and parameter percentile.

Source code in photonai/modelwrapper/feature_selection.py
class FClassifSelectPercentile(BaseEstimator, TransformerMixin):
    """Feature Selection for classification data - percentile based.

    Apply VarianceThreshold -> SelectPercentile to data.
    SelectPercentile based on f_classif and parameter percentile.

    """
    _estimator_type = "transformer"

    def __init__(self, percentile: float = 10):
        """
        Initialize the object.

        Parameters:
            percentile:
                Percent of features to keep.

        """
        self.var_thres = VarianceThreshold()
        self.percentile = percentile
        self.my_fs = None

    def fit(self, X, y):
        X = self.var_thres.fit_transform(X)
        self.my_fs = SelectPercentile(score_func=f_classif, percentile=self.percentile)
        self.my_fs.fit(X, y)
        return self

    def transform(self, X):
        X = self.var_thres.transform(X)
        return self.my_fs.transform(X)

    def inverse_transform(self, X: np.ndarray) -> np.ndarray:
        """Reverse to original dimension.

        1. SelectPercentile.inverse_transform
        2. VarianceThreshold.inverse_transform

        Parameters:
            X:
                The input samples of shape [n_samples, n_selected_features].

        Returns:
            Array of shape [n_samples, n_original_features]
            with columns of zeros inserted where features would have
            been removed.

        """
        Xt = self.my_fs.inverse_transform(X)
        return self.var_thres.inverse_transform(Xt)

__init__(self, percentile=10) special

Initialize the object.

Parameters:

Name Type Description Default
percentile float

Percent of features to keep.

10
Source code in photonai/modelwrapper/feature_selection.py
def __init__(self, percentile: float = 10):
    """
    Initialize the object.

    Parameters:
        percentile:
            Percent of features to keep.

    """
    self.var_thres = VarianceThreshold()
    self.percentile = percentile
    self.my_fs = None