mojolearn.VarianceThreshold#

class mojolearn.VarianceThreshold(threshold=0.0)[source]#

Bases: _SelectorMixin

Feature selector that removes low-variance features.

Follows scikit-learn’s VarianceThreshold. Fit computes each column’s population variance over its non-NaN values and keeps the columns whose variance is greater than threshold. With the default threshold of 0, a constant column has variance exactly 0 and is removed. Fit raises ValueError when no column passes.

Parameters:

threshold (float, default 0.0) – Columns with variance at or below this are removed.

Variables:
  • variances_ (array of shape (n_features,)) – Variance of each column.

  • n_features_in_ (int) – Number of columns seen in fit.

  • numeric_mode_ (str) – Numeric mode the estimator was fitted in; transform runs in the same mode.

Examples

>>> import numpy as np, mojolearn
>>> X = np.array([[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]], dtype=np.float32)
>>> mojolearn.VarianceThreshold().fit_transform(X)
__init__(threshold=0.0)[source]#

Methods

fit(X[, y])

fit_transform(X[, y])

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

get_support([indices])

Return the selected features.

set_params(**params)

Set constructor parameters.

transform(X)

Keep only the selected columns of X.