hfs.LazyHierarchicalFeatureSelector

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

Abstract class used for all lazy hierarchical feature selection methods.

Every method should implement the method select_and_predict.

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

Initialize a LazyHierarchicalFeatureSelector with the required data.

Parameters
hierarchynp.ndarray

The hierarchy graph as an adjacency matrix.

fit(X, y=None)[source]

Implementing the fit function for Sklearn compatibility.

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

The training input samples.

yarray-like, shape (n_samples,)

The target values. An array of int.

Returns
selfobject

Fitted estimator.

fit_selector(X_train, y_train, X_test, columns=None)[source]

Fit LazyHierarchicalFeatureSelector class.

Due to laziness fitting of parameters as well as predictions are obtained per instance.

Parameters
X_train{numpy array} of shape (n_samples, n_features)

The training input samples.

X_test{numpy array} of shape (n_samples, n_features)

The test input samples. converted into a sparse csc_matrix.

y_trainarray-like of shape (n_samples, n_levels)

The target values, i.e., hierarchical class labels for classification.

get_features()[source]

Get selected features.

Parameters
None
Returns
featuresnumpy array

Boolean value at index states if feature is selected.

get_score(ytest, predictions)[source]

Returns score of the predictions.

Note that recall of the positive class is known as “sensitivity”; recall of the negative class is “specificity”

Parameters
ytest1d array-like, or label indicator array / sparse matrix

truth values of y.

predictions1d array-like, or label indicator array / sparse matrix

obtained predictions.

Returns
reportdict

metrics of prediction.

select_and_predict(predict=True, saveFeatures=False, estimator=BernoulliNB())[source]

Select features lazy for each test instance amd optionally predict target value of test instances.

To be implemented by children.

Parameters
predict{bool}

true if predictions shall be obtained.

saveFeatures{bool}

true if features selected for each test instance shall be saved.

estimatorsklearn-compatible estimator.

Estimator to use for predictions.

Returns
predictions for test input samples

if predict = false, returns empty array