hfs.HierarchicalEstimator

class hfs.HierarchicalEstimator(hierarchy: Optional[ndarray] = None)[source]

Base class for estimators using hierarchical data.

The HierarchicalEstimator implements scikit-learn’s BaseEstimator and TransformerMixin interfaces. It can be used as a base class for feature selection classes or data preprocessors that use hierarchical data.

__init__(hierarchy: Optional[ndarray] = None)[source]

Initializes a HierarchicalEstimator.

Parameters
hierarchynp.ndarray

The hierarchy graph as an adjacency matrix.

fit(X, y=None, columns=None)[source]

Fitting function that prepares the hierarchy and _columns parameter.

The hierarchy is transformed to a nx.DiGraph with a virtual root node named “ROOT” that connects all parts of the graph to one component.

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

The training input samples.

yarray-like, shape (n_samples,) or None

The target values. Only necessary for some estimators.

columns: list or None

The mapping from the hierarchy graph’s nodes to the columns in X. A list of ints. If this parameter is None the columns in X and the corresponding nodes in the hierarchy are expected to be in the same order.

Returns
selfobject

Returns self.

get_columns()[source]

Get mapping from the dataset’s columns to the hierarchy’s nodes.

Returns
columnslist of shape n_features

The value at index i is the name of the corresponding node in the hierarchy graph for columns i in the dataset.

transform(X)[source]

Reduce X to the selected features.

Extend this methods to actually transform the dataset.

Parameters
Xarray of shape (n_samples, n_features)

The input samples.

Returns
Xarray of shape (n_samples, n_selected_features)

The input samples with only the selected features.