Skip to content

Feature Selection

molfp.selection

Standalone feature selection utilities for any fingerprint matrix.

Works with output from any molfp function: fingerprints, graph_vectors, etc.

remove_low_variance(X, threshold=0.0)

Remove features with variance at or below threshold.

Parameters:

Name Type Description Default
X

numpy array (n_samples, n_features).

required
threshold

variance cutoff. 0.0 removes constant features, 0.01 removes near-constant, etc.

0.0

Returns:

Type Description

dict with: X: filtered array (n_samples, n_remaining) mask: boolean mask of kept features n_removed: number of features removed n_remaining: number of features kept

select_features(X, y, k=500, threshold=None)

Select top-k features by mutual information with optional variance pre-filter.

Parameters:

Name Type Description Default
X

numpy array (n_samples, n_features).

required
y

labels array (n_samples,) — class labels for mutual information.

required
k

number of top features to keep.

500
threshold

if set, remove features with variance <= threshold before mutual information ranking. Reduces noise and speeds up MI computation.

None

Returns:

Type Description

dict with: X: selected array (n_samples, k) indices: original column indices of selected features scores: mutual information scores for selected features n_input: original number of features n_after_variance: features after variance filter (if threshold set) n_selected: final number of selected features